Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Names route NFT #43

Open
wants to merge 102 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
3df7e58
added sqlite server
Jan 7, 2024
9f222bb
added sqlite server
Jan 7, 2024
56993a7
added a hello world server
Jan 7, 2024
bfa1edd
added a hello world server
Jan 7, 2024
7a146c5
Merge pull request #1 from SmartTokenLabs/feature/sqlite-fastify-server
JamesSmartCell Jan 7, 2024
8bb6300
Update name server
JamesSmartCell Jan 7, 2024
f4aff5f
updates to api
Jan 7, 2024
908e552
make name-api runnable.
foxgem Jan 8, 2024
b9e7e3c
Roll back executable update
JamesSmartCell Jan 8, 2024
c76703c
Update server to check token ownership
JamesSmartCell Jan 8, 2024
2791904
add dotenv.
foxgem Jan 8, 2024
fee39eb
Merge
JamesSmartCell Jan 8, 2024
36e9a7c
add missing files.
foxgem Jan 8, 2024
8318c03
Update to add API routes
JamesSmartCell Jan 8, 2024
431338a
Able to use cert
JamesSmartCell Jan 8, 2024
c9d74f5
Add cors
JamesSmartCell Jan 8, 2024
f2cb9b3
Write to database
JamesSmartCell Jan 8, 2024
9aa28a6
Fix sslcert
JamesSmartCell Jan 8, 2024
68fca30
Ensure database updates are used
JamesSmartCell Jan 8, 2024
4c748e6
added sqlite
Jan 8, 2024
217e681
debug
JamesSmartCell Jan 8, 2024
da2276f
updated to mirror SQLite with JSON db design
Jan 9, 2024
f60eae1
updated the insert logic
Jan 9, 2024
69f0bcf
updated the insert logic
Jan 9, 2024
caa22f9
updated the insert logic
Jan 9, 2024
903c2b9
added cors to gateway
Jan 9, 2024
0eed470
Update client resolve code
JamesSmartCell Jan 9, 2024
78e3ca2
tidy
JamesSmartCell Jan 9, 2024
9ec7248
Handle errors
JamesSmartCell Jan 9, 2024
7eb9d37
Merge pull request #2 from SmartTokenLabs/sqlite
JamesSmartCell Jan 9, 2024
26767a4
initial fixes
JamesSmartCell Jan 9, 2024
d4b2bd8
Update with database fix
JamesSmartCell Jan 9, 2024
0d6d236
simplify
JamesSmartCell Jan 9, 2024
e23afeb
db changes
Jan 9, 2024
aad10ae
endpoint fixes
Jan 9, 2024
f852278
Merge branch 'build-fixing' of github.com:SmartTokenLabs/cats-offchai…
Jan 9, 2024
dde2b4c
updated gateway
Jan 9, 2024
b988b49
https tmp work around
Jan 9, 2024
c381b3b
updated gateway node-fetch lib
Jan 9, 2024
0b78f15
update code
JamesSmartCell Jan 9, 2024
de43959
add constants
JamesSmartCell Jan 9, 2024
9151972
limit enties to 10 and return the most recently added name
Jan 9, 2024
5c88dde
Merge branch 'feature/sqlite-updates' into build-fixing
Jan 10, 2024
c1e4f0d
Ensure signature is in correct format
JamesSmartCell Jan 10, 2024
0d0dd17
Remove cert
JamesSmartCell Jan 10, 2024
1e94a28
limit to one name per cat
Jan 10, 2024
731b2cb
Merge branch 'build-fixing' of github.com:SmartTokenLabs/cats-offchai…
Jan 10, 2024
a282f59
Merge
JamesSmartCell Jan 10, 2024
4aecd56
Merge pull request #3 from SmartTokenLabs/build-fixing
JamesSmartCell Jan 10, 2024
cbb1e10
remove json
JamesSmartCell Jan 10, 2024
d3b150e
Add proof test
JamesSmartCell Jan 10, 2024
1776d94
Remove json
JamesSmartCell Jan 10, 2024
db4658d
Add certificate back in
JamesSmartCell Jan 10, 2024
775b3f4
sanitse the name entry text
Jan 10, 2024
e2f2bcb
fix to limit of entries
Jan 11, 2024
a7cec65
use test ens add ext
Jan 11, 2024
14339b7
db logic fix
Jan 11, 2024
f26575e
db logic fix
Jan 11, 2024
9bdbc6a
db logic fix
Jan 11, 2024
0508af1
added env logic to determine which cats ens name to use
Jan 11, 2024
f7f8e31
updated env check
Jan 11, 2024
81eb163
added polygon rpc
Jan 11, 2024
24db76e
added polygon rpc and todo
Jan 11, 2024
9d7d5dc
added smartcat contract addr
Jan 11, 2024
9fc67cb
match the char limit on the client and server
Jan 11, 2024
0fe6bb2
Various improvement
micwallace Jan 11, 2024
0064c6c
Various fixes
micwallace Jan 11, 2024
787968a
Various fixes
micwallace Jan 11, 2024
ad6c520
Fix chain integer/string issues
micwallace Jan 11, 2024
5c1da09
merged with main
Jan 11, 2024
519c6a8
Merge pull request #4 from SmartTokenLabs/feat/proposed-changes
nicktaras Jan 11, 2024
d903d63
Remove unnecessary private key from name-api
JamesSmartCell Jan 12, 2024
deb01b8
Update name-api to add count API call
JamesSmartCell Jan 13, 2024
82e36ce
Implement chain specific lookup.
micwallace Jan 15, 2024
64c79cd
Return 0 address for mainnet resolver
micwallace Jan 15, 2024
7bf899c
Fix args type
micwallace Jan 15, 2024
86b6bb4
Fix missing await
micwallace Jan 15, 2024
353efa8
Fix args and tidy up returns
JamesSmartCell Jan 15, 2024
5f7f1ab
Update to use correct cointypes
JamesSmartCell Jan 15, 2024
8bf1527
Update nametype
JamesSmartCell Jan 15, 2024
433a1fa
update
JamesSmartCell Jan 15, 2024
2dcbc79
Update cointype
JamesSmartCell Jan 15, 2024
733456d
Merge pull request #5 from SmartTokenLabs/test-cointtype
JamesSmartCell Jan 15, 2024
e16a64e
Add resolver contracts and deployment scripts
JamesSmartCell Jan 15, 2024
c7383af
add log
JamesSmartCell Jan 16, 2024
35025cd
comments
JamesSmartCell Jan 16, 2024
9d78703
Add Avatar resolve (#7)
JamesSmartCell Jan 17, 2024
2f50b9e
merge
JamesSmartCell Jan 17, 2024
b033b70
remove image dump
JamesSmartCell Jan 17, 2024
a94d703
Allow correct TokenId handling (#8)
JamesSmartCell Jan 18, 2024
f9c7b40
Bump log size to 2000
JamesSmartCell Jan 18, 2024
da675ab
Add ability to dump names & ensure cointypes doesn't overflow
JamesSmartCell Jan 25, 2024
bea676b
Universal routing (#10)
JamesSmartCell May 3, 2024
19fbac4
Update server after full testing (#12)
JamesSmartCell May 9, 2024
7e7e372
Further restrictions (#13)
JamesSmartCell May 9, 2024
8f6414f
Ensure smartcats works with legacy contract (#14)
JamesSmartCell May 10, 2024
65d4616
Multichain functionality (#15)
JamesSmartCell May 23, 2024
ea06734
Update for Multichain support rules (#16)
JamesSmartCell May 25, 2024
ce6d551
Nft naming (#17)
JamesSmartCell May 30, 2024
3bdf6ad
improve name resolution
JamesSmartCell May 30, 2024
9ef9846
update
JamesSmartCell May 31, 2024
329599f
remove logs
JamesSmartCell May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ typings/
.rts2_cache_es/
.rts2_cache_umd/

packages/ensnames.db

# Optional REPL history
.node_repl_history

Expand Down
243 changes: 243 additions & 0 deletions packages/client/src/domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
import { Command } from 'commander';
import ethers from 'ethers';
//@ts-ignore
import fetch from 'node-fetch';
import dotenv from "dotenv";

dotenv.config();

const { PRIVATE_KEY, INFURA_KEY } = process.env;

const program = new Command();
program
.requiredOption('-r --registry <address>', 'ENS registry address', '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e') //0x4dBFD41eA7639eB5FbC95e4D2Ea63369e7Be143f <<-- resolver, registry is 0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5
.option('-p --provider <url>', 'web3 provider URL', `https://sepolia.infura.io/v3/${INFURA_KEY}`) //https://ethereum-goerli.publicnode.com
.option('-i --chainId <chainId>', 'chainId', '11155111') //5
.option('-n --chainName <name>', 'chainName', 'sepolia') //Goerli
.argument('<name>');

program.parse(process.argv);
const options = program.opts();
const ensAddress = options.registry;
const chainId = parseInt(options.chainId);
const chainName = options.chainName;
const provider = new ethers.providers.JsonRpcProvider(options.provider, {
chainId,
name: chainName,
ensAddress,
});

// Define the ENS resolver contract address for now, will add dynamic resolution if needed
//const ensResolverAddress = '0x8464135c8F25Da09e49BC8782676a84730C318bC';
//const ensResolverAddress = '0x02957D5823c1C973f2075d870985c856b6D1b93E';
//const ensResolverAddress = '0xeE6a307cdFe7Ee16988BF73Dfd0D001B3f200bD5'; //testnet

//@ts-ignore
const returnAbi = [
{
"constant": false,
"inputs": [
{
"name": "sender",
"type": "address"
},
{
"name": "urls",
"type": "string[]"
},
{
"name": "callData",
"type": "bytes"
},
{
"name": "callbackFunction",
"type": "bytes4"
},
{
"name": "extraData",
"type": "bytes"
}
],
"name": "OffchainLookup",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
];

//@ts-ignore
const decodeAbi = [
{
"constant": true,
"inputs": [],
"name": "decode",
"outputs": [
{
"name": "address",
"type": "bytes"
},
{
"name": "time",
"type": "uint64"
},
{
"name": "sig",
"type": "bytes"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];

// @ts-ignore
async function postUrl(url: string): Promise<string> {
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(""),
});

if (!response.ok) {
throw new Error(`Error: ${response.status}`);
}

const responseData = await response.json();
console.log('Response:', responseData);
return JSON.stringify(responseData);
} catch (error) {
console.error('Failed to post:', error);
}

return "failed";
}

(async () => {
// @ts-ignore
const name = program.args[0];

let pk: string = PRIVATE_KEY!;
// @ts-ignore
const wallet = new ethers.Wallet(pk);

// 1. Register token
//register on xNFT (will be sepolia)
//let tokenAddr = "0x4ffb1b3c2464644ba3436de3fc81a5d79cdf5760";
// @ts-ignore
let catsTokenAddr = "0xa04664f6191d9a65f5f48c6f9d6dd81cb636e65c";
// @ts-ignore
let chainId = 11155111;
// @ts-ignore
let tokenId = 5;
let tokenName = name;

/*const message = `Attempting to register domain ${tokenName} name to ${catsTokenAddr}`;

console.log(`MSG: ${message}`);

const signature = await wallet.signMessage(message);
console.log('Signature: ', signature);

let callUrl = `http://192.168.43.187:8083/registertoken/${chainId}/${catsTokenAddr}/${tokenName}/${signature}/${chainId}`;

console.log(`CALL: ${callUrl}`);

const response = await postUrl(callUrl);

console.log(`RSP: ${response}`);*/

// @ts-ignore
let tokenIdName = "max";

// 2. Create 6551 name
// /register/:chainId/:tokenContract/:tokenId/:name/:signature
let registerMsg = `Registering your catId ${tokenId} name to ${tokenIdName}.${tokenName}`;
const signature2 = await wallet.signMessage(registerMsg);
console.log('Signature: ', signature2);
let callUrl2 = `http://192.168.43.187:8083/register/${chainId}/${catsTokenAddr}/${tokenId}/${tokenIdName}.${tokenName}/${signature2}`;
console.log(`CALL: ${callUrl2}`);
const response2 = await postUrl(callUrl2);

console.log(`RSP: ${response2}`);


//now resolve Avatar
let resolver = await provider.getResolver(`${tokenIdName}.${tokenName}`);

let ethMainnetAddress = await resolver!!.getAddress();

console.log(`ADDR: ${ethMainnetAddress}`);

//resolve image
let avatarUrl = await resolver!!.getAvatar();

console.log(`AVATAR: ${JSON.stringify(avatarUrl)}`);


// @ts-ignore
async function resolve(name: string, resolverAddress: string): Promise<string> {
const namehash = ethers.utils.namehash(name);
const dnsEncode = ethers.utils.dnsEncode(name);
const funcEncode = "0x3b3b57de" + namehash.substring(2);

const catResolver = new ethers.Contract(resolverAddress, [
'function resolve(bytes name, bytes data) view returns (bytes)',
'function resolveWithProof(bytes calldata response, bytes calldata extraData) external view returns(bytes memory)'
], provider);

//call, get error
try {
const resolverTx = await catResolver.resolve(dnsEncode, funcEncode);
console.log(resolverTx);
} catch (error) {
//break down the data
const iface = new ethers.utils.Interface(returnAbi);
const decoded = iface.decodeFunctionData('OffchainLookup', error.data);


//format URL:
const callUrl = decoded.urls[0].replace('{sender}', decoded.sender).replace('{data}', decoded.callData);

try {
const response = await fetch(callUrl);

if (response.ok) {
const data = await response.json();

//response1
const proofResponse = data.data;
const extraData = decoded.extraData;

//now call proof
const proofReturn = await catResolver.resolveWithProof(proofResponse, extraData);
console.log(proofReturn);

console.log("Len: " + proofReturn.length);
var truncated = proofReturn;
if (proofReturn.length > 42) {
truncated = "0x" + proofReturn.substring(proofReturn.length - 40);
}

console.log("Truncated: " + truncated);

return ethers.utils.getAddress(truncated);
}
} catch (callError) {
// nop, expected
}
}

return ethers.constants.AddressZero;
}


}

)();


Loading