From 7cf691cab3acce2da02ab3ad59902bb0d65e2b33 Mon Sep 17 00:00:00 2001 From: bowensanders Date: Mon, 23 Sep 2024 15:00:19 -0700 Subject: [PATCH 1/4] snap modified --- .../packages/name-lookup/snap.manifest.json | 2 +- .../packages/name-lookup/src/index.ts | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/examples/packages/name-lookup/snap.manifest.json b/packages/examples/packages/name-lookup/snap.manifest.json index a9b37e9c18..c568ca42f8 100644 --- a/packages/examples/packages/name-lookup/snap.manifest.json +++ b/packages/examples/packages/name-lookup/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "xk7O5itVsuV3Dfldq3rI3WgggHa3z7HX7e17jzheE8w=", + "shasum": "8w0VHAID5gqtyRoZ92f070XZcdkf7tOqEeaYavhEslg=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/name-lookup/src/index.ts b/packages/examples/packages/name-lookup/src/index.ts index fa91fd1d8b..3ad3b8b011 100644 --- a/packages/examples/packages/name-lookup/src/index.ts +++ b/packages/examples/packages/name-lookup/src/index.ts @@ -21,12 +21,32 @@ export const onNameLookup: OnNameLookupHandler = async (request) => { } if (domain) { - const resolvedAddress = '0xc0ffee254729296a45a3885639AC7E10F9d54979'; - return { - resolvedAddresses: [ - { resolvedAddress, protocol: 'test protocol', domainName: domain }, - ], + const resolutions = { + fooBar: '0xc0ffee254729296a45a3885639AC7E10F9d54979', + bar: '0x0000000000000000000000000000000000000000', + barstool: '0x1234567890123456789012345678901234567890', }; + + const getResolution = (domainName: string) => { + if (resolutions[domainName]) { + return { resolvedAddress: resolutions[domainName], domainName }; + } + const entries = Object.entries(resolutions); + for (const [key, value] of entries) { + if (key.startsWith(domainName)) { + return { + domainName: key, + resolvedAddress: value, + protocol: 'test protocol', + }; + } + } + return null; + }; + const fetchedResolution = getResolution(domain); + if (fetchedResolution !== null) { + return { resolvedAddresses: [fetchedResolution] }; + } } return null; From 4146368eea9cc211f37ae1fbd6803116615aaae0 Mon Sep 17 00:00:00 2001 From: bowensanders Date: Tue, 24 Sep 2024 11:31:40 -0700 Subject: [PATCH 2/4] improvements and test fix --- packages/examples/packages/name-lookup/snap.manifest.json | 2 +- packages/examples/packages/name-lookup/src/index.test.ts | 2 +- packages/examples/packages/name-lookup/src/index.ts | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/examples/packages/name-lookup/snap.manifest.json b/packages/examples/packages/name-lookup/snap.manifest.json index c568ca42f8..ee43e9f07b 100644 --- a/packages/examples/packages/name-lookup/snap.manifest.json +++ b/packages/examples/packages/name-lookup/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "8w0VHAID5gqtyRoZ92f070XZcdkf7tOqEeaYavhEslg=", + "shasum": "+2tvVrCeAmrz5nv0HN569OSbpYUKvoSlnfroKg92GrU=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/name-lookup/src/index.test.ts b/packages/examples/packages/name-lookup/src/index.test.ts index dbd671defc..fc58d00de7 100644 --- a/packages/examples/packages/name-lookup/src/index.test.ts +++ b/packages/examples/packages/name-lookup/src/index.test.ts @@ -3,7 +3,7 @@ import type { ChainId } from '@metamask/snaps-sdk'; import { onNameLookup } from '.'; -const DOMAIN_MOCK = 'test.domain'; +const DOMAIN_MOCK = 'fooBar'; const ADDRESS_MOCK = '0xc0ffee254729296a45a3885639AC7E10F9d54979'; const CHAIN_ID_MOCK = 'eip155:1' as ChainId; diff --git a/packages/examples/packages/name-lookup/src/index.ts b/packages/examples/packages/name-lookup/src/index.ts index 3ad3b8b011..0e7f3cf001 100644 --- a/packages/examples/packages/name-lookup/src/index.ts +++ b/packages/examples/packages/name-lookup/src/index.ts @@ -23,13 +23,17 @@ export const onNameLookup: OnNameLookupHandler = async (request) => { if (domain) { const resolutions = { fooBar: '0xc0ffee254729296a45a3885639AC7E10F9d54979', - bar: '0x0000000000000000000000000000000000000000', + bartholemew: '0x0000000000000000000000000000000000000000', barstool: '0x1234567890123456789012345678901234567890', }; const getResolution = (domainName: string) => { if (resolutions[domainName]) { - return { resolvedAddress: resolutions[domainName], domainName }; + return { + resolvedAddress: resolutions[domainName], + domainName, + protocol: 'test protocol', + }; } const entries = Object.entries(resolutions); for (const [key, value] of entries) { From 1ed9ffc02a857ac935f2a08230fcd418c5762301 Mon Sep 17 00:00:00 2001 From: bowensanders Date: Tue, 24 Sep 2024 12:26:37 -0700 Subject: [PATCH 3/4] small fix --- packages/examples/packages/name-lookup/snap.manifest.json | 2 +- packages/examples/packages/name-lookup/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/examples/packages/name-lookup/snap.manifest.json b/packages/examples/packages/name-lookup/snap.manifest.json index ee43e9f07b..863e16d25f 100644 --- a/packages/examples/packages/name-lookup/snap.manifest.json +++ b/packages/examples/packages/name-lookup/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "+2tvVrCeAmrz5nv0HN569OSbpYUKvoSlnfroKg92GrU=", + "shasum": "jYVSW1ljYZwbnptZXUqxzOqj8EM+9ot5m5cM5J5KBiU=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/name-lookup/src/index.ts b/packages/examples/packages/name-lookup/src/index.ts index 0e7f3cf001..b1231702d4 100644 --- a/packages/examples/packages/name-lookup/src/index.ts +++ b/packages/examples/packages/name-lookup/src/index.ts @@ -23,7 +23,7 @@ export const onNameLookup: OnNameLookupHandler = async (request) => { if (domain) { const resolutions = { fooBar: '0xc0ffee254729296a45a3885639AC7E10F9d54979', - bartholemew: '0x0000000000000000000000000000000000000000', + bar: '0x0000000000000000000000000000000000000000', barstool: '0x1234567890123456789012345678901234567890', }; From 022cd99c40946b3ccd8db2c2ab1f0fa0ade4e147 Mon Sep 17 00:00:00 2001 From: bowensanders Date: Thu, 26 Sep 2024 10:18:45 -0700 Subject: [PATCH 4/4] eliminate case sensitivity --- packages/examples/packages/browserify/snap.manifest.json | 2 +- packages/examples/packages/name-lookup/snap.manifest.json | 2 +- packages/examples/packages/name-lookup/src/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/examples/packages/browserify/snap.manifest.json b/packages/examples/packages/browserify/snap.manifest.json index e8a3a4c059..10e6d77211 100644 --- a/packages/examples/packages/browserify/snap.manifest.json +++ b/packages/examples/packages/browserify/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "3LsbiHzT2I8gHJPQCu6JbTiKKCy5XA2VQQdW9Qkn3XU=", + "shasum": "u+bnPdpw6us0nDDr3k28cfDoIA+5CT1Y7A88nYJLNGk=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/name-lookup/snap.manifest.json b/packages/examples/packages/name-lookup/snap.manifest.json index 863e16d25f..3ee540f3e7 100644 --- a/packages/examples/packages/name-lookup/snap.manifest.json +++ b/packages/examples/packages/name-lookup/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "jYVSW1ljYZwbnptZXUqxzOqj8EM+9ot5m5cM5J5KBiU=", + "shasum": "xFeB7CqtdR3GLUmfSmxzes32oUFEVzCbniKprMtx7vY=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/name-lookup/src/index.ts b/packages/examples/packages/name-lookup/src/index.ts index b1231702d4..61472dc1a1 100644 --- a/packages/examples/packages/name-lookup/src/index.ts +++ b/packages/examples/packages/name-lookup/src/index.ts @@ -37,7 +37,7 @@ export const onNameLookup: OnNameLookupHandler = async (request) => { } const entries = Object.entries(resolutions); for (const [key, value] of entries) { - if (key.startsWith(domainName)) { + if (key.toLowerCase().startsWith(domainName.toLowerCase())) { return { domainName: key, resolvedAddress: value,