@pezkuwi/keyring 14.0.12 → 14.0.14

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.
Files changed (179) hide show
  1. package/bundle-pezkuwi-keyring.js +1 -1
  2. package/cjs/packageInfo.js +1 -1
  3. package/cjs/pair/defaults.d.ts +2 -2
  4. package/package.json +11 -11
  5. package/packageInfo.js +1 -1
  6. package/pair/defaults.d.ts +2 -2
  7. package/build/LICENSE +0 -201
  8. package/build/README.md +0 -17
  9. package/build/bundle-pezkuwi-keyring.js +0 -553
  10. package/build/bundle.d.ts +0 -7
  11. package/build/bundle.js +0 -7
  12. package/build/cjs/bundle.d.ts +0 -7
  13. package/build/cjs/bundle.js +0 -19
  14. package/build/cjs/defaults.d.ts +0 -2
  15. package/build/cjs/defaults.js +0 -5
  16. package/build/cjs/index.d.ts +0 -4
  17. package/build/cjs/index.js +0 -7
  18. package/build/cjs/keyring.d.ts +0 -145
  19. package/build/cjs/keyring.js +0 -261
  20. package/build/cjs/package.json +0 -3
  21. package/build/cjs/packageDetect.d.ts +0 -1
  22. package/build/cjs/packageDetect.js +0 -7
  23. package/build/cjs/packageInfo.d.ts +0 -6
  24. package/build/cjs/packageInfo.js +0 -4
  25. package/build/cjs/pair/decode.d.ts +0 -12
  26. package/build/cjs/pair/decode.js +0 -45
  27. package/build/cjs/pair/defaults.d.ts +0 -12
  28. package/build/cjs/pair/defaults.js +0 -15
  29. package/build/cjs/pair/encode.d.ts +0 -5
  30. package/build/cjs/pair/encode.js +0 -22
  31. package/build/cjs/pair/index.d.ts +0 -40
  32. package/build/cjs/pair/index.js +0 -183
  33. package/build/cjs/pair/nobody.d.ts +0 -2
  34. package/build/cjs/pair/nobody.js +0 -43
  35. package/build/cjs/pair/toJson.d.ts +0 -8
  36. package/build/cjs/pair/toJson.js +0 -11
  37. package/build/cjs/pair/types.d.ts +0 -5
  38. package/build/cjs/pair/types.js +0 -2
  39. package/build/cjs/pairs.d.ts +0 -8
  40. package/build/cjs/pairs.js +0 -28
  41. package/build/cjs/testing.d.ts +0 -20
  42. package/build/cjs/testing.js +0 -126
  43. package/build/cjs/testingPairs.d.ts +0 -25
  44. package/build/cjs/testingPairs.js +0 -16
  45. package/build/cjs/types.d.ts +0 -111
  46. package/build/cjs/types.js +0 -2
  47. package/build/defaults.d.ts +0 -2
  48. package/build/defaults.js +0 -2
  49. package/build/index.d.ts +0 -4
  50. package/build/index.js +0 -4
  51. package/build/keyring.d.ts +0 -145
  52. package/build/keyring.js +0 -257
  53. package/build/package.json +0 -294
  54. package/build/packageDetect.d.ts +0 -1
  55. package/build/packageDetect.js +0 -5
  56. package/build/packageInfo.d.ts +0 -6
  57. package/build/packageInfo.js +0 -1
  58. package/build/pair/decode.d.ts +0 -12
  59. package/build/pair/decode.js +0 -42
  60. package/build/pair/defaults.d.ts +0 -12
  61. package/build/pair/defaults.js +0 -12
  62. package/build/pair/encode.d.ts +0 -5
  63. package/build/pair/encode.js +0 -19
  64. package/build/pair/index.d.ts +0 -40
  65. package/build/pair/index.js +0 -180
  66. package/build/pair/nobody.d.ts +0 -2
  67. package/build/pair/nobody.js +0 -40
  68. package/build/pair/toJson.d.ts +0 -8
  69. package/build/pair/toJson.js +0 -8
  70. package/build/pair/types.d.ts +0 -5
  71. package/build/pair/types.js +0 -1
  72. package/build/pairs.d.ts +0 -8
  73. package/build/pairs.js +0 -24
  74. package/build/testing.d.ts +0 -20
  75. package/build/testing.js +0 -122
  76. package/build/testingPairs.d.ts +0 -25
  77. package/build/testingPairs.js +0 -13
  78. package/build/types.d.ts +0 -111
  79. package/build/types.js +0 -1
  80. package/build-deno/README.md +0 -17
  81. package/build-deno/bundle.ts +0 -10
  82. package/build-deno/defaults.ts +0 -4
  83. package/build-deno/index.ts +0 -8
  84. package/build-deno/keyring.ts +0 -305
  85. package/build-deno/mod.ts +0 -2
  86. package/build-deno/packageDetect.ts +0 -9
  87. package/build-deno/packageInfo.ts +0 -3
  88. package/build-deno/pair/decode.ts +0 -54
  89. package/build-deno/pair/defaults.ts +0 -18
  90. package/build-deno/pair/encode.ts +0 -28
  91. package/build-deno/pair/index.ts +0 -218
  92. package/build-deno/pair/nobody.ts +0 -58
  93. package/build-deno/pair/toJson.ts +0 -18
  94. package/build-deno/pair/types.ts +0 -6
  95. package/build-deno/pairs.ts +0 -39
  96. package/build-deno/testing.ts +0 -150
  97. package/build-deno/testingPairs.ts +0 -54
  98. package/build-deno/types.ts +0 -129
  99. package/build-tsc/bundle.d.ts +0 -7
  100. package/build-tsc/defaults.d.ts +0 -2
  101. package/build-tsc/index.d.ts +0 -4
  102. package/build-tsc/keyring.d.ts +0 -145
  103. package/build-tsc/packageDetect.d.ts +0 -1
  104. package/build-tsc/packageInfo.d.ts +0 -6
  105. package/build-tsc/pair/decode.d.ts +0 -12
  106. package/build-tsc/pair/defaults.d.ts +0 -12
  107. package/build-tsc/pair/encode.d.ts +0 -5
  108. package/build-tsc/pair/index.d.ts +0 -40
  109. package/build-tsc/pair/nobody.d.ts +0 -2
  110. package/build-tsc/pair/toJson.d.ts +0 -8
  111. package/build-tsc/pair/types.d.ts +0 -5
  112. package/build-tsc/pairs.d.ts +0 -8
  113. package/build-tsc/testing.d.ts +0 -20
  114. package/build-tsc/testingPairs.d.ts +0 -25
  115. package/build-tsc/types.d.ts +0 -111
  116. package/build-tsc-cjs/bundle.js +0 -19
  117. package/build-tsc-cjs/defaults.js +0 -5
  118. package/build-tsc-cjs/index.js +0 -7
  119. package/build-tsc-cjs/keyring.js +0 -261
  120. package/build-tsc-cjs/packageDetect.js +0 -7
  121. package/build-tsc-cjs/packageInfo.js +0 -4
  122. package/build-tsc-cjs/pair/decode.js +0 -45
  123. package/build-tsc-cjs/pair/defaults.js +0 -15
  124. package/build-tsc-cjs/pair/encode.js +0 -22
  125. package/build-tsc-cjs/pair/index.js +0 -183
  126. package/build-tsc-cjs/pair/nobody.js +0 -43
  127. package/build-tsc-cjs/pair/toJson.js +0 -11
  128. package/build-tsc-cjs/pair/types.js +0 -2
  129. package/build-tsc-cjs/pairs.js +0 -28
  130. package/build-tsc-cjs/testing.js +0 -126
  131. package/build-tsc-cjs/testingPairs.js +0 -16
  132. package/build-tsc-cjs/types.js +0 -2
  133. package/build-tsc-esm/bundle.js +0 -7
  134. package/build-tsc-esm/defaults.js +0 -2
  135. package/build-tsc-esm/index.js +0 -4
  136. package/build-tsc-esm/keyring.js +0 -257
  137. package/build-tsc-esm/packageDetect.js +0 -5
  138. package/build-tsc-esm/packageInfo.js +0 -1
  139. package/build-tsc-esm/pair/decode.js +0 -42
  140. package/build-tsc-esm/pair/defaults.js +0 -12
  141. package/build-tsc-esm/pair/encode.js +0 -19
  142. package/build-tsc-esm/pair/index.js +0 -180
  143. package/build-tsc-esm/pair/nobody.js +0 -40
  144. package/build-tsc-esm/pair/toJson.js +0 -8
  145. package/build-tsc-esm/pair/types.js +0 -1
  146. package/build-tsc-esm/pairs.js +0 -24
  147. package/build-tsc-esm/testing.js +0 -122
  148. package/build-tsc-esm/testingPairs.js +0 -13
  149. package/build-tsc-esm/types.js +0 -1
  150. package/src/bundle.ts +0 -16
  151. package/src/defaults.ts +0 -8
  152. package/src/index.spec.ts +0 -609
  153. package/src/index.ts +0 -10
  154. package/src/keyring.ts +0 -307
  155. package/src/mod.ts +0 -4
  156. package/src/packageDetect.ts +0 -13
  157. package/src/packageInfo.ts +0 -6
  158. package/src/pair/decode.spec.ts +0 -26
  159. package/src/pair/decode.ts +0 -56
  160. package/src/pair/defaults.ts +0 -20
  161. package/src/pair/encode.spec.ts +0 -28
  162. package/src/pair/encode.ts +0 -30
  163. package/src/pair/index.spec.ts +0 -189
  164. package/src/pair/index.ts +0 -220
  165. package/src/pair/nobody.ts +0 -62
  166. package/src/pair/toJson.spec.ts +0 -42
  167. package/src/pair/toJson.ts +0 -20
  168. package/src/pair/types.ts +0 -8
  169. package/src/pair/vrf.spec.ts +0 -47
  170. package/src/pairs.ts +0 -41
  171. package/src/suri.spec.ts +0 -109
  172. package/src/testing.ts +0 -156
  173. package/src/testingPairs.spec.ts +0 -79
  174. package/src/testingPairs.ts +0 -56
  175. package/src/types.ts +0 -131
  176. package/tsconfig.build.json +0 -16
  177. package/tsconfig.build.tsbuildinfo +0 -1
  178. package/tsconfig.spec.json +0 -18
  179. package/tsconfig.spec.tsbuildinfo +0 -1
@@ -1,40 +0,0 @@
1
- import type { EncryptedJsonEncoding, KeypairType } from '@pezkuwi/util-crypto/types';
2
- import type { KeyringPair, KeyringPair$Meta } from '../types.js';
3
- import type { PairInfo } from './types.js';
4
- interface Setup {
5
- toSS58: (publicKey: Uint8Array) => string;
6
- type: KeypairType;
7
- }
8
- /**
9
- * @name createPair
10
- * @summary Creates a keyring pair object
11
- * @description Creates a keyring pair object with provided account public key, metadata, and encoded arguments.
12
- * The keyring pair stores the account state including the encoded address and associated metadata.
13
- *
14
- * It has properties whose values are functions that may be called to perform account actions:
15
- *
16
- * - `address` function retrieves the address associated with the account.
17
- * - `decodedPkcs8` function is called with the account passphrase and account encoded public key.
18
- * It decodes the encoded public key using the passphrase provided to obtain the decoded account public key
19
- * and associated secret key that are then available in memory, and changes the account address stored in the
20
- * state of the pair to correspond to the address of the decoded public key.
21
- * - `encodePkcs8` function when provided with the correct passphrase associated with the account pair
22
- * and when the secret key is in memory (when the account pair is not locked) it returns an encoded
23
- * public key of the account.
24
- * - `meta` is the metadata that is stored in the state of the pair, either when it was originally
25
- * created or set via `setMeta`.
26
- * - `publicKey` returns the public key stored in memory for the pair.
27
- * - `sign` may be used to return a signature by signing a provided message with the secret
28
- * key (if it is in memory) using Nacl.
29
- * - `toJson` calls another `toJson` function and provides the state of the pair,
30
- * it generates arguments to be passed to the other `toJson` function including an encoded public key of the account
31
- * that it generates using the secret key from memory (if it has been made available in memory)
32
- * and the optionally provided passphrase argument. It passes a third boolean argument to `toJson`
33
- * indicating whether the public key has been encoded or not (if a passphrase argument was provided then it is encoded).
34
- * The `toJson` function that it calls returns a JSON object with properties including the `address`
35
- * and `meta` that are assigned with the values stored in the corresponding state variables of the account pair,
36
- * an `encoded` property that is assigned with the encoded public key in hex format, and an `encoding`
37
- * property that indicates whether the public key value of the `encoded` property is encoded or not.
38
- */
39
- export declare function createPair({ toSS58, type }: Setup, { publicKey, secretKey }: PairInfo, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, encTypes?: EncryptedJsonEncoding[]): KeyringPair;
40
- export {};
@@ -1,2 +0,0 @@
1
- import type { KeyringPair } from '../types.js';
2
- export declare function nobody(): KeyringPair;
@@ -1,8 +0,0 @@
1
- import type { KeypairType } from '@pezkuwi/util-crypto/types';
2
- import type { KeyringPair$Json, KeyringPair$Meta } from '../types.js';
3
- interface PairStateJson {
4
- address: string;
5
- meta: KeyringPair$Meta;
6
- }
7
- export declare function pairToJson(type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json;
8
- export {};
@@ -1,5 +0,0 @@
1
- export interface PairInfo {
2
- publicKey: Uint8Array;
3
- secretKey?: Uint8Array | undefined;
4
- seed?: Uint8Array | null;
5
- }
@@ -1,8 +0,0 @@
1
- import type { KeyringPair, KeyringPairs } from './types.js';
2
- export declare class Pairs implements KeyringPairs {
3
- #private;
4
- add(pair: KeyringPair): KeyringPair;
5
- all(): KeyringPair[];
6
- get(address: string | Uint8Array): KeyringPair;
7
- remove(address: string | Uint8Array): void;
8
- }
@@ -1,20 +0,0 @@
1
- import type { HexString } from '@pezkuwi/util/types';
2
- import type { KeypairType } from '@pezkuwi/util-crypto/types';
3
- import type { KeyringInstance, KeyringOptions } from './types.js';
4
- interface PairDef {
5
- name?: string;
6
- p: HexString;
7
- s: HexString;
8
- seed?: string;
9
- type: KeypairType;
10
- }
11
- export declare const PAIRSSR25519: PairDef[];
12
- export declare const PAIRSETHEREUM: PairDef[];
13
- /**
14
- * @name testKeyring
15
- * @summary Create an instance of Keyring pre-populated with locked test accounts
16
- * @description The test accounts (i.e. alice, bob, dave, eve, ferdie)
17
- * are available on the dev chain and each test account is initialized with DOT funds.
18
- */
19
- export declare function createTestKeyring(options?: KeyringOptions, isDerived?: boolean): KeyringInstance;
20
- export {};
@@ -1,25 +0,0 @@
1
- import type { KeypairType } from '@pezkuwi/util-crypto/types';
2
- import type { KeyringOptions, KeyringPair } from './types.js';
3
- export interface TestKeyringMap {
4
- nobody: KeyringPair;
5
- [index: string]: KeyringPair;
6
- }
7
- export interface TestKeyringMapBizinikiwi extends TestKeyringMap {
8
- alice: KeyringPair;
9
- bob: KeyringPair;
10
- charlie: KeyringPair;
11
- dave: KeyringPair;
12
- eve: KeyringPair;
13
- ferdie: KeyringPair;
14
- }
15
- export interface TestKeyringMapEthereum extends TestKeyringMap {
16
- Alith: KeyringPair;
17
- Baltathar: KeyringPair;
18
- Charleth: KeyringPair;
19
- Dorothy: KeyringPair;
20
- Ethan: KeyringPair;
21
- Faith: KeyringPair;
22
- }
23
- export type DetectMap<O extends KeyringOptions | undefined> = DetectPairType<O> extends 'ethereum' ? TestKeyringMapEthereum : TestKeyringMapBizinikiwi;
24
- export type DetectPairType<O extends KeyringOptions | undefined> = O extends KeyringOptions ? O['type'] extends KeypairType ? O['type'] : 'sr25519' : 'sr25519';
25
- export declare function createTestPairs<O extends KeyringOptions, M = DetectMap<O>>(options?: O, isDerived?: boolean): M;
@@ -1,111 +0,0 @@
1
- import type { HexString } from '@pezkuwi/util/types';
2
- import type { EncryptedJson, Keypair, KeypairType, Prefix } from '@pezkuwi/util-crypto/types';
3
- export interface KeyringOptions {
4
- /** The ss58Format to use for address encoding (defaults to 42) */
5
- ss58Format?: Prefix;
6
- /** The type of keyring to create (defaults to ed25519) */
7
- type?: KeypairType;
8
- }
9
- export interface KeyringPair$MetaHardware {
10
- accountIndex?: number;
11
- accountOffset?: number;
12
- addressOffset?: number;
13
- hardwareType?: 'ledger';
14
- }
15
- export interface KeyringPair$MetaFlags {
16
- isDefaultAuthSelected?: boolean;
17
- isExternal?: boolean;
18
- isHardware?: boolean;
19
- isHidden?: boolean;
20
- isInjected?: boolean;
21
- isMultisig?: boolean;
22
- isProxied?: boolean;
23
- isRecent?: boolean;
24
- isTesting?: boolean;
25
- }
26
- export interface KeyringPair$MetaContract {
27
- abi: string;
28
- genesisHash?: HexString | null;
29
- }
30
- export interface KeyringPair$MetaExtension {
31
- source?: string;
32
- }
33
- export interface KeyringPair$MetaMultisig {
34
- threshold?: number;
35
- who?: string[];
36
- }
37
- export interface KeyringPair$MetaParent {
38
- parentAddress?: string;
39
- parentName?: string;
40
- }
41
- export interface KeyringPair$Meta extends KeyringPair$MetaExtension, KeyringPair$MetaFlags, KeyringPair$MetaHardware, KeyringPair$MetaMultisig, KeyringPair$MetaParent {
42
- address?: string;
43
- contract?: KeyringPair$MetaContract;
44
- genesisHash?: HexString | null;
45
- name?: string;
46
- suri?: string;
47
- tags?: string[];
48
- type?: KeypairType;
49
- whenCreated?: number;
50
- whenEdited?: number;
51
- whenUsed?: number;
52
- [key: string]: unknown;
53
- }
54
- export interface KeyringPair$Json extends EncryptedJson {
55
- /** The ss58 encoded address or the hex-encoded version (the latter is for ETH-compat chains) */
56
- address: string;
57
- /** The underlying metadata associated with the keypair */
58
- meta: KeyringPair$Meta;
59
- }
60
- export interface SignOptions {
61
- /** Create a MultiSignature-compatible output with an indicator type */
62
- withType?: boolean;
63
- }
64
- export interface KeyringPair {
65
- readonly address: string;
66
- readonly addressRaw: Uint8Array;
67
- readonly meta: KeyringPair$Meta;
68
- readonly isLocked: boolean;
69
- readonly publicKey: Uint8Array;
70
- readonly type: KeypairType;
71
- decodePkcs8(passphrase?: string, encoded?: Uint8Array): void;
72
- derive(suri: string, meta?: KeyringPair$Meta): KeyringPair;
73
- encodePkcs8(passphrase?: string): Uint8Array;
74
- lock(): void;
75
- setMeta(meta: KeyringPair$Meta): void;
76
- sign(message: string | Uint8Array, options?: SignOptions): Uint8Array;
77
- toJson(passphrase?: string): KeyringPair$Json;
78
- unlock(passphrase?: string): void;
79
- verify(message: string | Uint8Array, signature: Uint8Array, signerPublic: string | Uint8Array): boolean;
80
- vrfSign(message: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array;
81
- vrfVerify(message: string | Uint8Array, vrfResult: Uint8Array, signerPublic: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): boolean;
82
- }
83
- export interface KeyringPairs {
84
- add: (pair: KeyringPair) => KeyringPair;
85
- all: () => KeyringPair[];
86
- get: (address: string | Uint8Array) => KeyringPair;
87
- remove: (address: string | Uint8Array) => void;
88
- }
89
- export interface KeyringInstance {
90
- readonly pairs: KeyringPair[];
91
- readonly publicKeys: Uint8Array[];
92
- readonly type: KeypairType;
93
- decodeAddress(encoded: string | Uint8Array, ignoreChecksum?: boolean, ss58Format?: Prefix): Uint8Array;
94
- encodeAddress(key: Uint8Array | string, ss58Format?: Prefix): string;
95
- setSS58Format(ss58Format: Prefix): void;
96
- addPair(pair: KeyringPair): KeyringPair;
97
- addFromAddress(address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
98
- addFromJson(pair: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
99
- addFromMnemonic(mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
100
- addFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
101
- addFromSeed(seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
102
- addFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
103
- createFromJson(json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
104
- createFromPair(pair: Keypair, meta: KeyringPair$Meta, type: KeypairType): KeyringPair;
105
- createFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
106
- getPair(address: string | Uint8Array): KeyringPair;
107
- getPairs(): KeyringPair[];
108
- getPublicKeys(): Uint8Array[];
109
- removePair(address: string | Uint8Array): void;
110
- toJson(address: string | Uint8Array, passphrase?: string): KeyringPair$Json;
111
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTestPairs = exports.createTestKeyring = exports.createPair = exports.packageInfo = exports.Keyring = exports.setSS58Format = exports.encodeAddress = exports.decodeAddress = void 0;
4
- const tslib_1 = require("tslib");
5
- var util_crypto_1 = require("@pezkuwi/util-crypto");
6
- Object.defineProperty(exports, "decodeAddress", { enumerable: true, get: function () { return util_crypto_1.decodeAddress; } });
7
- Object.defineProperty(exports, "encodeAddress", { enumerable: true, get: function () { return util_crypto_1.encodeAddress; } });
8
- Object.defineProperty(exports, "setSS58Format", { enumerable: true, get: function () { return util_crypto_1.setSS58Format; } });
9
- var keyring_js_1 = require("./keyring.js");
10
- Object.defineProperty(exports, "Keyring", { enumerable: true, get: function () { return keyring_js_1.Keyring; } });
11
- var packageInfo_js_1 = require("./packageInfo.js");
12
- Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
13
- var index_js_1 = require("./pair/index.js");
14
- Object.defineProperty(exports, "createPair", { enumerable: true, get: function () { return index_js_1.createPair; } });
15
- var testing_js_1 = require("./testing.js");
16
- Object.defineProperty(exports, "createTestKeyring", { enumerable: true, get: function () { return testing_js_1.createTestKeyring; } });
17
- var testingPairs_js_1 = require("./testingPairs.js");
18
- Object.defineProperty(exports, "createTestPairs", { enumerable: true, get: function () { return testingPairs_js_1.createTestPairs; } });
19
- tslib_1.__exportStar(require("./defaults.js"), exports);
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEV_SEED = exports.DEV_PHRASE = void 0;
4
- exports.DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
5
- exports.DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- require("./packageDetect.js");
5
- const bundle_js_1 = require("./bundle.js");
6
- tslib_1.__exportStar(require("./bundle.js"), exports);
7
- exports.default = bundle_js_1.Keyring;
@@ -1,261 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Keyring = void 0;
4
- const util_1 = require("@pezkuwi/util");
5
- const util_crypto_1 = require("@pezkuwi/util-crypto");
6
- const index_js_1 = require("./pair/index.js");
7
- const defaults_js_1 = require("./defaults.js");
8
- const pairs_js_1 = require("./pairs.js");
9
- const PairFromSeed = {
10
- ecdsa: (seed) => (0, util_crypto_1.secp256k1PairFromSeed)(seed),
11
- ed25519: (seed) => (0, util_crypto_1.ed25519PairFromSeed)(seed),
12
- ethereum: (seed) => (0, util_crypto_1.secp256k1PairFromSeed)(seed),
13
- sr25519: (seed) => (0, util_crypto_1.sr25519PairFromSeed)(seed)
14
- };
15
- function pairToPublic({ publicKey }) {
16
- return publicKey;
17
- }
18
- /**
19
- * # @pezkuwi/keyring
20
- *
21
- * ## Overview
22
- *
23
- * @name Keyring
24
- * @summary Keyring management of user accounts
25
- * @description Allows generation of keyring pairs from a variety of input combinations, such as
26
- * json object containing account address or public key, account metadata, and account encoded using
27
- * `addFromJson`, or by providing those values as arguments separately to `addFromAddress`,
28
- * or by providing the mnemonic (seed phrase) and account metadata as arguments to `addFromMnemonic`.
29
- * Stores the keyring pairs in a keyring pair dictionary. Removal of the keyring pairs from the keyring pair
30
- * dictionary is achieved using `removePair`. Retrieval of all the stored pairs via `getPairs` or perform
31
- * lookup of a pair for a given account address or public key using `getPair`. JSON metadata associated with
32
- * an account may be obtained using `toJson` accompanied by the account passphrase.
33
- */
34
- class Keyring {
35
- #pairs;
36
- #type;
37
- #ss58;
38
- decodeAddress = util_crypto_1.decodeAddress;
39
- constructor(options = {}) {
40
- options.type = options.type || 'ed25519';
41
- if (!['ecdsa', 'ethereum', 'ed25519', 'sr25519'].includes(options.type || 'undefined')) {
42
- throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${options.type || 'unknown'}`);
43
- }
44
- this.#pairs = new pairs_js_1.Pairs();
45
- this.#ss58 = options.ss58Format;
46
- this.#type = options.type;
47
- }
48
- /**
49
- * @description retrieve the pairs (alias for getPairs)
50
- */
51
- get pairs() {
52
- return this.getPairs();
53
- }
54
- /**
55
- * @description retrieve the publicKeys (alias for getPublicKeys)
56
- */
57
- get publicKeys() {
58
- return this.getPublicKeys();
59
- }
60
- /**
61
- * @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
62
- */
63
- get type() {
64
- return this.#type;
65
- }
66
- /**
67
- * @name addPair
68
- * @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
69
- */
70
- addPair(pair) {
71
- return this.#pairs.add(pair);
72
- }
73
- /**
74
- * @name addFromAddress
75
- * @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
76
- * @description Allows user to explicitly provide separate inputs including account address or public key, and optionally
77
- * the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file
78
- * of an account backup), and then generates a keyring pair from them that it passes to
79
- * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
80
- */
81
- addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
82
- const publicKey = this.decodeAddress(address, ignoreChecksum);
83
- return this.addPair((0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
84
- }
85
- /**
86
- * @name addFromJson
87
- * @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
88
- * @description Allows user to provide a json object argument that contains account information (that may be obtained from the json file
89
- * of an account backup), and then generates a keyring pair from it that it passes to
90
- * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
91
- */
92
- addFromJson(json, ignoreChecksum) {
93
- return this.addPair(this.createFromJson(json, ignoreChecksum));
94
- }
95
- /**
96
- * @name addFromMnemonic
97
- * @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
98
- * @description Allows user to provide a mnemonic (seed phrase that is provided when account is originally created)
99
- * argument and a metadata argument that contains account information (that may be obtained from the json file
100
- * of an account backup), and then generates a keyring pair from it that it passes to
101
- * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
102
- */
103
- addFromMnemonic(mnemonic, meta = {}, type = this.type, wordlist) {
104
- return this.addFromUri(mnemonic, meta, type, wordlist);
105
- }
106
- /**
107
- * @name addFromPair
108
- * @summary Stores an account created from an explicit publicKey/secreteKey combination
109
- */
110
- addFromPair(pair, meta = {}, type = this.type) {
111
- return this.addPair(this.createFromPair(pair, meta, type));
112
- }
113
- /**
114
- * @name addFromSeed
115
- * @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
116
- * @description Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.
117
- * Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
118
- * `addPair` to store in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
119
- */
120
- addFromSeed(seed, meta = {}, type = this.type) {
121
- return this.addPair((0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
122
- }
123
- /**
124
- * @name addFromUri
125
- * @summary Creates an account via an suri
126
- * @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
127
- */
128
- addFromUri(suri, meta = {}, type = this.type, wordlist) {
129
- return this.addPair(this.createFromUri(suri, meta, type, wordlist));
130
- }
131
- /**
132
- * @name createFromJson
133
- * @description Creates a pair from a JSON keyfile
134
- */
135
- createFromJson({ address, encoded, encoding: { content, type, version }, meta }, ignoreChecksum) {
136
- if (version === '3' && content[0] !== 'pkcs8') {
137
- throw new Error(`Unable to decode non-pkcs8 type, [${content.join(',')}] found}`);
138
- }
139
- const cryptoType = version === '0' || !Array.isArray(content)
140
- ? this.type
141
- : content[1];
142
- const encType = !Array.isArray(type)
143
- ? [type]
144
- : type;
145
- if (!['ed25519', 'sr25519', 'ecdsa', 'ethereum'].includes(cryptoType)) {
146
- throw new Error(`Unknown crypto type ${cryptoType}`);
147
- }
148
- // Here the address and publicKey are 32 bytes and isomorphic. This is why the address field needs to be the public key for ethereum type pairs
149
- const publicKey = (0, util_1.isHex)(address)
150
- ? (0, util_1.hexToU8a)(address)
151
- : this.decodeAddress(address, ignoreChecksum);
152
- const decoded = (0, util_1.isHex)(encoded)
153
- ? (0, util_1.hexToU8a)(encoded)
154
- : (0, util_crypto_1.base64Decode)(encoded);
155
- return (0, index_js_1.createPair)({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
156
- }
157
- /**
158
- * @name createFromPair
159
- * @summary Creates a pair from an explicit publicKey/secreteKey combination
160
- */
161
- createFromPair(pair, meta = {}, type = this.type) {
162
- return (0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, pair, meta, null);
163
- }
164
- /**
165
- * @name createFromUri
166
- * @summary Creates a Keypair from an suri
167
- * @description This creates a pair from the suri, but does not add it to the keyring
168
- */
169
- createFromUri(_suri, meta = {}, type = this.type, wordlist) {
170
- // here we only aut-add the dev phrase if we have a hard-derived path
171
- const suri = _suri.startsWith('//')
172
- ? `${defaults_js_1.DEV_PHRASE}${_suri}`
173
- : _suri;
174
- const { derivePath, password, path, phrase } = (0, util_crypto_1.keyExtractSuri)(suri);
175
- let seed;
176
- const isPhraseHex = (0, util_1.isHex)(phrase, 256);
177
- if (isPhraseHex) {
178
- seed = (0, util_1.hexToU8a)(phrase);
179
- }
180
- else {
181
- const parts = phrase.split(' ');
182
- if ([12, 15, 18, 21, 24].includes(parts.length)) {
183
- seed = type === 'ethereum'
184
- ? (0, util_crypto_1.mnemonicToLegacySeed)(phrase, '', false, 64)
185
- : (0, util_crypto_1.mnemonicToMiniSecret)(phrase, password, wordlist);
186
- }
187
- else {
188
- if (phrase.length > 32) {
189
- throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');
190
- }
191
- seed = (0, util_1.stringToU8a)(phrase.padEnd(32));
192
- }
193
- }
194
- const derived = type === 'ethereum'
195
- ? isPhraseHex
196
- ? PairFromSeed[type](seed) // for eth, if the private key is provided as suri, it must be derived only once
197
- : (0, util_crypto_1.hdEthereum)(seed, derivePath.substring(1))
198
- : (0, util_crypto_1.keyFromPath)(PairFromSeed[type](seed), path, type);
199
- return (0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, derived, meta, null);
200
- }
201
- /**
202
- * @name encodeAddress
203
- * @description Encodes the input into an ss58 representation
204
- */
205
- encodeAddress = (address, ss58Format) => {
206
- return this.type === 'ethereum'
207
- ? (0, util_crypto_1.ethereumEncode)(address)
208
- : (0, util_crypto_1.encodeAddress)(address, ss58Format ?? this.#ss58);
209
- };
210
- /**
211
- * @name getPair
212
- * @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
213
- * @description Returns a keyring pair value from the keyring pair dictionary by performing
214
- * a key lookup using the provided account address or public key (after decoding it).
215
- */
216
- getPair(address) {
217
- return this.#pairs.get(address);
218
- }
219
- /**
220
- * @name getPairs
221
- * @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
222
- * @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
223
- */
224
- getPairs() {
225
- return this.#pairs.all();
226
- }
227
- /**
228
- * @name getPublicKeys
229
- * @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
230
- * @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
231
- */
232
- getPublicKeys() {
233
- return this.#pairs.all().map(pairToPublic);
234
- }
235
- /**
236
- * @name removePair
237
- * @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
238
- */
239
- removePair(address) {
240
- this.#pairs.remove(address);
241
- }
242
- /**
243
- * @name setSS58Format;
244
- * @description Sets the ss58 format for the keyring
245
- */
246
- setSS58Format(ss58) {
247
- this.#ss58 = ss58;
248
- }
249
- /**
250
- * @name toJson
251
- * @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
252
- * @description Returns a JSON object containing the metadata associated with an account
253
- * when valid address or public key and when the account passphrase is provided if the account secret
254
- * is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user
255
- * may backup their account to a JSON file that contains this information.
256
- */
257
- toJson(address, passphrase) {
258
- return this.#pairs.get(address).toJson(passphrase);
259
- }
260
- }
261
- exports.Keyring = Keyring;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("@pezkuwi/util");
4
- const packageInfo_1 = require("@pezkuwi/util/packageInfo");
5
- const packageInfo_2 = require("@pezkuwi/util-crypto/packageInfo");
6
- const packageInfo_js_1 = require("./packageInfo.js");
7
- (0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_2.packageInfo, packageInfo_1.packageInfo]);
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packageInfo = void 0;
4
- exports.packageInfo = { name: '@pezkuwi/keyring', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '14.0.12' };
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodePair = decodePair;
4
- const util_1 = require("@pezkuwi/util");
5
- const util_crypto_1 = require("@pezkuwi/util-crypto");
6
- const defaults_js_1 = require("./defaults.js");
7
- const SEED_OFFSET = defaults_js_1.PAIR_HDR.length;
8
- /**
9
- * Decode a pair, taking into account the generation-specific formats and headers
10
- *
11
- * For divisor/headers, don't rely on the magic being static. These will
12
- * change between generations, aka with the long-awaited 4th generation
13
- * of the format. The external decode interface is the only way to use and decode these.
14
- **/
15
- function decodePair(passphrase, encrypted, _encType) {
16
- const encType = Array.isArray(_encType) || _encType === undefined
17
- ? _encType
18
- : [_encType];
19
- const decrypted = (0, util_crypto_1.jsonDecryptData)(encrypted, passphrase, encType);
20
- const header = decrypted.subarray(0, defaults_js_1.PAIR_HDR.length);
21
- // check the start header (generations 1-3)
22
- if (!(0, util_1.u8aEq)(header, defaults_js_1.PAIR_HDR)) {
23
- throw new Error('Invalid encoding header found in body');
24
- }
25
- // setup for generation 3 format
26
- let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + defaults_js_1.SEC_LENGTH);
27
- let divOffset = SEED_OFFSET + defaults_js_1.SEC_LENGTH;
28
- let divider = decrypted.subarray(divOffset, divOffset + defaults_js_1.PAIR_DIV.length);
29
- // old-style (generation 1 & 2), we have the seed here
30
- if (!(0, util_1.u8aEq)(divider, defaults_js_1.PAIR_DIV)) {
31
- divOffset = SEED_OFFSET + defaults_js_1.SEED_LENGTH;
32
- secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
33
- divider = decrypted.subarray(divOffset, divOffset + defaults_js_1.PAIR_DIV.length);
34
- // check the divisior at this point (already checked for generation 3)
35
- if (!(0, util_1.u8aEq)(divider, defaults_js_1.PAIR_DIV)) {
36
- throw new Error('Invalid encoding divider found in body');
37
- }
38
- }
39
- const pubOffset = divOffset + defaults_js_1.PAIR_DIV.length;
40
- const publicKey = decrypted.subarray(pubOffset, pubOffset + defaults_js_1.PUB_LENGTH);
41
- return {
42
- publicKey,
43
- secretKey
44
- };
45
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SEED_LENGTH = exports.SEC_LENGTH = exports.SALT_LENGTH = exports.PUB_LENGTH = exports.PAIR_HDR = exports.PAIR_DIV = void 0;
4
- /** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
5
- exports.PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
6
- /** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
7
- exports.PAIR_HDR = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
8
- /** length of a public key */
9
- exports.PUB_LENGTH = 32;
10
- /** length of a salt */
11
- exports.SALT_LENGTH = 32;
12
- /** length of a secret key */
13
- exports.SEC_LENGTH = 64;
14
- /** length of a user-input seed */
15
- exports.SEED_LENGTH = 32;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodePair = encodePair;
4
- const util_1 = require("@pezkuwi/util");
5
- const util_crypto_1 = require("@pezkuwi/util-crypto");
6
- const defaults_js_1 = require("./defaults.js");
7
- /**
8
- * Encode a pair with the latest generation format (generation 3)
9
- **/
10
- function encodePair({ publicKey, secretKey }, passphrase) {
11
- if (!secretKey) {
12
- throw new Error('Expected a valid secretKey to be passed to encode');
13
- }
14
- const encoded = (0, util_1.u8aConcat)(defaults_js_1.PAIR_HDR, secretKey, defaults_js_1.PAIR_DIV, publicKey);
15
- if (!passphrase) {
16
- return encoded;
17
- }
18
- // this is only for generation 3 (previous generations are only handled in decoding)
19
- const { params, password, salt } = (0, util_crypto_1.scryptEncode)(passphrase);
20
- const { encrypted, nonce } = (0, util_crypto_1.naclEncrypt)(encoded, password.subarray(0, 32));
21
- return (0, util_1.u8aConcat)((0, util_crypto_1.scryptToU8a)(salt, params), nonce, encrypted);
22
- }