@pezkuwi/ui-keyring 3.16.6

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/README.md +136 -0
  2. package/build/Base.d.ts +30 -0
  3. package/build/Base.js +109 -0
  4. package/build/Keyring.d.ts +49 -0
  5. package/build/Keyring.js +304 -0
  6. package/build/LICENSE +201 -0
  7. package/build/README.md +136 -0
  8. package/build/bundle-pezkuwi-ui-keyring.js +2751 -0
  9. package/build/bundle.d.ts +4 -0
  10. package/build/bundle.js +4 -0
  11. package/build/cjs/Base.d.ts +30 -0
  12. package/build/cjs/Base.js +113 -0
  13. package/build/cjs/Keyring.d.ts +49 -0
  14. package/build/cjs/Keyring.js +308 -0
  15. package/build/cjs/bundle.d.ts +4 -0
  16. package/build/cjs/bundle.js +8 -0
  17. package/build/cjs/defaults.d.ts +6 -0
  18. package/build/cjs/defaults.js +28 -0
  19. package/build/cjs/index.d.ts +4 -0
  20. package/build/cjs/index.js +7 -0
  21. package/build/cjs/observable/accounts.d.ts +1 -0
  22. package/build/cjs/observable/accounts.js +6 -0
  23. package/build/cjs/observable/addresses.d.ts +1 -0
  24. package/build/cjs/observable/addresses.js +6 -0
  25. package/build/cjs/observable/contracts.d.ts +1 -0
  26. package/build/cjs/observable/contracts.js +6 -0
  27. package/build/cjs/observable/env.d.ts +6 -0
  28. package/build/cjs/observable/env.js +12 -0
  29. package/build/cjs/observable/genericSubject.d.ts +2 -0
  30. package/build/cjs/observable/genericSubject.js +47 -0
  31. package/build/cjs/observable/index.d.ts +8 -0
  32. package/build/cjs/observable/index.js +16 -0
  33. package/build/cjs/observable/types.d.ts +15 -0
  34. package/build/cjs/observable/types.js +2 -0
  35. package/build/cjs/options/index.d.ts +15 -0
  36. package/build/cjs/options/index.js +116 -0
  37. package/build/cjs/options/item.d.ts +2 -0
  38. package/build/cjs/options/item.js +16 -0
  39. package/build/cjs/options/types.d.ts +15 -0
  40. package/build/cjs/options/types.js +2 -0
  41. package/build/cjs/package.json +3 -0
  42. package/build/cjs/packageDetect.d.ts +1 -0
  43. package/build/cjs/packageDetect.js +6 -0
  44. package/build/cjs/packageInfo.d.ts +6 -0
  45. package/build/cjs/packageInfo.js +4 -0
  46. package/build/cjs/stores/Browser.d.ts +7 -0
  47. package/build/cjs/stores/Browser.js +24 -0
  48. package/build/cjs/stores/File.d.ts +12 -0
  49. package/build/cjs/stores/File.js +72 -0
  50. package/build/cjs/stores/index.d.ts +2 -0
  51. package/build/cjs/stores/index.js +7 -0
  52. package/build/cjs/types.d.ts +78 -0
  53. package/build/cjs/types.js +2 -0
  54. package/build/defaults.d.ts +6 -0
  55. package/build/defaults.js +22 -0
  56. package/build/index.d.ts +4 -0
  57. package/build/index.js +4 -0
  58. package/build/observable/accounts.d.ts +1 -0
  59. package/build/observable/accounts.js +3 -0
  60. package/build/observable/addresses.d.ts +1 -0
  61. package/build/observable/addresses.js +3 -0
  62. package/build/observable/contracts.d.ts +1 -0
  63. package/build/observable/contracts.js +3 -0
  64. package/build/observable/env.d.ts +6 -0
  65. package/build/observable/env.js +9 -0
  66. package/build/observable/genericSubject.d.ts +2 -0
  67. package/build/observable/genericSubject.js +44 -0
  68. package/build/observable/index.d.ts +8 -0
  69. package/build/observable/index.js +13 -0
  70. package/build/observable/types.d.ts +15 -0
  71. package/build/observable/types.js +1 -0
  72. package/build/options/index.d.ts +15 -0
  73. package/build/options/index.js +112 -0
  74. package/build/options/item.d.ts +2 -0
  75. package/build/options/item.js +13 -0
  76. package/build/options/types.d.ts +15 -0
  77. package/build/options/types.js +1 -0
  78. package/build/package.json +355 -0
  79. package/build/packageDetect.d.ts +1 -0
  80. package/build/packageDetect.js +4 -0
  81. package/build/packageInfo.d.ts +6 -0
  82. package/build/packageInfo.js +1 -0
  83. package/build/stores/Browser.d.ts +7 -0
  84. package/build/stores/Browser.js +19 -0
  85. package/build/stores/File.d.ts +12 -0
  86. package/build/stores/File.js +67 -0
  87. package/build/stores/index.d.ts +2 -0
  88. package/build/stores/index.js +2 -0
  89. package/build/types.d.ts +78 -0
  90. package/build/types.js +1 -0
  91. package/build-tsc/Base.d.ts +30 -0
  92. package/build-tsc/Keyring.d.ts +49 -0
  93. package/build-tsc/bundle.d.ts +4 -0
  94. package/build-tsc/defaults.d.ts +6 -0
  95. package/build-tsc/index.d.ts +4 -0
  96. package/build-tsc/observable/accounts.d.ts +1 -0
  97. package/build-tsc/observable/addresses.d.ts +1 -0
  98. package/build-tsc/observable/contracts.d.ts +1 -0
  99. package/build-tsc/observable/env.d.ts +6 -0
  100. package/build-tsc/observable/genericSubject.d.ts +2 -0
  101. package/build-tsc/observable/index.d.ts +8 -0
  102. package/build-tsc/observable/types.d.ts +15 -0
  103. package/build-tsc/options/index.d.ts +15 -0
  104. package/build-tsc/options/item.d.ts +2 -0
  105. package/build-tsc/options/types.d.ts +15 -0
  106. package/build-tsc/packageDetect.d.ts +1 -0
  107. package/build-tsc/packageInfo.d.ts +6 -0
  108. package/build-tsc/stores/Browser.d.ts +7 -0
  109. package/build-tsc/stores/File.d.ts +12 -0
  110. package/build-tsc/stores/index.d.ts +2 -0
  111. package/build-tsc/types.d.ts +78 -0
  112. package/build-tsc-cjs/Base.js +113 -0
  113. package/build-tsc-cjs/Keyring.js +308 -0
  114. package/build-tsc-cjs/bundle.js +8 -0
  115. package/build-tsc-cjs/defaults.js +28 -0
  116. package/build-tsc-cjs/index.js +7 -0
  117. package/build-tsc-cjs/observable/accounts.js +6 -0
  118. package/build-tsc-cjs/observable/addresses.js +6 -0
  119. package/build-tsc-cjs/observable/contracts.js +6 -0
  120. package/build-tsc-cjs/observable/env.js +12 -0
  121. package/build-tsc-cjs/observable/genericSubject.js +47 -0
  122. package/build-tsc-cjs/observable/index.js +16 -0
  123. package/build-tsc-cjs/observable/types.js +2 -0
  124. package/build-tsc-cjs/options/index.js +116 -0
  125. package/build-tsc-cjs/options/item.js +16 -0
  126. package/build-tsc-cjs/options/types.js +2 -0
  127. package/build-tsc-cjs/packageDetect.js +6 -0
  128. package/build-tsc-cjs/packageInfo.js +4 -0
  129. package/build-tsc-cjs/stores/Browser.js +24 -0
  130. package/build-tsc-cjs/stores/File.js +72 -0
  131. package/build-tsc-cjs/stores/index.js +7 -0
  132. package/build-tsc-cjs/types.js +2 -0
  133. package/build-tsc-esm/Base.js +109 -0
  134. package/build-tsc-esm/Keyring.js +304 -0
  135. package/build-tsc-esm/bundle.js +4 -0
  136. package/build-tsc-esm/defaults.js +22 -0
  137. package/build-tsc-esm/index.js +4 -0
  138. package/build-tsc-esm/observable/accounts.js +3 -0
  139. package/build-tsc-esm/observable/addresses.js +3 -0
  140. package/build-tsc-esm/observable/contracts.js +3 -0
  141. package/build-tsc-esm/observable/env.js +9 -0
  142. package/build-tsc-esm/observable/genericSubject.js +44 -0
  143. package/build-tsc-esm/observable/index.js +13 -0
  144. package/build-tsc-esm/observable/types.js +1 -0
  145. package/build-tsc-esm/options/index.js +112 -0
  146. package/build-tsc-esm/options/item.js +13 -0
  147. package/build-tsc-esm/options/types.js +1 -0
  148. package/build-tsc-esm/packageDetect.js +4 -0
  149. package/build-tsc-esm/packageInfo.js +1 -0
  150. package/build-tsc-esm/stores/Browser.js +19 -0
  151. package/build-tsc-esm/stores/File.js +67 -0
  152. package/build-tsc-esm/stores/index.js +2 -0
  153. package/build-tsc-esm/types.js +1 -0
  154. package/package.json +41 -0
  155. package/src/Base.ts +156 -0
  156. package/src/Keyring.ts +420 -0
  157. package/src/bundle.ts +10 -0
  158. package/src/defaults.ts +34 -0
  159. package/src/index.ts +10 -0
  160. package/src/json.d.ts +11 -0
  161. package/src/observable/accounts.ts +7 -0
  162. package/src/observable/addresses.ts +7 -0
  163. package/src/observable/contracts.ts +7 -0
  164. package/src/observable/env.ts +15 -0
  165. package/src/observable/genericSubject.ts +66 -0
  166. package/src/observable/index.ts +28 -0
  167. package/src/observable/types.ts +21 -0
  168. package/src/options/index.ts +150 -0
  169. package/src/options/item.ts +22 -0
  170. package/src/options/types.ts +23 -0
  171. package/src/packageDetect.ts +12 -0
  172. package/src/packageInfo.ts +6 -0
  173. package/src/stores/Browser.ts +28 -0
  174. package/src/stores/File.ts +94 -0
  175. package/src/stores/index.ts +5 -0
  176. package/src/types.ts +91 -0
  177. package/tsconfig.build.json +14 -0
  178. package/tsconfig.build.tsbuildinfo +1 -0
  179. package/tsconfig.spec.json +16 -0
@@ -0,0 +1,67 @@
1
+ import { mkdirpSync } from 'mkdirp';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ export class FileStore {
5
+ #path;
6
+ constructor(path) {
7
+ if (!fs.existsSync(path)) {
8
+ mkdirpSync(path);
9
+ }
10
+ this.#path = path;
11
+ }
12
+ validateKey(key) {
13
+ // Make sure the key has a .json extension
14
+ if (!key.endsWith('.json')) {
15
+ console.error('Non-JSON file requested: ', key);
16
+ return false;
17
+ }
18
+ // Remove '.json'
19
+ const keyWithoutExtension = key.slice(0, -5);
20
+ // Only allow alphanumeric characters, hyphens, and underscores in the base filename
21
+ const safeKeyRegex = /^[a-zA-Z0-9_-]+$/;
22
+ if (!safeKeyRegex.test(keyWithoutExtension)) {
23
+ console.error('Invalid key format detected: ', key);
24
+ return false;
25
+ }
26
+ return true;
27
+ }
28
+ all(fn) {
29
+ fs
30
+ .readdirSync(this.#path)
31
+ .filter((key) => !['.', '..', '.DS_Store'].includes(key))
32
+ .forEach((key) => {
33
+ const value = this._readKey(key);
34
+ value?.address && fn(key, value);
35
+ });
36
+ }
37
+ get(key, fn) {
38
+ const value = this._readKey(key);
39
+ if (!value?.address) {
40
+ throw new Error(`Invalid JSON found for ${key}`);
41
+ }
42
+ fn(value);
43
+ }
44
+ remove(key, fn) {
45
+ fs.unlinkSync(this._getPath(key));
46
+ fn && fn();
47
+ }
48
+ set(key, value, fn) {
49
+ fs.writeFileSync(this._getPath(key), Buffer.from(JSON.stringify(value), 'utf-8'));
50
+ fn && fn();
51
+ }
52
+ _getPath(key) {
53
+ if (!this.validateKey(key)) {
54
+ throw new Error('Invalid key format');
55
+ }
56
+ return path.join(this.#path, key);
57
+ }
58
+ _readKey(key) {
59
+ try {
60
+ return JSON.parse(fs.readFileSync(this._getPath(key)).toString('utf-8'));
61
+ }
62
+ catch (error) {
63
+ console.error(error);
64
+ }
65
+ return undefined;
66
+ }
67
+ }
@@ -0,0 +1,2 @@
1
+ export { BrowserStore } from './Browser.js';
2
+ export { FileStore } from './File.js';
@@ -0,0 +1,2 @@
1
+ export { BrowserStore } from './Browser.js';
2
+ export { FileStore } from './File.js';
@@ -0,0 +1,78 @@
1
+ import type { KeyringInstance as BaseKeyringInstance, KeyringOptions as KeyringOptionsBase, KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '@pezkuwi/keyring/types';
2
+ import type { HexString } from '@pezkuwi/util/types';
3
+ import type { EncryptedJson } from '@pezkuwi/util-crypto/json/types';
4
+ import type { KeypairType } from '@pezkuwi/util-crypto/types';
5
+ import type { AddressSubject, SingleAddress } from './observable/types.js';
6
+ export type ContractMeta = NonNullable<KeyringPair$Meta['contract']>;
7
+ export type KeyringJson$Meta = KeyringPair$Meta;
8
+ export interface KeyringJson {
9
+ address: string;
10
+ meta: KeyringJson$Meta;
11
+ }
12
+ export interface KeyringPairs$Json extends EncryptedJson {
13
+ accounts: KeyringJson[];
14
+ }
15
+ export interface KeyringStore {
16
+ all: (cb: (key: string, value: KeyringJson) => void) => void;
17
+ get: (key: string, cb: (value: KeyringJson) => void) => void;
18
+ remove: (key: string, cb?: () => void) => void;
19
+ set: (key: string, value: KeyringJson, cb?: () => void) => void;
20
+ }
21
+ export interface KeyringOptions extends KeyringOptionsBase {
22
+ filter?: (json: KeyringJson) => boolean;
23
+ genesisHash?: HexString | {
24
+ toHex: () => HexString;
25
+ };
26
+ genesisHashAdd?: HexString[];
27
+ isDevelopment?: boolean;
28
+ store?: KeyringStore;
29
+ }
30
+ export interface KeyringAddress {
31
+ readonly address: string;
32
+ readonly meta: KeyringJson$Meta;
33
+ readonly publicKey: Uint8Array;
34
+ }
35
+ export type KeyringAddressType = 'address' | 'contract';
36
+ export type KeyringItemType = 'account' | KeyringAddressType;
37
+ export interface CreateResult {
38
+ json: KeyringPair$Json;
39
+ pair: KeyringPair;
40
+ }
41
+ export interface KeyringStruct {
42
+ readonly accounts: AddressSubject;
43
+ readonly addresses: AddressSubject;
44
+ readonly contracts: AddressSubject;
45
+ readonly keyring: BaseKeyringInstance | undefined;
46
+ readonly genesisHash?: string | undefined;
47
+ addExternal: (publicKey: Uint8Array, meta?: KeyringPair$Meta) => CreateResult;
48
+ addPair: (pair: KeyringPair, password: string) => CreateResult;
49
+ addUri: (suri: string, password?: string, meta?: KeyringPair$Meta, type?: KeypairType) => CreateResult;
50
+ backupAccount: (pair: KeyringPair, password: string) => KeyringPair$Json;
51
+ backupAccounts: (addresses: string[], password: string) => Promise<KeyringPairs$Json>;
52
+ createFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
53
+ decodeAddress: (key: string | Uint8Array) => Uint8Array;
54
+ encodeAddress: (key: string | Uint8Array) => string;
55
+ encryptAccount: (pair: KeyringPair, password: string) => void;
56
+ forgetAccount: (address: string) => void;
57
+ forgetAddress: (address: string) => void;
58
+ forgetContract: (address: string) => void;
59
+ getAccount: (address: string | Uint8Array) => KeyringAddress | undefined;
60
+ getAccounts: () => KeyringAddress[];
61
+ getAddress: (address: string | Uint8Array, type: KeyringItemType | null) => KeyringAddress | undefined;
62
+ getAddresses: () => KeyringAddress[];
63
+ getContract: (address: string | Uint8Array) => KeyringAddress | undefined;
64
+ getContracts: (genesisHash?: string) => KeyringAddress[];
65
+ getPair: (address: string | Uint8Array) => KeyringPair;
66
+ getPairs: () => KeyringPair[];
67
+ isAvailable: (address: string | Uint8Array) => boolean;
68
+ isPassValid: (password: string) => boolean;
69
+ loadAll: (options: KeyringOptions) => void;
70
+ restoreAccount: (json: KeyringPair$Json, password: string) => KeyringPair;
71
+ restoreAccounts: (json: EncryptedJson, password: string) => void;
72
+ saveAccount: (pair: KeyringPair, password?: string) => KeyringPair$Json;
73
+ saveAccountMeta: (pair: KeyringPair, meta: KeyringPair$Meta) => void;
74
+ saveAddress: (address: string, meta: KeyringPair$Meta) => KeyringPair$Json;
75
+ saveContract: (address: string, meta: KeyringPair$Meta) => KeyringPair$Json;
76
+ saveRecent: (address: string) => SingleAddress;
77
+ setDevMode: (isDevelopment: boolean) => void;
78
+ }
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { KeyringInstance, KeyringPair } from '@pezkuwi/keyring/types';
2
+ import type { HexString } from '@pezkuwi/util/types';
3
+ import type { Prefix } from '@pezkuwi/util-crypto/address/types';
4
+ import type { AddressSubject } from './observable/types.js';
5
+ import type { KeyringOptions, KeyringStore } from './types.js';
6
+ export declare class Base {
7
+ #private;
8
+ protected _store: KeyringStore;
9
+ protected _genesisHash?: HexString | undefined;
10
+ protected _genesisHashAdd: HexString[];
11
+ constructor();
12
+ get accounts(): AddressSubject;
13
+ get addresses(): AddressSubject;
14
+ get contracts(): AddressSubject;
15
+ get isEthereum(): boolean;
16
+ get keyring(): KeyringInstance;
17
+ get genesisHash(): HexString | undefined;
18
+ get genesisHashes(): HexString[];
19
+ decodeAddress: (key: string | Uint8Array, ignoreChecksum?: boolean, ss58Format?: Prefix) => Uint8Array;
20
+ encodeAddress: (key: string | Uint8Array, ss58Format?: Prefix) => string;
21
+ getPair(address: string | Uint8Array): KeyringPair;
22
+ getPairs(): KeyringPair[];
23
+ isAvailable(_address: Uint8Array | string): boolean;
24
+ isPassValid(password: string): boolean;
25
+ setSS58Format(ss58Format?: Prefix): void;
26
+ setDevMode(isDevelopment: boolean): void;
27
+ protected initKeyring(options: KeyringOptions): void;
28
+ protected addAccountPairs(): void;
29
+ protected addTimestamp(pair: KeyringPair): void;
30
+ }
@@ -0,0 +1,49 @@
1
+ import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '@pezkuwi/keyring/types';
2
+ import type { BN } from '@pezkuwi/util';
3
+ import type { EncryptedJson } from '@pezkuwi/util-crypto/json/types';
4
+ import type { KeypairType } from '@pezkuwi/util-crypto/types';
5
+ import type { SingleAddress } from './observable/types.js';
6
+ import type { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType, KeyringJson$Meta, KeyringOptions, KeyringPairs$Json, KeyringStruct } from './types.js';
7
+ import { KeyringOption } from './options/index.js';
8
+ import { Base } from './Base.js';
9
+ export declare class Keyring extends Base implements KeyringStruct {
10
+ #private;
11
+ readonly keyringOption: KeyringOption;
12
+ addExternal(address: string | Uint8Array, meta?: KeyringPair$Meta): CreateResult;
13
+ addHardware(address: string | Uint8Array, hardwareType: string, meta?: KeyringPair$Meta): CreateResult;
14
+ addMultisig(addresses: (string | Uint8Array)[], threshold: bigint | BN | number, meta?: KeyringPair$Meta): CreateResult;
15
+ addPair(pair: KeyringPair, password: string): CreateResult;
16
+ addUri(suri: string, password?: string, meta?: KeyringPair$Meta, type?: KeypairType): CreateResult;
17
+ backupAccount(pair: KeyringPair, password: string): KeyringPair$Json;
18
+ backupAccounts(addresses: string[], password: string): Promise<KeyringPairs$Json>;
19
+ createFromJson(json: KeyringPair$Json, meta?: KeyringPair$Meta): KeyringPair;
20
+ createFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
21
+ encryptAccount(pair: KeyringPair, password: string): void;
22
+ forgetAccount(address: string): void;
23
+ forgetAddress(address: string): void;
24
+ forgetContract(address: string): void;
25
+ getAccount(address: string | Uint8Array): KeyringAddress | undefined;
26
+ getAccounts(): KeyringAddress[];
27
+ getAddress(_address: string | Uint8Array, type?: KeyringItemType | null): KeyringAddress | undefined;
28
+ getAddresses(): KeyringAddress[];
29
+ getContract(address: string | Uint8Array): KeyringAddress | undefined;
30
+ getContracts(): KeyringAddress[];
31
+ private rewriteKey;
32
+ private loadAccount;
33
+ private loadAddress;
34
+ private loadContract;
35
+ private loadInjected;
36
+ private allowGenesis;
37
+ loadAll(options: KeyringOptions, injected?: {
38
+ address: string;
39
+ meta: KeyringJson$Meta;
40
+ type?: KeypairType;
41
+ }[]): void;
42
+ restoreAccount(json: KeyringPair$Json, password: string): KeyringPair;
43
+ restoreAccounts(json: EncryptedJson, password: string): void;
44
+ saveAccount(pair: KeyringPair, password?: string): KeyringPair$Json;
45
+ saveAccountMeta(pair: KeyringPair, meta: KeyringPair$Meta): void;
46
+ saveAddress(address: string, meta: KeyringPair$Meta, type?: KeyringAddressType): KeyringPair$Json;
47
+ saveContract(address: string, meta: KeyringPair$Meta): KeyringPair$Json;
48
+ saveRecent(address: string): SingleAddress;
49
+ }
@@ -0,0 +1,4 @@
1
+ import { Keyring } from './Keyring.js';
2
+ export { packageInfo } from './packageInfo.js';
3
+ export declare const keyring: Keyring;
4
+ export { Keyring };
@@ -0,0 +1,6 @@
1
+ export declare function accountKey(address: string): string;
2
+ export declare function addressKey(address: string): string;
3
+ export declare function contractKey(address: string): string;
4
+ export declare const accountRegex: RegExp;
5
+ export declare const addressRegex: RegExp;
6
+ export declare const contractRegex: RegExp;
@@ -0,0 +1,4 @@
1
+ import './packageDetect.js';
2
+ import { keyring } from './bundle.js';
3
+ export * from './bundle.js';
4
+ export default keyring;
@@ -0,0 +1 @@
1
+ export declare const accounts: import("./types.js").AddressSubject;
@@ -0,0 +1 @@
1
+ export declare const addresses: import("./types.js").AddressSubject;
@@ -0,0 +1 @@
1
+ export declare const contracts: import("./types.js").AddressSubject;
@@ -0,0 +1,6 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ export declare const env: {
3
+ isDevelopment: () => boolean;
4
+ set: (isDevelopment: boolean) => void;
5
+ subject: BehaviorSubject<boolean>;
6
+ };
@@ -0,0 +1,2 @@
1
+ import type { AddressSubject } from './types.js';
2
+ export declare function genericSubject(keyCreator: (address: string) => string, withTest?: boolean): AddressSubject;
@@ -0,0 +1,8 @@
1
+ import type { SubjectInfo } from './types.js';
2
+ interface Result {
3
+ accounts: SubjectInfo;
4
+ addresses: SubjectInfo;
5
+ contracts: SubjectInfo;
6
+ }
7
+ export declare const obervableAll: import("rxjs").Observable<Result>;
8
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { BehaviorSubject } from 'rxjs';
2
+ import type { KeypairType } from '@pezkuwi/util-crypto/types';
3
+ import type { KeyringSectionOption } from '../options/types.js';
4
+ import type { KeyringJson, KeyringStore } from '../types.js';
5
+ export interface SingleAddress {
6
+ json: KeyringJson;
7
+ option: KeyringSectionOption;
8
+ type?: KeypairType | undefined;
9
+ }
10
+ export type SubjectInfo = Record<string, SingleAddress>;
11
+ export interface AddressSubject {
12
+ add: (store: KeyringStore, address: string, json: KeyringJson, type?: KeypairType) => SingleAddress;
13
+ remove: (store: KeyringStore, address: string) => void;
14
+ subject: BehaviorSubject<SubjectInfo>;
15
+ }
@@ -0,0 +1,15 @@
1
+ import type { KeyringStruct } from '../types.js';
2
+ import type { KeyringOptionInstance, KeyringOptions, KeyringSectionOption } from './types.js';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ export declare class KeyringOption implements KeyringOptionInstance {
5
+ #private;
6
+ readonly optionsSubject: BehaviorSubject<KeyringOptions>;
7
+ createOptionHeader(name: string): KeyringSectionOption;
8
+ init(keyring: KeyringStruct): void;
9
+ clear(): void;
10
+ private linkItems;
11
+ private addAccounts;
12
+ private addAddresses;
13
+ private addContracts;
14
+ private emptyOptions;
15
+ }
@@ -0,0 +1,2 @@
1
+ import type { KeyringSectionOption } from './types.js';
2
+ export declare function createOptionItem(address: string, _name?: string): KeyringSectionOption;
@@ -0,0 +1,15 @@
1
+ import type { KeyringItemType, KeyringStruct } from '../types.js';
2
+ export interface KeyringSectionOption {
3
+ key: string | null;
4
+ name: string;
5
+ value: string | null;
6
+ }
7
+ export type KeyringSectionOptions = KeyringSectionOption[];
8
+ export type KeyringOptions = {
9
+ [type in KeyringItemType | 'all' | 'allPlus' | 'recent' | 'testing']: KeyringSectionOptions;
10
+ };
11
+ export type KeyringOption$Type = keyof KeyringOptions;
12
+ export interface KeyringOptionInstance {
13
+ createOptionHeader: (name: string) => KeyringSectionOption;
14
+ init: (keyring: KeyringStruct) => void;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1,7 @@
1
+ import type { KeyringJson, KeyringStore } from '../types.js';
2
+ export declare class BrowserStore implements KeyringStore {
3
+ all(fn: (key: string, value: KeyringJson) => void): void;
4
+ get(key: string, fn: (value: KeyringJson) => void): void;
5
+ remove(key: string, fn?: () => void): void;
6
+ set(key: string, value: KeyringJson, fn?: () => void): void;
7
+ }
@@ -0,0 +1,12 @@
1
+ import type { KeyringJson, KeyringStore } from '../types.js';
2
+ export declare class FileStore implements KeyringStore {
3
+ #private;
4
+ constructor(path: string);
5
+ private validateKey;
6
+ all(fn: (key: string, value: KeyringJson) => void): void;
7
+ get(key: string, fn: (value: KeyringJson) => void): void;
8
+ remove(key: string, fn?: () => void): void;
9
+ set(key: string, value: KeyringJson, fn?: () => void): void;
10
+ private _getPath;
11
+ private _readKey;
12
+ }
@@ -0,0 +1,2 @@
1
+ export { BrowserStore } from './Browser.js';
2
+ export { FileStore } from './File.js';
@@ -0,0 +1,78 @@
1
+ import type { KeyringInstance as BaseKeyringInstance, KeyringOptions as KeyringOptionsBase, KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '@pezkuwi/keyring/types';
2
+ import type { HexString } from '@pezkuwi/util/types';
3
+ import type { EncryptedJson } from '@pezkuwi/util-crypto/json/types';
4
+ import type { KeypairType } from '@pezkuwi/util-crypto/types';
5
+ import type { AddressSubject, SingleAddress } from './observable/types.js';
6
+ export type ContractMeta = NonNullable<KeyringPair$Meta['contract']>;
7
+ export type KeyringJson$Meta = KeyringPair$Meta;
8
+ export interface KeyringJson {
9
+ address: string;
10
+ meta: KeyringJson$Meta;
11
+ }
12
+ export interface KeyringPairs$Json extends EncryptedJson {
13
+ accounts: KeyringJson[];
14
+ }
15
+ export interface KeyringStore {
16
+ all: (cb: (key: string, value: KeyringJson) => void) => void;
17
+ get: (key: string, cb: (value: KeyringJson) => void) => void;
18
+ remove: (key: string, cb?: () => void) => void;
19
+ set: (key: string, value: KeyringJson, cb?: () => void) => void;
20
+ }
21
+ export interface KeyringOptions extends KeyringOptionsBase {
22
+ filter?: (json: KeyringJson) => boolean;
23
+ genesisHash?: HexString | {
24
+ toHex: () => HexString;
25
+ };
26
+ genesisHashAdd?: HexString[];
27
+ isDevelopment?: boolean;
28
+ store?: KeyringStore;
29
+ }
30
+ export interface KeyringAddress {
31
+ readonly address: string;
32
+ readonly meta: KeyringJson$Meta;
33
+ readonly publicKey: Uint8Array;
34
+ }
35
+ export type KeyringAddressType = 'address' | 'contract';
36
+ export type KeyringItemType = 'account' | KeyringAddressType;
37
+ export interface CreateResult {
38
+ json: KeyringPair$Json;
39
+ pair: KeyringPair;
40
+ }
41
+ export interface KeyringStruct {
42
+ readonly accounts: AddressSubject;
43
+ readonly addresses: AddressSubject;
44
+ readonly contracts: AddressSubject;
45
+ readonly keyring: BaseKeyringInstance | undefined;
46
+ readonly genesisHash?: string | undefined;
47
+ addExternal: (publicKey: Uint8Array, meta?: KeyringPair$Meta) => CreateResult;
48
+ addPair: (pair: KeyringPair, password: string) => CreateResult;
49
+ addUri: (suri: string, password?: string, meta?: KeyringPair$Meta, type?: KeypairType) => CreateResult;
50
+ backupAccount: (pair: KeyringPair, password: string) => KeyringPair$Json;
51
+ backupAccounts: (addresses: string[], password: string) => Promise<KeyringPairs$Json>;
52
+ createFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
53
+ decodeAddress: (key: string | Uint8Array) => Uint8Array;
54
+ encodeAddress: (key: string | Uint8Array) => string;
55
+ encryptAccount: (pair: KeyringPair, password: string) => void;
56
+ forgetAccount: (address: string) => void;
57
+ forgetAddress: (address: string) => void;
58
+ forgetContract: (address: string) => void;
59
+ getAccount: (address: string | Uint8Array) => KeyringAddress | undefined;
60
+ getAccounts: () => KeyringAddress[];
61
+ getAddress: (address: string | Uint8Array, type: KeyringItemType | null) => KeyringAddress | undefined;
62
+ getAddresses: () => KeyringAddress[];
63
+ getContract: (address: string | Uint8Array) => KeyringAddress | undefined;
64
+ getContracts: (genesisHash?: string) => KeyringAddress[];
65
+ getPair: (address: string | Uint8Array) => KeyringPair;
66
+ getPairs: () => KeyringPair[];
67
+ isAvailable: (address: string | Uint8Array) => boolean;
68
+ isPassValid: (password: string) => boolean;
69
+ loadAll: (options: KeyringOptions) => void;
70
+ restoreAccount: (json: KeyringPair$Json, password: string) => KeyringPair;
71
+ restoreAccounts: (json: EncryptedJson, password: string) => void;
72
+ saveAccount: (pair: KeyringPair, password?: string) => KeyringPair$Json;
73
+ saveAccountMeta: (pair: KeyringPair, meta: KeyringPair$Meta) => void;
74
+ saveAddress: (address: string, meta: KeyringPair$Meta) => KeyringPair$Json;
75
+ saveContract: (address: string, meta: KeyringPair$Meta) => KeyringPair$Json;
76
+ saveRecent: (address: string) => SingleAddress;
77
+ setDevMode: (isDevelopment: boolean) => void;
78
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Base = void 0;
4
+ const keyring_1 = require("@pezkuwi/keyring");
5
+ const util_1 = require("@pezkuwi/util");
6
+ const accounts_js_1 = require("./observable/accounts.js");
7
+ const addresses_js_1 = require("./observable/addresses.js");
8
+ const contracts_js_1 = require("./observable/contracts.js");
9
+ const env_js_1 = require("./observable/env.js");
10
+ const Browser_js_1 = require("./stores/Browser.js"); // direct import (skip index with all)
11
+ class Base {
12
+ #accounts;
13
+ #addresses;
14
+ #contracts;
15
+ #isEthereum;
16
+ #keyring;
17
+ _store;
18
+ _genesisHash;
19
+ _genesisHashAdd = [];
20
+ constructor() {
21
+ this.#accounts = accounts_js_1.accounts;
22
+ this.#addresses = addresses_js_1.addresses;
23
+ this.#contracts = contracts_js_1.contracts;
24
+ this.#isEthereum = false;
25
+ this._store = new Browser_js_1.BrowserStore();
26
+ }
27
+ get accounts() {
28
+ return this.#accounts;
29
+ }
30
+ get addresses() {
31
+ return this.#addresses;
32
+ }
33
+ get contracts() {
34
+ return this.#contracts;
35
+ }
36
+ get isEthereum() {
37
+ return this.#isEthereum;
38
+ }
39
+ get keyring() {
40
+ if (this.#keyring) {
41
+ return this.#keyring;
42
+ }
43
+ throw new Error('Keyring should be initialised via \'loadAll\' before use');
44
+ }
45
+ get genesisHash() {
46
+ return this._genesisHash;
47
+ }
48
+ get genesisHashes() {
49
+ return this._genesisHash
50
+ ? [this._genesisHash, ...this._genesisHashAdd]
51
+ : [...this._genesisHashAdd];
52
+ }
53
+ decodeAddress = (key, ignoreChecksum, ss58Format) => {
54
+ return this.keyring.decodeAddress(key, ignoreChecksum, ss58Format);
55
+ };
56
+ encodeAddress = (key, ss58Format) => {
57
+ return this.keyring.encodeAddress(key, ss58Format);
58
+ };
59
+ getPair(address) {
60
+ return this.keyring.getPair(address);
61
+ }
62
+ getPairs() {
63
+ return this.keyring.getPairs().filter((pair) => env_js_1.env.isDevelopment() || pair.meta.isTesting !== true);
64
+ }
65
+ isAvailable(_address) {
66
+ const accountsValue = this.accounts.subject.getValue();
67
+ const addressesValue = this.addresses.subject.getValue();
68
+ const contractsValue = this.contracts.subject.getValue();
69
+ const address = (0, util_1.isString)(_address)
70
+ ? _address
71
+ : this.encodeAddress(_address);
72
+ return !accountsValue[address] && !addressesValue[address] && !contractsValue[address];
73
+ }
74
+ isPassValid(password) {
75
+ return password.length > 0;
76
+ }
77
+ setSS58Format(ss58Format) {
78
+ if (this.#keyring && (0, util_1.isNumber)(ss58Format)) {
79
+ this.#keyring.setSS58Format(ss58Format);
80
+ }
81
+ }
82
+ setDevMode(isDevelopment) {
83
+ env_js_1.env.set(isDevelopment);
84
+ }
85
+ initKeyring(options) {
86
+ const keyring = (0, keyring_1.createTestKeyring)(options, true);
87
+ if ((0, util_1.isBoolean)(options.isDevelopment)) {
88
+ this.setDevMode(options.isDevelopment);
89
+ }
90
+ // set Ethereum state
91
+ this.#isEthereum = keyring.type === 'ethereum';
92
+ this.#keyring = keyring;
93
+ this._genesisHash = options.genesisHash && ((0, util_1.isString)(options.genesisHash)
94
+ ? options.genesisHash.toString()
95
+ : options.genesisHash.toHex());
96
+ this._genesisHashAdd = options.genesisHashAdd || [];
97
+ this._store = options.store || this._store;
98
+ this.addAccountPairs();
99
+ }
100
+ addAccountPairs() {
101
+ this.keyring
102
+ .getPairs()
103
+ .forEach(({ address, meta }) => {
104
+ this.accounts.add(this._store, address, { address, meta });
105
+ });
106
+ }
107
+ addTimestamp(pair) {
108
+ if (!pair.meta.whenCreated) {
109
+ pair.setMeta({ whenCreated: Date.now() });
110
+ }
111
+ }
112
+ }
113
+ exports.Base = Base;