@avalabs/avalanche-module 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -10
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +6 -7
- package/CHANGELOG.md +16 -0
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/manifest.json +1 -1
- package/package.json +4 -3
- package/src/handlers/get-address/get-address.ts +44 -0
- package/src/handlers/get-balances/get-balances.ts +3 -2
- package/src/module.ts +7 -3
- package/src/utils/hash-blockchain-id.test.ts +43 -0
- package/src/utils/hash-blockchain-id.ts +11 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { hashBlockchainId } from '../utils/hash-blockchain-id';
|
|
2
|
+
|
|
3
|
+
describe('hashBlockchainId', () => {
|
|
4
|
+
it('hashes the c-chain mainnet blockchain id', () => {
|
|
5
|
+
const result = hashBlockchainId({
|
|
6
|
+
blockchainId: '2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5',
|
|
7
|
+
});
|
|
8
|
+
expect(result).toBe('avax:8aDU0Kqh-5d23op-B-r-4YbQFRbsgF9a');
|
|
9
|
+
});
|
|
10
|
+
it('hashes the c-chain testnet blockchain id', () => {
|
|
11
|
+
const result = hashBlockchainId({
|
|
12
|
+
blockchainId: 'yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp',
|
|
13
|
+
isTestnet: true,
|
|
14
|
+
});
|
|
15
|
+
expect(result).toBe('avax:YRLfeDBJpfEqUWe2FYR1OpXsnDDZeKWd');
|
|
16
|
+
});
|
|
17
|
+
it('hashes the p-chain mainnet blockchain id', () => {
|
|
18
|
+
const result = hashBlockchainId({
|
|
19
|
+
blockchainId: '11111111111111111111111111111111LpoYY',
|
|
20
|
+
});
|
|
21
|
+
expect(result).toBe('avax:Rr9hnPVPxuUvrdCul-vjEsU1zmqKqRDo');
|
|
22
|
+
});
|
|
23
|
+
it('hashes the p-chain testnet blockchain id', () => {
|
|
24
|
+
const result = hashBlockchainId({
|
|
25
|
+
blockchainId: '11111111111111111111111111111111LpoYY',
|
|
26
|
+
isTestnet: true,
|
|
27
|
+
});
|
|
28
|
+
expect(result).toBe('avax:Sj7NVE3jXTbJvwFAiu7OEUo_8g8ctXMG');
|
|
29
|
+
});
|
|
30
|
+
it('hashes the x-chain mainnet blockchain id', () => {
|
|
31
|
+
const result = hashBlockchainId({
|
|
32
|
+
blockchainId: '2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM',
|
|
33
|
+
});
|
|
34
|
+
expect(result).toBe('avax:imji8papUf2EhV3le337w1vgFauqkJg-');
|
|
35
|
+
});
|
|
36
|
+
it('hashes the x-chain testnet blockchain id', () => {
|
|
37
|
+
const result = hashBlockchainId({
|
|
38
|
+
blockchainId: '2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm',
|
|
39
|
+
isTestnet: true,
|
|
40
|
+
});
|
|
41
|
+
expect(result).toBe('avax:8AJTpRj3SAqv1e80Mtl9em08LhvKEbkl');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
//github.com/gergelylovas/chain-agnostic-namespaces/pull/1/files#diff-cf7185539a48e85d069d194c1c17d7cfa0317b3caa3a89c92e797e3717e49d59R40
|
|
4
|
+
export function hashBlockchainId({ blockchainId, isTestnet }: { blockchainId: string; isTestnet?: boolean }): string {
|
|
5
|
+
const blockChainIdWithPrefix = isTestnet ? 'fuji' + blockchainId : blockchainId;
|
|
6
|
+
const base64 = Crypto.createHash('sha256').update(blockChainIdWithPrefix).digest('base64');
|
|
7
|
+
const hash = convertBase64ToBase64Url(base64).substring(0, 32);
|
|
8
|
+
return 'avax:' + hash;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const convertBase64ToBase64Url = (base64: string) => base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|