Skip to content

Commit a8d5aea

Browse files
committed
feat: pass binary-encoded value of address
1 parent d8727c6 commit a8d5aea

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

Diff for: packages/gateway/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"dependencies": {
5959
"@chainlink/ccip-read-server": "^0.2.1",
6060
"@chainlink/ethers-ccip-read-provider": "^0.2.3",
61+
"@ensdomains/address-encoder": "^1.1.2",
6162
"@ensdomains/ens-contracts": "^0.0.8",
6263
"@ensdomains/offchain-resolver-contracts": "^0.2.1",
6364
"@polkadot/api": "^12.3.1",

Diff for: packages/gateway/src/azero-id.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
33
import { Database } from './server';
44
import { ContractPromise } from '@polkadot/api-contract';
55
import type { WeightV2 } from '@polkadot/types/interfaces';
6+
import { getCoderByCoinType } from "@ensdomains/address-encoder";
7+
import { createDotAddressDecoder } from '@ensdomains/address-encoder/utils'
8+
import { hexlify } from 'ethers/lib/utils';
69

10+
const AZERO_COIN_TYPE = 643;
711
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
812
const EMPTY_CONTENT_HASH = '0x';
913

@@ -37,11 +41,11 @@ export class AzeroId implements Database {
3741
}
3842

3943
async addr(name: string, coinType: number) {
44+
coinType = Number(coinType); // convert BigNumber to number
4045
console.log("addr", name, coinType);
4146

4247
let value;
43-
if (coinType == 643) {
44-
// AlephZero
48+
if (coinType == AZERO_COIN_TYPE) {
4549
value = await this.fetchA0ResolverAddress(name);
4650
} else {
4751
let alias = AzeroId.getAlias(""+coinType);
@@ -55,7 +59,12 @@ export class AzeroId implements Database {
5559
}
5660
}
5761

58-
value = value ?? (coinType == 60? ZERO_ADDRESS:'0x');
62+
if (value === undefined) {
63+
value = coinType == 60? ZERO_ADDRESS:'0x';
64+
} else {
65+
value = AzeroId.encodeAddress(value, coinType);
66+
}
67+
5968
return { addr: value, ttl: this.ttl };
6069
}
6170

@@ -124,4 +133,25 @@ export class AzeroId implements Database {
124133

125134
return alias.get(coinType);
126135
}
136+
137+
static encodeAddress(addr: string, coinType: number) {
138+
const isEvmCoinType = (c: number) => {
139+
return c == 60 || (c & 0x80000000)!=0
140+
}
141+
142+
if (coinType == AZERO_COIN_TYPE) {
143+
const azeroCoder = createDotAddressDecoder(42);
144+
return hexlify(azeroCoder(addr));
145+
}
146+
if (isEvmCoinType(coinType) && !addr.startsWith('0x')) {
147+
addr = '0x' + addr;
148+
}
149+
150+
try {
151+
const coder = getCoderByCoinType(coinType);
152+
return hexlify(coder.decode(addr));
153+
} catch {
154+
return addr;
155+
}
156+
}
127157
}

Diff for: yarn.lock

+21
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,15 @@
994994
nano-base32 "^1.0.1"
995995
ripemd160 "^2.0.2"
996996

997+
"@ensdomains/address-encoder@^1.1.2":
998+
version "1.1.2"
999+
resolved "https://registry.yarnpkg.com/@ensdomains/address-encoder/-/address-encoder-1.1.2.tgz#29bb2346f4da21f8e2f7f05a4755d9ccd3ecab6e"
1000+
integrity sha512-x+uUZbtvtWDh23dLH/U//re0s9v341tFB6SJeUElkQ31O3jkoUh3jvgnx+NxiohWW6JWW6QrXS4kigxuvwbi2A==
1001+
dependencies:
1002+
"@noble/curves" "^1.2.0"
1003+
"@noble/hashes" "^1.3.2"
1004+
"@scure/base" "^1.1.5"
1005+
9971006
"@ensdomains/buffer@^0.0.13":
9981007
version "0.0.13"
9991008
resolved "https://registry.yarnpkg.com/@ensdomains/buffer/-/buffer-0.0.13.tgz#b9f60defb78fc5f2bee30faca17e63dfbef19253"
@@ -2235,6 +2244,13 @@
22352244
undici "5.5.1"
22362245
ws "^8.2.2"
22372246

2247+
"@noble/curves@^1.2.0":
2248+
version "1.6.0"
2249+
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.6.0.tgz#be5296ebcd5a1730fccea4786d420f87abfeb40b"
2250+
integrity sha512-TlaHRXDehJuRNR9TfZDNQ45mMEd5dwUwmicsafcIX4SsNiqnCHKjE/1alYPd/lDRVhxdhUAlv8uEhMCI5zjIJQ==
2251+
dependencies:
2252+
"@noble/hashes" "1.5.0"
2253+
22382254
"@noble/curves@^1.3.0":
22392255
version "1.5.0"
22402256
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.5.0.tgz#7a9b9b507065d516e6dce275a1e31db8d2a100dd"
@@ -2252,6 +2268,11 @@
22522268
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426"
22532269
integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==
22542270

2271+
"@noble/[email protected]", "@noble/hashes@^1.3.2":
2272+
version "1.5.0"
2273+
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.5.0.tgz#abadc5ca20332db2b1b2aa3e496e9af1213570b0"
2274+
integrity sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==
2275+
22552276
"@noble/hashes@~1.1.1":
22562277
version "1.1.3"
22572278
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.3.tgz#360afc77610e0a61f3417e497dcf36862e4f8111"

0 commit comments

Comments
 (0)