@pezkuwi/keyring 14.0.6 → 14.0.10
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/build/LICENSE +201 -0
- package/build/README.md +17 -0
- package/{bundle-pezkuwi-keyring.js → build/bundle-pezkuwi-keyring.js} +1 -1
- package/build/bundle.js +7 -0
- package/build/cjs/bundle.d.ts +7 -0
- package/build/cjs/bundle.js +19 -0
- package/build/cjs/defaults.js +5 -0
- package/build/cjs/index.js +7 -0
- package/build/cjs/keyring.js +261 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/pair/decode.js +45 -0
- package/build/cjs/pair/defaults.js +15 -0
- package/build/cjs/pair/encode.js +22 -0
- package/build/cjs/pair/index.js +183 -0
- package/build/cjs/pair/nobody.js +43 -0
- package/build/cjs/pair/toJson.js +11 -0
- package/build/cjs/pair/types.js +2 -0
- package/build/cjs/pairs.js +28 -0
- package/build/cjs/testing.js +126 -0
- package/build/cjs/testingPairs.js +16 -0
- package/build/cjs/types.js +2 -0
- package/build/defaults.d.ts +2 -0
- package/build/defaults.js +2 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/build/keyring.d.ts +145 -0
- package/build/keyring.js +257 -0
- package/build/package.json +294 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +5 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/pair/decode.d.ts +12 -0
- package/build/pair/decode.js +42 -0
- package/build/pair/defaults.d.ts +12 -0
- package/build/pair/defaults.js +12 -0
- package/build/pair/encode.d.ts +5 -0
- package/build/pair/encode.js +19 -0
- package/build/pair/index.d.ts +40 -0
- package/build/pair/index.js +180 -0
- package/build/pair/nobody.d.ts +2 -0
- package/build/pair/nobody.js +40 -0
- package/build/pair/toJson.d.ts +8 -0
- package/build/pair/toJson.js +8 -0
- package/build/pair/types.d.ts +5 -0
- package/build/pair/types.js +1 -0
- package/build/pairs.d.ts +8 -0
- package/build/pairs.js +24 -0
- package/build/testing.d.ts +20 -0
- package/build/testing.js +122 -0
- package/build/testingPairs.d.ts +25 -0
- package/build/testingPairs.js +13 -0
- package/build/types.d.ts +111 -0
- package/build/types.js +1 -0
- package/build-deno/README.md +17 -0
- package/build-deno/bundle.ts +10 -0
- package/build-deno/defaults.ts +4 -0
- package/build-deno/index.ts +8 -0
- package/build-deno/keyring.ts +305 -0
- package/build-deno/mod.ts +2 -0
- package/build-deno/packageDetect.ts +9 -0
- package/build-deno/packageInfo.ts +3 -0
- package/build-deno/pair/decode.ts +54 -0
- package/build-deno/pair/defaults.ts +18 -0
- package/build-deno/pair/encode.ts +28 -0
- package/build-deno/pair/index.ts +218 -0
- package/build-deno/pair/nobody.ts +58 -0
- package/build-deno/pair/toJson.ts +18 -0
- package/build-deno/pair/types.ts +6 -0
- package/build-deno/pairs.ts +39 -0
- package/build-deno/testing.ts +150 -0
- package/build-deno/testingPairs.ts +54 -0
- package/build-deno/types.ts +129 -0
- package/build-tsc-cjs/packageDetect.js +7 -0
- package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
- package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
- package/package.json +9 -271
- package/src/bundle.ts +16 -0
- package/src/defaults.ts +8 -0
- package/src/index.spec.ts +609 -0
- package/src/index.ts +10 -0
- package/src/keyring.ts +307 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +13 -0
- package/src/packageInfo.ts +6 -0
- package/src/pair/decode.spec.ts +26 -0
- package/src/pair/decode.ts +56 -0
- package/src/pair/defaults.ts +20 -0
- package/src/pair/encode.spec.ts +28 -0
- package/src/pair/encode.ts +30 -0
- package/src/pair/index.spec.ts +189 -0
- package/src/pair/index.ts +220 -0
- package/src/pair/nobody.ts +62 -0
- package/src/pair/toJson.spec.ts +42 -0
- package/src/pair/toJson.ts +20 -0
- package/src/pair/types.ts +8 -0
- package/src/pair/vrf.spec.ts +47 -0
- package/src/pairs.ts +41 -0
- package/src/suri.spec.ts +109 -0
- package/src/testing.ts +156 -0
- package/src/testingPairs.spec.ts +79 -0
- package/src/testingPairs.ts +56 -0
- package/src/types.ts +131 -0
- package/tsconfig.build.json +16 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +18 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
- /package/{cjs → build}/bundle.d.ts +0 -0
- /package/{defaults.d.ts → build/cjs/defaults.d.ts} +0 -0
- /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
- /package/{keyring.d.ts → build/cjs/keyring.d.ts} +0 -0
- /package/{cjs → build/cjs}/package.json +0 -0
- /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
- /package/{cjs → build/cjs}/packageDetect.js +0 -0
- /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
- /package/{pair → build/cjs/pair}/decode.d.ts +0 -0
- /package/{pair → build/cjs/pair}/defaults.d.ts +0 -0
- /package/{pair → build/cjs/pair}/encode.d.ts +0 -0
- /package/{pair → build/cjs/pair}/index.d.ts +0 -0
- /package/{pair → build/cjs/pair}/nobody.d.ts +0 -0
- /package/{pair → build/cjs/pair}/toJson.d.ts +0 -0
- /package/{pair → build/cjs/pair}/types.d.ts +0 -0
- /package/{pairs.d.ts → build/cjs/pairs.d.ts} +0 -0
- /package/{testing.d.ts → build/cjs/testing.d.ts} +0 -0
- /package/{testingPairs.d.ts → build/cjs/testingPairs.d.ts} +0 -0
- /package/{types.d.ts → build/cjs/types.d.ts} +0 -0
- /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
- /package/{cjs → build-tsc}/defaults.d.ts +0 -0
- /package/{cjs → build-tsc}/index.d.ts +0 -0
- /package/{cjs → build-tsc}/keyring.d.ts +0 -0
- /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
- /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
- /package/{cjs → build-tsc}/pair/decode.d.ts +0 -0
- /package/{cjs → build-tsc}/pair/defaults.d.ts +0 -0
- /package/{cjs → build-tsc}/pair/encode.d.ts +0 -0
- /package/{cjs → build-tsc}/pair/index.d.ts +0 -0
- /package/{cjs → build-tsc}/pair/nobody.d.ts +0 -0
- /package/{cjs → build-tsc}/pair/toJson.d.ts +0 -0
- /package/{cjs → build-tsc}/pair/types.d.ts +0 -0
- /package/{cjs → build-tsc}/pairs.d.ts +0 -0
- /package/{cjs → build-tsc}/testing.d.ts +0 -0
- /package/{cjs → build-tsc}/testingPairs.d.ts +0 -0
- /package/{cjs → build-tsc}/types.d.ts +0 -0
- /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
- /package/{cjs → build-tsc-cjs}/defaults.js +0 -0
- /package/{cjs → build-tsc-cjs}/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/keyring.js +0 -0
- /package/{cjs → build-tsc-cjs}/pair/decode.js +0 -0
- /package/{cjs → build-tsc-cjs}/pair/defaults.js +0 -0
- /package/{cjs → build-tsc-cjs}/pair/encode.js +0 -0
- /package/{cjs → build-tsc-cjs}/pair/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/pair/nobody.js +0 -0
- /package/{cjs → build-tsc-cjs}/pair/toJson.js +0 -0
- /package/{cjs → build-tsc-cjs}/pair/types.js +0 -0
- /package/{cjs → build-tsc-cjs}/pairs.js +0 -0
- /package/{cjs → build-tsc-cjs}/testing.js +0 -0
- /package/{cjs → build-tsc-cjs}/testingPairs.js +0 -0
- /package/{cjs → build-tsc-cjs}/types.js +0 -0
- /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
- /package/{defaults.js → build-tsc-esm/defaults.js} +0 -0
- /package/{index.js → build-tsc-esm/index.js} +0 -0
- /package/{keyring.js → build-tsc-esm/keyring.js} +0 -0
- /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
- /package/{pair → build-tsc-esm/pair}/decode.js +0 -0
- /package/{pair → build-tsc-esm/pair}/defaults.js +0 -0
- /package/{pair → build-tsc-esm/pair}/encode.js +0 -0
- /package/{pair → build-tsc-esm/pair}/index.js +0 -0
- /package/{pair → build-tsc-esm/pair}/nobody.js +0 -0
- /package/{pair → build-tsc-esm/pair}/toJson.js +0 -0
- /package/{pair → build-tsc-esm/pair}/types.js +0 -0
- /package/{pairs.js → build-tsc-esm/pairs.js} +0 -0
- /package/{testing.js → build-tsc-esm/testing.js} +0 -0
- /package/{testingPairs.js → build-tsc-esm/testingPairs.js} +0 -0
- /package/{types.js → build-tsc-esm/types.js} +0 -0
package/src/suri.spec.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/keyring authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
// From https://github.com/paritytech/substrate/wiki/Secret-URI-Test-Vectors
|
|
7
|
+
|
|
8
|
+
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
|
9
|
+
|
|
10
|
+
import { u8aToHex } from '@pezkuwi/util';
|
|
11
|
+
import { cryptoWaitReady } from '@pezkuwi/util-crypto';
|
|
12
|
+
|
|
13
|
+
import Keyring from './index.js';
|
|
14
|
+
|
|
15
|
+
const PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
|
16
|
+
const ETHEREUM_PHRASE = 'seed sock milk update focus rotate barely fade car face mechanic mercy';
|
|
17
|
+
|
|
18
|
+
const TESTS = {
|
|
19
|
+
ecdsa: [
|
|
20
|
+
{
|
|
21
|
+
pk: '0x020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1',
|
|
22
|
+
ss: '5C7C2Z5sWbytvHpuLTvzKunnnRwQxft1jiqrLD5rhucQ5S9X',
|
|
23
|
+
uri: `${PHRASE}//Alice`
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
ethereum: [
|
|
27
|
+
{
|
|
28
|
+
pk: '0x0381351b1b46d2602b0992bb5d5531f9c1696b0812feb2534b6884adc47e2e1d8b',
|
|
29
|
+
ss: '0x31ea8795EE32D782C8ff41a5C68Dcbf0F5B27f6d',
|
|
30
|
+
uri: `${ETHEREUM_PHRASE}/m/44'/60'/0'/0/0`
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
pk: '0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f',
|
|
34
|
+
ss: '0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac',
|
|
35
|
+
uri: `${PHRASE}/m/44'/60'/0'/0/0`
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
pk: '0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518',
|
|
39
|
+
ss: '0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0',
|
|
40
|
+
uri: `${PHRASE}/m/44'/60'/0'/0/1`
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
sr25519: [
|
|
44
|
+
{
|
|
45
|
+
pk: '0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a',
|
|
46
|
+
ss: '5DfhGyQdFobKM8NsWvEeAKk5EQQgYe9AydgJ7rMB6E1EqRzV',
|
|
47
|
+
uri: PHRASE
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
pk: '0xb69355deefa7a8f33e9297f5af22e680f03597a99d4f4b1c44be47e7a2275802',
|
|
51
|
+
ss: '5GC6LfpV352HtJPySfAecb5JdePtf4R9Vq49NUU8RhzgBqgq',
|
|
52
|
+
uri: `${PHRASE}///password`
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
pk: '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a',
|
|
56
|
+
ss: '5DXZzrDxHbkQov4QBAY4TjpwnHCMrKXkomTnKSw8UArBEY5v',
|
|
57
|
+
uri: `${PHRASE}/foo`
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
pk: '0x547d4a55642ec7ebadc0bd29b6e570b8c926059b3c0655d4948075e9a7e6f31e',
|
|
61
|
+
ss: '5DyV6fZuvPemWrUqBgWwTSgoV86w6xms3KhkFU6cQcWxU8eP',
|
|
62
|
+
uri: `${PHRASE}//foo`
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
pk: '0x3841947ffcde6f5fef26fb68b59bb8665637e30e32ec2051f99cf6b9c674fe09',
|
|
66
|
+
ss: '5DLU27is5iViNopQb2KxsTyPx6j4vCu8X3sk3j3NNLkPCqKM',
|
|
67
|
+
uri: `${PHRASE}//foo/bar`
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
pk: '0xdc142f7476a7b0aa262aeccf207f1d18daa90762db393006741e8a31f39dbc53',
|
|
71
|
+
ss: '5H3GPTqDSpjkfDwbHy12PD6BWm8jvGSX4xYC8UMprHpTPcRg',
|
|
72
|
+
uri: `${PHRASE}/foo//bar`
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
pk: '0xa2e56b06407a6d1e819d2fc33fa0ec604b29c2e868b70b3696bb049b8725934b',
|
|
76
|
+
ss: '5FkHmNgbg64MwStgCyDi2Uw3ufFu11mqQgmWT9uwK4Lghvpv',
|
|
77
|
+
uri: `${PHRASE}//foo/bar//42/69`
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
pk: '0x0e0d24e3e1ff2c07f269c99e2e0df8681fda1851ac42fc846ca2daaa90cd8f14',
|
|
81
|
+
ss: '5CP8S23JBNXYNpJsL7ESPJBNnUZE6itcfM4EnDxEhaVEU6dT',
|
|
82
|
+
uri: `${PHRASE}//foo/bar//42/69///password`
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
pk: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
|
|
86
|
+
ss: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
|
87
|
+
uri: `${PHRASE}//Alice`
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
await cryptoWaitReady();
|
|
93
|
+
|
|
94
|
+
describe('keyring.addFromUri', (): void => {
|
|
95
|
+
for (const [type, tests] of Object.entries(TESTS)) {
|
|
96
|
+
const keyring = new Keyring({ type: type as KeypairType });
|
|
97
|
+
|
|
98
|
+
describe(`${type}`, (): void => {
|
|
99
|
+
tests.forEach(({ pk, ss, uri }): void => {
|
|
100
|
+
it(`creates ${uri}`, (): void => {
|
|
101
|
+
const pair = keyring.addFromUri(uri, {}, type as KeypairType);
|
|
102
|
+
|
|
103
|
+
expect(u8aToHex(pair.publicKey)).toEqual(pk);
|
|
104
|
+
expect(pair.address).toEqual(ss);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/keyring authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
5
|
+
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
|
6
|
+
import type { KeyringInstance, KeyringOptions } from './types.js';
|
|
7
|
+
|
|
8
|
+
import { hexToU8a } from '@pezkuwi/util';
|
|
9
|
+
|
|
10
|
+
import { createPair } from './pair/index.js';
|
|
11
|
+
import { Keyring } from './keyring.js';
|
|
12
|
+
|
|
13
|
+
interface PairDef {
|
|
14
|
+
name?: string;
|
|
15
|
+
p: HexString;
|
|
16
|
+
s: HexString;
|
|
17
|
+
seed?: string;
|
|
18
|
+
type: KeypairType
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// NOTE This is not great since we have the secretKey here explicitly, but a testing
|
|
22
|
+
// keyring is for testing - what happens is that in most cases the keyring is initialises
|
|
23
|
+
// before anything else. Since the sr25519 crypto is async, this creates problems with
|
|
24
|
+
// adding the keys when only the keyring is used.
|
|
25
|
+
export const PAIRSSR25519: PairDef[] = [
|
|
26
|
+
{
|
|
27
|
+
p: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
|
|
28
|
+
s: '0x98319d4ff8a9508c4bb0cf0b5a78d760a0b2082c02775e6e82370816fedfff48925a225d97aa00682d6a59b95b18780c10d7032336e88f3442b42361f4a66011', // nosemgrep
|
|
29
|
+
seed: 'Alice',
|
|
30
|
+
type: 'sr25519'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
p: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f',
|
|
34
|
+
s: '0xe8da6c9d810e020f5e3c7f5af2dea314cbeaa0d72bc6421e92c0808a0c584a6046ab28e97c3ffc77fe12b5a4d37e8cd4afbfebbf2391ffc7cb07c0f38c023efd', // nosemgrep
|
|
35
|
+
seed: 'Alice//stash',
|
|
36
|
+
type: 'sr25519'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
p: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48',
|
|
40
|
+
s: '0x081ff694633e255136bdb456c20a5fc8fed21f8b964c11bb17ff534ce80ebd5941ae88f85d0c1bfc37be41c904e1dfc01de8c8067b0d6d5df25dd1ac0894a325', // nosemgrep
|
|
41
|
+
seed: 'Bob',
|
|
42
|
+
type: 'sr25519'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
p: '0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e',
|
|
46
|
+
s: '0xc006507cdfc267a21532394c49ca9b754ca71de21e15a1cdf807c7ceab6d0b6c3ed408d9d35311540dcd54931933e67cf1ea10d46f75408f82b789d9bd212fde', // nosemgrep
|
|
47
|
+
seed: 'Bob//stash',
|
|
48
|
+
type: 'sr25519'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
p: '0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22',
|
|
52
|
+
s: '0xa8f2d83016052e5d6d77b2f6fd5d59418922a09024cda701b3c34369ec43a7668faf12ff39cd4e5d92bb773972f41a7a5279ebc2ed92264bed8f47d344f8f18c', // nosemgrep
|
|
53
|
+
seed: 'Charlie',
|
|
54
|
+
type: 'sr25519'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
p: '0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20',
|
|
58
|
+
s: '0x20e05482ca4677e0edbc58ae9a3a59f6ed3b1a9484ba17e64d6fe8688b2b7b5d108c4487b9323b98b11fe36cb301b084e920f7b7895536809a6d62a451b25568', // nosemgrep
|
|
59
|
+
seed: 'Dave',
|
|
60
|
+
type: 'sr25519'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
p: '0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e',
|
|
64
|
+
s: '0x683576abfd5dc35273e4264c23095a1bf21c14517bece57c7f0cc5c0ed4ce06a3dbf386b7828f348abe15d76973a72009e6ef86a5c91db2990cb36bb657c6587', // nosemgrep
|
|
65
|
+
seed: 'Eve',
|
|
66
|
+
type: 'sr25519'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
p: '0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c',
|
|
70
|
+
s: '0xb835c20f450079cf4f513900ae9faf8df06ad86c681884122c752a4b2bf74d4303e4f21bc6cc62bb4eeed5a9cce642c25e2d2ac1464093b50f6196d78e3a7426', // nosemgrep
|
|
71
|
+
seed: 'Ferdie',
|
|
72
|
+
type: 'sr25519'
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
export const PAIRSETHEREUM: PairDef[] = [
|
|
77
|
+
{
|
|
78
|
+
name: 'Alith',
|
|
79
|
+
p: '0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f',
|
|
80
|
+
s: '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133', // nosemgrep
|
|
81
|
+
type: 'ethereum'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'Baltathar',
|
|
85
|
+
p: '0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518',
|
|
86
|
+
s: '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b', // nosemgrep
|
|
87
|
+
type: 'ethereum'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'Charleth',
|
|
91
|
+
p: '0x0234637bdc0e89b5d46543bcbf8edff329d2702bc995e27e9af4b1ba009a3c2a5e',
|
|
92
|
+
s: '0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b', // nosemgrep
|
|
93
|
+
type: 'ethereum'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'Dorothy',
|
|
97
|
+
p: '0x02a00d60b2b408c2a14c5d70cdd2c205db8985ef737a7e55ad20ea32cc9e7c417c',
|
|
98
|
+
s: '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68', // nosemgrep
|
|
99
|
+
type: 'ethereum'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'Ethan',
|
|
103
|
+
p: '0x025cdc005b752651cd3f728fb9192182acb3a9c89e19072cbd5b03f3ee1f1b3ffa',
|
|
104
|
+
s: '0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4', // nosemgrep
|
|
105
|
+
type: 'ethereum'
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'Faith',
|
|
109
|
+
p: '0x037964b6c9d546da4646ada28a99e34acaa1d14e7aba861a9055f9bd200c8abf74',
|
|
110
|
+
s: '0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df', // nosemgrep
|
|
111
|
+
type: 'ethereum'
|
|
112
|
+
}
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
function createMeta (name?: string, seed?: string) {
|
|
116
|
+
if (!name && !seed) {
|
|
117
|
+
throw new Error('Testing pair should have either a name or a seed');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
isTesting: true,
|
|
122
|
+
name: name || seed?.replace('//', '_').toLowerCase()
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @name testKeyring
|
|
128
|
+
* @summary Create an instance of Keyring pre-populated with locked test accounts
|
|
129
|
+
* @description The test accounts (i.e. alice, bob, dave, eve, ferdie)
|
|
130
|
+
* are available on the dev chain and each test account is initialized with DOT funds.
|
|
131
|
+
*/
|
|
132
|
+
export function createTestKeyring (options: KeyringOptions = {}, isDerived = true): KeyringInstance {
|
|
133
|
+
const keyring = new Keyring(options);
|
|
134
|
+
const pairs = options.type === 'ethereum'
|
|
135
|
+
? PAIRSETHEREUM
|
|
136
|
+
: PAIRSSR25519;
|
|
137
|
+
|
|
138
|
+
for (const { name, p, s, seed, type } of pairs) {
|
|
139
|
+
const meta = createMeta(name, seed);
|
|
140
|
+
const pair = !isDerived && !name && seed
|
|
141
|
+
? keyring.addFromUri(seed, meta, options.type)
|
|
142
|
+
: keyring.addPair(
|
|
143
|
+
createPair(
|
|
144
|
+
{ toSS58: keyring.encodeAddress, type },
|
|
145
|
+
{ publicKey: hexToU8a(p), secretKey: hexToU8a(s) },
|
|
146
|
+
meta
|
|
147
|
+
)
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
pair.lock = (): void => {
|
|
151
|
+
// we don't have lock/unlock functionality here
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return keyring;
|
|
156
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/keyring authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import { u8aToHex } from '@pezkuwi/util';
|
|
7
|
+
import { cryptoWaitReady } from '@pezkuwi/util-crypto';
|
|
8
|
+
|
|
9
|
+
import Keyring from './index.js';
|
|
10
|
+
import { createTestPairs } from './testingPairs.js';
|
|
11
|
+
|
|
12
|
+
const TEST_ADD = '0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac';
|
|
13
|
+
|
|
14
|
+
await cryptoWaitReady();
|
|
15
|
+
|
|
16
|
+
describe('testingPairs', (): void => {
|
|
17
|
+
it('creates without failing', (): void => {
|
|
18
|
+
expect(
|
|
19
|
+
Object.keys(createTestPairs())
|
|
20
|
+
).toHaveLength(2 + 0 + 7); // stash, session, pairs
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('has the correct address for Alice (non-HDKD)', (): void => {
|
|
24
|
+
expect(
|
|
25
|
+
createTestPairs({ type: 'ed25519' }, false).alice.address
|
|
26
|
+
).toEqual('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('has the correct address for Alice (HDKD)', (): void => {
|
|
30
|
+
expect(
|
|
31
|
+
createTestPairs({ type: 'ed25519' }).alice.address
|
|
32
|
+
).toEqual('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('has the correct address for Alith (Eth)', (): void => {
|
|
36
|
+
expect(
|
|
37
|
+
createTestPairs({ type: 'ethereum' }).Alith.address
|
|
38
|
+
).toEqual(TEST_ADD);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('has the correct address for Alith (Eth), same as obtained by createFromUri', (): void => {
|
|
42
|
+
const keyring = new Keyring({ type: 'ethereum' });
|
|
43
|
+
const pair = keyring.createFromUri('0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133');
|
|
44
|
+
|
|
45
|
+
expect(pair?.address).toEqual(TEST_ADD);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('checks eth test addresses', (): void => {
|
|
49
|
+
const ring = createTestPairs({ type: 'ethereum' });
|
|
50
|
+
const keyring = new Keyring({ type: 'ethereum' });
|
|
51
|
+
// priv keys generated by ganache-cli --mnemonic "bottom drive obey lake curtain smoke basket hold race lonely fit walk"
|
|
52
|
+
const privKeys: string[] = ['0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133',
|
|
53
|
+
'0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b',
|
|
54
|
+
'0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b',
|
|
55
|
+
'0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68',
|
|
56
|
+
'0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4',
|
|
57
|
+
'0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df',
|
|
58
|
+
'0x96b8a38e12e1a31dee1eab2fffdf9d9990045f5b37e44d8cc27766ef294acf18',
|
|
59
|
+
'0x0d6dcaaef49272a5411896be8ad16c01c35d6f8c18873387b71fbc734759b0ab',
|
|
60
|
+
'0x4c42532034540267bf568198ccec4cb822a025da542861fcb146a5fab6433ff8',
|
|
61
|
+
'0x94c49300a58d576011096bcb006aa06f5a91b34b4383891e8029c21dc39fbb8b'];
|
|
62
|
+
|
|
63
|
+
// @ts-expect-error We should not delete from the maps, however this is a test
|
|
64
|
+
delete ring.nobody;
|
|
65
|
+
|
|
66
|
+
Object
|
|
67
|
+
.keys(ring)
|
|
68
|
+
.filter((_, i) => i < 6)
|
|
69
|
+
.forEach((testKeyring, i) => {
|
|
70
|
+
it(`checks #${i}`, (): void => {
|
|
71
|
+
expect(
|
|
72
|
+
u8aToHex(ring[testKeyring].publicKey)
|
|
73
|
+
).toEqual(
|
|
74
|
+
u8aToHex(keyring.createFromUri(privKeys[i]).publicKey)
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/keyring authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
|
5
|
+
import type { KeyringOptions, KeyringPair } from './types.js';
|
|
6
|
+
|
|
7
|
+
import { nobody } from './pair/nobody.js';
|
|
8
|
+
import { createTestKeyring } from './testing.js';
|
|
9
|
+
|
|
10
|
+
export interface TestKeyringMap {
|
|
11
|
+
nobody: KeyringPair;
|
|
12
|
+
|
|
13
|
+
[index: string]: KeyringPair;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TestKeyringMapBizinikiwi extends TestKeyringMap {
|
|
17
|
+
alice: KeyringPair;
|
|
18
|
+
bob: KeyringPair;
|
|
19
|
+
charlie: KeyringPair;
|
|
20
|
+
dave: KeyringPair;
|
|
21
|
+
eve: KeyringPair;
|
|
22
|
+
ferdie: KeyringPair;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TestKeyringMapEthereum extends TestKeyringMap {
|
|
26
|
+
Alith: KeyringPair;
|
|
27
|
+
Baltathar: KeyringPair;
|
|
28
|
+
Charleth: KeyringPair;
|
|
29
|
+
Dorothy: KeyringPair;
|
|
30
|
+
Ethan: KeyringPair;
|
|
31
|
+
Faith: KeyringPair;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type DetectMap<O extends KeyringOptions | undefined> = DetectPairType<O> extends 'ethereum'
|
|
35
|
+
? TestKeyringMapEthereum
|
|
36
|
+
: TestKeyringMapBizinikiwi;
|
|
37
|
+
|
|
38
|
+
export type DetectPairType<O extends KeyringOptions | undefined> = O extends KeyringOptions
|
|
39
|
+
? O['type'] extends KeypairType
|
|
40
|
+
? O['type']
|
|
41
|
+
: 'sr25519'
|
|
42
|
+
: 'sr25519';
|
|
43
|
+
|
|
44
|
+
export function createTestPairs <O extends KeyringOptions, M = DetectMap<O>> (options?: O, isDerived = true): M {
|
|
45
|
+
const keyring = createTestKeyring(options, isDerived);
|
|
46
|
+
const pairs = keyring.getPairs();
|
|
47
|
+
const map: TestKeyringMap = { nobody: nobody() };
|
|
48
|
+
|
|
49
|
+
for (const p of pairs) {
|
|
50
|
+
if (p.meta.name) {
|
|
51
|
+
map[p.meta.name] = p;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return map as M;
|
|
56
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/keyring authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
5
|
+
import type { EncryptedJson, Keypair, KeypairType, Prefix } from '@pezkuwi/util-crypto/types';
|
|
6
|
+
|
|
7
|
+
export interface KeyringOptions {
|
|
8
|
+
/** The ss58Format to use for address encoding (defaults to 42) */
|
|
9
|
+
ss58Format?: Prefix;
|
|
10
|
+
/** The type of keyring to create (defaults to ed25519) */
|
|
11
|
+
type?: KeypairType;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface KeyringPair$MetaHardware {
|
|
15
|
+
accountIndex?: number;
|
|
16
|
+
accountOffset?: number;
|
|
17
|
+
addressOffset?: number;
|
|
18
|
+
hardwareType?: 'ledger';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface KeyringPair$MetaFlags {
|
|
22
|
+
isDefaultAuthSelected?: boolean;
|
|
23
|
+
isExternal?: boolean;
|
|
24
|
+
isHardware?: boolean;
|
|
25
|
+
isHidden?: boolean;
|
|
26
|
+
isInjected?: boolean;
|
|
27
|
+
isMultisig?: boolean;
|
|
28
|
+
isProxied?: boolean;
|
|
29
|
+
isRecent?: boolean;
|
|
30
|
+
isTesting?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface KeyringPair$MetaContract {
|
|
34
|
+
abi: string;
|
|
35
|
+
genesisHash?: HexString | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface KeyringPair$MetaExtension {
|
|
39
|
+
source?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface KeyringPair$MetaMultisig {
|
|
43
|
+
threshold?: number;
|
|
44
|
+
who?: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface KeyringPair$MetaParent {
|
|
48
|
+
parentAddress?: string;
|
|
49
|
+
parentName?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface KeyringPair$Meta extends KeyringPair$MetaExtension, KeyringPair$MetaFlags, KeyringPair$MetaHardware, KeyringPair$MetaMultisig, KeyringPair$MetaParent {
|
|
53
|
+
address?: string;
|
|
54
|
+
contract?: KeyringPair$MetaContract;
|
|
55
|
+
genesisHash?: HexString | null;
|
|
56
|
+
name?: string;
|
|
57
|
+
suri?: string;
|
|
58
|
+
tags?: string[];
|
|
59
|
+
type?: KeypairType;
|
|
60
|
+
whenCreated?: number;
|
|
61
|
+
whenEdited?: number;
|
|
62
|
+
whenUsed?: number;
|
|
63
|
+
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface KeyringPair$Json extends EncryptedJson {
|
|
68
|
+
/** The ss58 encoded address or the hex-encoded version (the latter is for ETH-compat chains) */
|
|
69
|
+
address: string;
|
|
70
|
+
/** The underlying metadata associated with the keypair */
|
|
71
|
+
meta: KeyringPair$Meta;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SignOptions {
|
|
75
|
+
/** Create a MultiSignature-compatible output with an indicator type */
|
|
76
|
+
withType?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface KeyringPair {
|
|
80
|
+
readonly address: string;
|
|
81
|
+
readonly addressRaw: Uint8Array;
|
|
82
|
+
readonly meta: KeyringPair$Meta;
|
|
83
|
+
readonly isLocked: boolean;
|
|
84
|
+
readonly publicKey: Uint8Array;
|
|
85
|
+
readonly type: KeypairType;
|
|
86
|
+
|
|
87
|
+
decodePkcs8 (passphrase?: string, encoded?: Uint8Array): void;
|
|
88
|
+
derive (suri: string, meta?: KeyringPair$Meta): KeyringPair;
|
|
89
|
+
encodePkcs8 (passphrase?: string): Uint8Array;
|
|
90
|
+
lock (): void;
|
|
91
|
+
setMeta (meta: KeyringPair$Meta): void;
|
|
92
|
+
sign (message: string | Uint8Array, options?: SignOptions): Uint8Array;
|
|
93
|
+
toJson (passphrase?: string): KeyringPair$Json;
|
|
94
|
+
unlock (passphrase?: string): void;
|
|
95
|
+
verify (message: string | Uint8Array, signature: Uint8Array, signerPublic: string | Uint8Array): boolean;
|
|
96
|
+
vrfSign (message: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array;
|
|
97
|
+
vrfVerify (message: string | Uint8Array, vrfResult: Uint8Array, signerPublic: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface KeyringPairs {
|
|
101
|
+
add: (pair: KeyringPair) => KeyringPair;
|
|
102
|
+
all: () => KeyringPair[];
|
|
103
|
+
get: (address: string | Uint8Array) => KeyringPair;
|
|
104
|
+
remove: (address: string | Uint8Array) => void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface KeyringInstance {
|
|
108
|
+
readonly pairs: KeyringPair[];
|
|
109
|
+
readonly publicKeys: Uint8Array[];
|
|
110
|
+
readonly type: KeypairType;
|
|
111
|
+
|
|
112
|
+
decodeAddress (encoded: string | Uint8Array, ignoreChecksum?: boolean, ss58Format?: Prefix): Uint8Array;
|
|
113
|
+
encodeAddress (key: Uint8Array | string, ss58Format?: Prefix): string;
|
|
114
|
+
setSS58Format (ss58Format: Prefix): void;
|
|
115
|
+
|
|
116
|
+
addPair (pair: KeyringPair): KeyringPair;
|
|
117
|
+
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
|
|
118
|
+
addFromJson (pair: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
|
119
|
+
addFromMnemonic (mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
|
120
|
+
addFromPair (pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair
|
|
121
|
+
addFromSeed (seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
|
122
|
+
addFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
|
123
|
+
createFromJson (json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
|
124
|
+
createFromPair (pair: Keypair, meta: KeyringPair$Meta, type: KeypairType): KeyringPair
|
|
125
|
+
createFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
|
126
|
+
getPair (address: string | Uint8Array): KeyringPair;
|
|
127
|
+
getPairs (): KeyringPair[];
|
|
128
|
+
getPublicKeys (): Uint8Array[];
|
|
129
|
+
removePair (address: string | Uint8Array): void;
|
|
130
|
+
toJson (address: string | Uint8Array, passphrase?: string): KeyringPair$Json;
|
|
131
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": "..",
|
|
5
|
+
"outDir": "./build",
|
|
6
|
+
"rootDir": "./src"
|
|
7
|
+
},
|
|
8
|
+
"exclude": [
|
|
9
|
+
"**/*.spec.ts",
|
|
10
|
+
"**/mod.ts"
|
|
11
|
+
],
|
|
12
|
+
"references": [
|
|
13
|
+
{ "path": "../util/tsconfig.build.json" },
|
|
14
|
+
{ "path": "../util-crypto/tsconfig.build.json" }
|
|
15
|
+
]
|
|
16
|
+
}
|