@pezkuwi/ui-keyring 3.16.6 → 3.16.8

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 (178) hide show
  1. package/package.json +321 -7
  2. package/build/Base.js +0 -109
  3. package/build/Keyring.js +0 -304
  4. package/build/README.md +0 -136
  5. package/build/bundle.js +0 -4
  6. package/build/cjs/Base.d.ts +0 -30
  7. package/build/cjs/Base.js +0 -113
  8. package/build/cjs/Keyring.d.ts +0 -49
  9. package/build/cjs/Keyring.js +0 -308
  10. package/build/cjs/bundle.d.ts +0 -4
  11. package/build/cjs/bundle.js +0 -8
  12. package/build/cjs/defaults.js +0 -28
  13. package/build/cjs/index.js +0 -7
  14. package/build/cjs/observable/accounts.js +0 -6
  15. package/build/cjs/observable/addresses.js +0 -6
  16. package/build/cjs/observable/contracts.js +0 -6
  17. package/build/cjs/observable/env.js +0 -12
  18. package/build/cjs/observable/genericSubject.js +0 -47
  19. package/build/cjs/observable/index.js +0 -16
  20. package/build/cjs/observable/types.js +0 -2
  21. package/build/cjs/options/index.js +0 -116
  22. package/build/cjs/options/item.js +0 -16
  23. package/build/cjs/options/types.js +0 -2
  24. package/build/cjs/packageInfo.js +0 -4
  25. package/build/cjs/stores/Browser.js +0 -24
  26. package/build/cjs/stores/File.js +0 -72
  27. package/build/cjs/stores/index.js +0 -7
  28. package/build/cjs/types.js +0 -2
  29. package/build/defaults.d.ts +0 -6
  30. package/build/defaults.js +0 -22
  31. package/build/index.d.ts +0 -4
  32. package/build/index.js +0 -4
  33. package/build/observable/accounts.d.ts +0 -1
  34. package/build/observable/accounts.js +0 -3
  35. package/build/observable/addresses.d.ts +0 -1
  36. package/build/observable/addresses.js +0 -3
  37. package/build/observable/contracts.d.ts +0 -1
  38. package/build/observable/contracts.js +0 -3
  39. package/build/observable/env.d.ts +0 -6
  40. package/build/observable/env.js +0 -9
  41. package/build/observable/genericSubject.d.ts +0 -2
  42. package/build/observable/genericSubject.js +0 -44
  43. package/build/observable/index.d.ts +0 -8
  44. package/build/observable/index.js +0 -13
  45. package/build/observable/types.d.ts +0 -15
  46. package/build/observable/types.js +0 -1
  47. package/build/options/index.d.ts +0 -15
  48. package/build/options/index.js +0 -112
  49. package/build/options/item.d.ts +0 -2
  50. package/build/options/item.js +0 -13
  51. package/build/options/types.d.ts +0 -15
  52. package/build/options/types.js +0 -1
  53. package/build/package.json +0 -355
  54. package/build/packageDetect.d.ts +0 -1
  55. package/build/packageDetect.js +0 -4
  56. package/build/packageInfo.d.ts +0 -6
  57. package/build/packageInfo.js +0 -1
  58. package/build/stores/Browser.d.ts +0 -7
  59. package/build/stores/Browser.js +0 -19
  60. package/build/stores/File.d.ts +0 -12
  61. package/build/stores/File.js +0 -67
  62. package/build/stores/index.d.ts +0 -2
  63. package/build/stores/index.js +0 -2
  64. package/build/types.d.ts +0 -78
  65. package/build/types.js +0 -1
  66. package/build-tsc-cjs/packageDetect.js +0 -6
  67. package/src/Base.ts +0 -156
  68. package/src/Keyring.ts +0 -420
  69. package/src/bundle.ts +0 -10
  70. package/src/defaults.ts +0 -34
  71. package/src/index.ts +0 -10
  72. package/src/json.d.ts +0 -11
  73. package/src/observable/accounts.ts +0 -7
  74. package/src/observable/addresses.ts +0 -7
  75. package/src/observable/contracts.ts +0 -7
  76. package/src/observable/env.ts +0 -15
  77. package/src/observable/genericSubject.ts +0 -66
  78. package/src/observable/index.ts +0 -28
  79. package/src/observable/types.ts +0 -21
  80. package/src/options/index.ts +0 -150
  81. package/src/options/item.ts +0 -22
  82. package/src/options/types.ts +0 -23
  83. package/src/packageDetect.ts +0 -12
  84. package/src/packageInfo.ts +0 -6
  85. package/src/stores/Browser.ts +0 -28
  86. package/src/stores/File.ts +0 -94
  87. package/src/stores/index.ts +0 -5
  88. package/src/types.ts +0 -91
  89. package/tsconfig.build.json +0 -14
  90. package/tsconfig.build.tsbuildinfo +0 -1
  91. package/tsconfig.spec.json +0 -16
  92. /package/{build-tsc/Base.d.ts → Base.d.ts} +0 -0
  93. /package/{build-tsc-esm/Base.js → Base.js} +0 -0
  94. /package/{build-tsc/Keyring.d.ts → Keyring.d.ts} +0 -0
  95. /package/{build-tsc-esm/Keyring.js → Keyring.js} +0 -0
  96. /package/{build/LICENSE → LICENSE} +0 -0
  97. /package/{build/bundle-pezkuwi-ui-keyring.js → bundle-pezkuwi-ui-keyring.js} +0 -0
  98. /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
  99. /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
  100. /package/{build → cjs}/Base.d.ts +0 -0
  101. /package/{build-tsc-cjs → cjs}/Base.js +0 -0
  102. /package/{build → cjs}/Keyring.d.ts +0 -0
  103. /package/{build-tsc-cjs → cjs}/Keyring.js +0 -0
  104. /package/{build → cjs}/bundle.d.ts +0 -0
  105. /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
  106. /package/{build-tsc → cjs}/defaults.d.ts +0 -0
  107. /package/{build-tsc-cjs → cjs}/defaults.js +0 -0
  108. /package/{build-tsc → cjs}/index.d.ts +0 -0
  109. /package/{build-tsc-cjs → cjs}/index.js +0 -0
  110. /package/{build-tsc → cjs}/observable/accounts.d.ts +0 -0
  111. /package/{build-tsc-cjs → cjs}/observable/accounts.js +0 -0
  112. /package/{build-tsc → cjs}/observable/addresses.d.ts +0 -0
  113. /package/{build-tsc-cjs → cjs}/observable/addresses.js +0 -0
  114. /package/{build-tsc → cjs}/observable/contracts.d.ts +0 -0
  115. /package/{build-tsc-cjs → cjs}/observable/contracts.js +0 -0
  116. /package/{build-tsc → cjs}/observable/env.d.ts +0 -0
  117. /package/{build-tsc-cjs → cjs}/observable/env.js +0 -0
  118. /package/{build-tsc → cjs}/observable/genericSubject.d.ts +0 -0
  119. /package/{build-tsc-cjs → cjs}/observable/genericSubject.js +0 -0
  120. /package/{build-tsc → cjs}/observable/index.d.ts +0 -0
  121. /package/{build-tsc-cjs → cjs}/observable/index.js +0 -0
  122. /package/{build-tsc → cjs}/observable/types.d.ts +0 -0
  123. /package/{build-tsc-cjs → cjs}/observable/types.js +0 -0
  124. /package/{build-tsc → cjs}/options/index.d.ts +0 -0
  125. /package/{build-tsc-cjs → cjs}/options/index.js +0 -0
  126. /package/{build-tsc → cjs}/options/item.d.ts +0 -0
  127. /package/{build-tsc-cjs → cjs}/options/item.js +0 -0
  128. /package/{build-tsc → cjs}/options/types.d.ts +0 -0
  129. /package/{build-tsc-cjs → cjs}/options/types.js +0 -0
  130. /package/{build/cjs → cjs}/package.json +0 -0
  131. /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
  132. /package/{build/cjs → cjs}/packageDetect.js +0 -0
  133. /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
  134. /package/{build-tsc-cjs → cjs}/packageInfo.js +0 -0
  135. /package/{build-tsc → cjs}/stores/Browser.d.ts +0 -0
  136. /package/{build-tsc-cjs → cjs}/stores/Browser.js +0 -0
  137. /package/{build-tsc → cjs}/stores/File.d.ts +0 -0
  138. /package/{build-tsc-cjs → cjs}/stores/File.js +0 -0
  139. /package/{build-tsc → cjs}/stores/index.d.ts +0 -0
  140. /package/{build-tsc-cjs → cjs}/stores/index.js +0 -0
  141. /package/{build-tsc → cjs}/types.d.ts +0 -0
  142. /package/{build-tsc-cjs → cjs}/types.js +0 -0
  143. /package/{build/cjs/defaults.d.ts → defaults.d.ts} +0 -0
  144. /package/{build-tsc-esm/defaults.js → defaults.js} +0 -0
  145. /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
  146. /package/{build-tsc-esm/index.js → index.js} +0 -0
  147. /package/{build/cjs/observable → observable}/accounts.d.ts +0 -0
  148. /package/{build-tsc-esm/observable → observable}/accounts.js +0 -0
  149. /package/{build/cjs/observable → observable}/addresses.d.ts +0 -0
  150. /package/{build-tsc-esm/observable → observable}/addresses.js +0 -0
  151. /package/{build/cjs/observable → observable}/contracts.d.ts +0 -0
  152. /package/{build-tsc-esm/observable → observable}/contracts.js +0 -0
  153. /package/{build/cjs/observable → observable}/env.d.ts +0 -0
  154. /package/{build-tsc-esm/observable → observable}/env.js +0 -0
  155. /package/{build/cjs/observable → observable}/genericSubject.d.ts +0 -0
  156. /package/{build-tsc-esm/observable → observable}/genericSubject.js +0 -0
  157. /package/{build/cjs/observable → observable}/index.d.ts +0 -0
  158. /package/{build-tsc-esm/observable → observable}/index.js +0 -0
  159. /package/{build/cjs/observable → observable}/types.d.ts +0 -0
  160. /package/{build-tsc-esm/observable → observable}/types.js +0 -0
  161. /package/{build/cjs/options → options}/index.d.ts +0 -0
  162. /package/{build-tsc-esm/options → options}/index.js +0 -0
  163. /package/{build/cjs/options → options}/item.d.ts +0 -0
  164. /package/{build-tsc-esm/options → options}/item.js +0 -0
  165. /package/{build/cjs/options → options}/types.d.ts +0 -0
  166. /package/{build-tsc-esm/options → options}/types.js +0 -0
  167. /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
  168. /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
  169. /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
  170. /package/{build-tsc-esm/packageInfo.js → packageInfo.js} +0 -0
  171. /package/{build/cjs/stores → stores}/Browser.d.ts +0 -0
  172. /package/{build-tsc-esm/stores → stores}/Browser.js +0 -0
  173. /package/{build/cjs/stores → stores}/File.d.ts +0 -0
  174. /package/{build-tsc-esm/stores → stores}/File.js +0 -0
  175. /package/{build/cjs/stores → stores}/index.d.ts +0 -0
  176. /package/{build-tsc-esm/stores → stores}/index.js +0 -0
  177. /package/{build/cjs/types.d.ts → types.d.ts} +0 -0
  178. /package/{build-tsc-esm/types.js → types.js} +0 -0
@@ -1,66 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeypairType } from '@pezkuwi/util-crypto/types';
5
- import type { KeyringJson, KeyringStore } from '../types.js';
6
- import type { AddressSubject, SingleAddress, SubjectInfo } from './types.js';
7
-
8
- import { BehaviorSubject } from 'rxjs';
9
-
10
- import { objectCopy, objectSpread } from '@pezkuwi/util';
11
-
12
- import { createOptionItem } from '../options/item.js';
13
- import { env } from './env.js';
14
-
15
- function callNext (current: SubjectInfo, subject: BehaviorSubject<SubjectInfo>, withTest: boolean): void {
16
- const isDevMode = env.isDevelopment();
17
- const filtered: SubjectInfo = {};
18
-
19
- Object.keys(current).forEach((key): void => {
20
- const { json: { meta: { isTesting = false } = {} } = {} } = current[key];
21
-
22
- if (!withTest || isDevMode || isTesting !== true) {
23
- filtered[key] = current[key];
24
- }
25
- });
26
-
27
- subject.next(filtered);
28
- }
29
-
30
- export function genericSubject (keyCreator: (address: string) => string, withTest = false): AddressSubject {
31
- let current: SubjectInfo = {};
32
- const subject = new BehaviorSubject({});
33
- const next = (): void => callNext(current, subject, withTest);
34
-
35
- env.subject.subscribe(next);
36
-
37
- return {
38
- add: (store: KeyringStore, address: string, json: KeyringJson, type?: KeypairType): SingleAddress => {
39
- current = objectCopy(current);
40
-
41
- current[address] = {
42
- json: objectSpread({}, json, { address }),
43
- option: createOptionItem(address, json.meta.name),
44
- type
45
- };
46
-
47
- // we do not store dev or injected accounts (external/transient)
48
- if (!json.meta.isInjected && (!json.meta.isTesting || env.isDevelopment())) {
49
- store.set(keyCreator(address), json);
50
- }
51
-
52
- next();
53
-
54
- return current[address];
55
- },
56
- remove: (store: KeyringStore, address: string): void => {
57
- current = objectCopy(current);
58
-
59
- delete current[address];
60
-
61
- store.remove(keyCreator(address));
62
- next();
63
- },
64
- subject
65
- };
66
- }
@@ -1,28 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { SubjectInfo } from './types.js';
5
-
6
- import { combineLatest, map } from 'rxjs';
7
-
8
- import { accounts } from './accounts.js';
9
- import { addresses } from './addresses.js';
10
- import { contracts } from './contracts.js';
11
-
12
- interface Result {
13
- accounts: SubjectInfo;
14
- addresses: SubjectInfo;
15
- contracts: SubjectInfo;
16
- }
17
-
18
- export const obervableAll = /*#__PURE__*/ combineLatest([
19
- accounts.subject,
20
- addresses.subject,
21
- contracts.subject
22
- ]).pipe(
23
- map(([accounts, addresses, contracts]): Result => ({
24
- accounts,
25
- addresses,
26
- contracts
27
- }))
28
- );
@@ -1,21 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { BehaviorSubject } from 'rxjs';
5
- import type { KeypairType } from '@pezkuwi/util-crypto/types';
6
- import type { KeyringSectionOption } from '../options/types.js';
7
- import type { KeyringJson, KeyringStore } from '../types.js';
8
-
9
- export interface SingleAddress {
10
- json: KeyringJson;
11
- option: KeyringSectionOption;
12
- type?: KeypairType | undefined;
13
- }
14
-
15
- export type SubjectInfo = Record<string, SingleAddress>;
16
-
17
- export interface AddressSubject {
18
- add: (store: KeyringStore, address: string, json: KeyringJson, type?: KeypairType) => SingleAddress;
19
- remove: (store: KeyringStore, address: string) => void;
20
- subject: BehaviorSubject<SubjectInfo>;
21
- }
@@ -1,150 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Subscription } from 'rxjs';
5
- import type { SingleAddress } from '../observable/types.js';
6
- import type { KeyringStruct } from '../types.js';
7
- import type { KeyringOptionInstance, KeyringOptions, KeyringSectionOption, KeyringSectionOptions } from './types.js';
8
-
9
- import { BehaviorSubject } from 'rxjs';
10
-
11
- import { obervableAll } from '../observable/index.js';
12
-
13
- let hasCalledInitOptions = false;
14
-
15
- const sortByName = (a: SingleAddress, b: SingleAddress): number => {
16
- const valueA = a.option.name;
17
- const valueB = b.option.name;
18
-
19
- return valueA.localeCompare(valueB);
20
- };
21
-
22
- const sortByCreated = (a: SingleAddress, b: SingleAddress): number => {
23
- const valueA = a.json.meta.whenCreated || 0;
24
- const valueB = b.json.meta.whenCreated || 0;
25
-
26
- if (valueA < valueB) {
27
- return 1;
28
- }
29
-
30
- if (valueA > valueB) {
31
- return -1;
32
- }
33
-
34
- return 0;
35
- };
36
-
37
- export class KeyringOption implements KeyringOptionInstance {
38
- #allSub: Subscription | null = null;
39
-
40
- public readonly optionsSubject = new BehaviorSubject<KeyringOptions>(this.emptyOptions());
41
-
42
- public createOptionHeader (name: string): KeyringSectionOption {
43
- return {
44
- key: `header-${name.toLowerCase()}`,
45
- name,
46
- value: null
47
- };
48
- }
49
-
50
- public init (keyring: KeyringStruct): void {
51
- if (hasCalledInitOptions) {
52
- throw new Error('Unable to initialise options more than once');
53
- }
54
-
55
- this.#allSub = obervableAll.subscribe((): void => {
56
- const opts = this.emptyOptions();
57
-
58
- this.addAccounts(keyring, opts);
59
- this.addAddresses(keyring, opts);
60
- this.addContracts(keyring, opts);
61
-
62
- opts.address = this.linkItems({ Addresses: opts.address, Recent: opts.recent });
63
- opts.account = this.linkItems({ Accounts: opts.account, Development: opts.testing });
64
- opts.contract = this.linkItems({ Contracts: opts.contract });
65
- opts.all = ([] as KeyringSectionOptions).concat(opts.account, opts.address);
66
- opts.allPlus = ([] as KeyringSectionOptions).concat(opts.account, opts.address, opts.contract);
67
-
68
- this.optionsSubject.next(opts);
69
- });
70
-
71
- hasCalledInitOptions = true;
72
- }
73
-
74
- public clear (): void {
75
- if (this.#allSub) {
76
- this.#allSub.unsubscribe();
77
- }
78
- }
79
-
80
- private linkItems (items: Record<string, KeyringSectionOptions>): KeyringSectionOptions {
81
- return Object.keys(items).reduce((result, header): KeyringSectionOptions => {
82
- const options = items[header];
83
-
84
- return result.concat(
85
- options.length
86
- ? [this.createOptionHeader(header)]
87
- : [],
88
- options
89
- );
90
- }, [] as KeyringSectionOptions);
91
- }
92
-
93
- private addAccounts (keyring: KeyringStruct, options: KeyringOptions): void {
94
- const available = keyring.accounts.subject.getValue();
95
-
96
- Object
97
- .values(available)
98
- .sort(sortByName)
99
- .forEach(({ json: { meta: { isTesting = false } }, option }: SingleAddress): void => {
100
- if (!isTesting) {
101
- options.account.push(option);
102
- } else {
103
- options.testing.push(option);
104
- }
105
- });
106
- }
107
-
108
- private addAddresses (keyring: KeyringStruct, options: KeyringOptions): void {
109
- const available = keyring.addresses.subject.getValue();
110
-
111
- Object
112
- .values(available)
113
- .filter(({ json }: SingleAddress): boolean => !!json.meta.isRecent)
114
- .sort(sortByCreated)
115
- .forEach(({ option }: SingleAddress): void => {
116
- options.recent.push(option);
117
- });
118
-
119
- Object
120
- .values(available)
121
- .filter(({ json }: SingleAddress): boolean => !json.meta.isRecent)
122
- .sort(sortByName)
123
- .forEach(({ option }: SingleAddress): void => {
124
- options.address.push(option);
125
- });
126
- }
127
-
128
- private addContracts (keyring: KeyringStruct, options: KeyringOptions): void {
129
- const available = keyring.contracts.subject.getValue();
130
-
131
- Object
132
- .values(available)
133
- .sort(sortByName)
134
- .forEach(({ option }: SingleAddress): void => {
135
- options.contract.push(option);
136
- });
137
- }
138
-
139
- private emptyOptions (): KeyringOptions {
140
- return {
141
- account: [],
142
- address: [],
143
- all: [],
144
- allPlus: [],
145
- contract: [],
146
- recent: [],
147
- testing: []
148
- };
149
- }
150
- }
@@ -1,22 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeyringSectionOption } from './types.js';
5
-
6
- import { isUndefined } from '@pezkuwi/util';
7
-
8
- export function createOptionItem (address: string, _name?: string): KeyringSectionOption {
9
- const name = isUndefined(_name)
10
- ? (
11
- (address.length > 15)
12
- ? `${address.slice(0, 6)}…${address.slice(-6)}`
13
- : address
14
- )
15
- : _name;
16
-
17
- return {
18
- key: address,
19
- name,
20
- value: address
21
- };
22
- }
@@ -1,23 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeyringItemType, KeyringStruct } from '../types.js';
5
-
6
- export interface KeyringSectionOption {
7
- key: string | null;
8
- name: string;
9
- value: string | null;
10
- }
11
-
12
- export type KeyringSectionOptions = KeyringSectionOption[];
13
-
14
- export type KeyringOptions = {
15
- [type in KeyringItemType | 'all' | 'allPlus' | 'recent' | 'testing']: KeyringSectionOptions
16
- };
17
-
18
- export type KeyringOption$Type = keyof KeyringOptions;
19
-
20
- export interface KeyringOptionInstance {
21
- createOptionHeader: (name: string) => KeyringSectionOption;
22
- init: (keyring: KeyringStruct) => void;
23
- }
@@ -1,12 +0,0 @@
1
- // Copyright 2017-2026 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Do not edit, auto-generated by @pezkuwi/dev
5
- // (packageInfo imports will be kept as-is, user-editable)
6
-
7
- import { packageInfo as settingsInfo } from '@pezkuwi/ui-settings/packageInfo';
8
- import { detectPackage } from '@pezkuwi/util';
9
-
10
- import { packageInfo } from './packageInfo.js';
11
-
12
- detectPackage(packageInfo, null, [settingsInfo]);
@@ -1,6 +0,0 @@
1
- // Copyright 2017-2026 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Do not edit, auto-generated by @pezkuwi/dev
5
-
6
- export const packageInfo = { name: '@pezkuwi/ui-keyring', path: 'auto', type: 'auto', version: '3.16.6' };
@@ -1,28 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeyringJson, KeyringStore } from '../types.js';
5
-
6
- import store from 'store';
7
-
8
- export class BrowserStore implements KeyringStore {
9
- public all (fn: (key: string, value: KeyringJson) => void): void {
10
- store.each((value: KeyringJson, key: string): void => {
11
- fn(key, value);
12
- });
13
- }
14
-
15
- public get (key: string, fn: (value: KeyringJson) => void): void {
16
- fn(store.get(key) as KeyringJson);
17
- }
18
-
19
- public remove (key: string, fn?: () => void): void {
20
- store.remove(key);
21
- fn && fn();
22
- }
23
-
24
- public set (key: string, value: KeyringJson, fn?: () => void): void {
25
- store.set(key, value);
26
- fn && fn();
27
- }
28
- }
@@ -1,94 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeyringJson, KeyringStore } from '../types.js';
5
-
6
- import { mkdirpSync } from 'mkdirp';
7
- import fs from 'node:fs';
8
- import path from 'node:path';
9
-
10
- // NOTE untested and unused by any known apps, probably broken in various mysterious ways
11
- export class FileStore implements KeyringStore {
12
- #path: string;
13
-
14
- constructor (path: string) {
15
- if (!fs.existsSync(path)) {
16
- mkdirpSync(path);
17
- }
18
-
19
- this.#path = path;
20
- }
21
-
22
- private validateKey (key: string): boolean {
23
- // Make sure the key has a .json extension
24
- if (!key.endsWith('.json')) {
25
- console.error('Non-JSON file requested: ', key);
26
-
27
- return false;
28
- }
29
-
30
- // Remove '.json'
31
- const keyWithoutExtension = key.slice(0, -5);
32
- // Only allow alphanumeric characters, hyphens, and underscores in the base filename
33
- const safeKeyRegex = /^[a-zA-Z0-9_-]+$/;
34
-
35
- if (!safeKeyRegex.test(keyWithoutExtension)) {
36
- console.error('Invalid key format detected: ', key);
37
-
38
- return false;
39
- }
40
-
41
- return true;
42
- }
43
-
44
- public all (fn: (key: string, value: KeyringJson) => void): void {
45
- fs
46
- .readdirSync(this.#path)
47
- .filter((key): boolean => !['.', '..', '.DS_Store'].includes(key))
48
- .forEach((key): void => {
49
- const value = this._readKey(key);
50
-
51
- value?.address && fn(key, value);
52
- });
53
- }
54
-
55
- public get (key: string, fn: (value: KeyringJson) => void): void {
56
- const value = this._readKey(key);
57
-
58
- if (!value?.address) {
59
- throw new Error(`Invalid JSON found for ${key}`);
60
- }
61
-
62
- fn(value);
63
- }
64
-
65
- public remove (key: string, fn?: () => void): void {
66
- fs.unlinkSync(this._getPath(key));
67
- fn && fn();
68
- }
69
-
70
- public set (key: string, value: KeyringJson, fn?: () => void): void {
71
- fs.writeFileSync(this._getPath(key), Buffer.from(JSON.stringify(value), 'utf-8'));
72
- fn && fn();
73
- }
74
-
75
- private _getPath (key: string): string {
76
- if (!this.validateKey(key)) {
77
- throw new Error('Invalid key format');
78
- }
79
-
80
- return path.join(this.#path, key);
81
- }
82
-
83
- private _readKey (key: string): KeyringJson | undefined {
84
- try {
85
- return JSON.parse(
86
- fs.readFileSync(this._getPath(key)).toString('utf-8')
87
- ) as KeyringJson;
88
- } catch (error) {
89
- console.error(error);
90
- }
91
-
92
- return undefined;
93
- }
94
- }
@@ -1,5 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export { BrowserStore } from './Browser.js';
5
- export { FileStore } from './File.js';
package/src/types.ts DELETED
@@ -1,91 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/ui-keyring authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeyringInstance as BaseKeyringInstance, KeyringOptions as KeyringOptionsBase, KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '@pezkuwi/keyring/types';
5
- import type { HexString } from '@pezkuwi/util/types';
6
- import type { EncryptedJson } from '@pezkuwi/util-crypto/json/types';
7
- import type { KeypairType } from '@pezkuwi/util-crypto/types';
8
- import type { AddressSubject, SingleAddress } from './observable/types.js';
9
-
10
- export type ContractMeta = NonNullable<KeyringPair$Meta['contract']>;
11
-
12
- export type KeyringJson$Meta = KeyringPair$Meta;
13
-
14
- export interface KeyringJson {
15
- address: string;
16
- meta: KeyringJson$Meta;
17
- }
18
-
19
- export interface KeyringPairs$Json extends EncryptedJson {
20
- accounts: KeyringJson[];
21
- }
22
-
23
- export interface KeyringStore {
24
- all: (cb: (key: string, value: KeyringJson) => void) => void;
25
- get: (key: string, cb: (value: KeyringJson) => void) => void;
26
- remove: (key: string, cb?: () => void) => void;
27
- set: (key: string, value: KeyringJson, cb?: () => void) => void;
28
- }
29
-
30
- export interface KeyringOptions extends KeyringOptionsBase {
31
- filter?: (json: KeyringJson) => boolean;
32
- genesisHash?: HexString | { toHex: () => HexString };
33
- genesisHashAdd?: HexString[];
34
- isDevelopment?: boolean;
35
- store?: KeyringStore;
36
- }
37
-
38
- export interface KeyringAddress {
39
- readonly address: string;
40
- readonly meta: KeyringJson$Meta;
41
- readonly publicKey: Uint8Array;
42
- }
43
-
44
- export type KeyringAddressType = 'address' | 'contract';
45
-
46
- export type KeyringItemType = 'account' | KeyringAddressType;
47
-
48
- export interface CreateResult {
49
- json: KeyringPair$Json;
50
- pair: KeyringPair;
51
- }
52
-
53
- export interface KeyringStruct {
54
- readonly accounts: AddressSubject;
55
- readonly addresses: AddressSubject;
56
- readonly contracts: AddressSubject;
57
- readonly keyring: BaseKeyringInstance | undefined;
58
- readonly genesisHash?: string | undefined;
59
-
60
- addExternal: (publicKey: Uint8Array, meta?: KeyringPair$Meta) => CreateResult;
61
- addPair: (pair: KeyringPair, password: string) => CreateResult;
62
- addUri: (suri: string, password?: string, meta?: KeyringPair$Meta, type?: KeypairType) => CreateResult;
63
- backupAccount: (pair: KeyringPair, password: string) => KeyringPair$Json;
64
- backupAccounts: (addresses: string[], password: string) => Promise<KeyringPairs$Json>
65
- createFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
66
- decodeAddress: (key: string | Uint8Array) => Uint8Array;
67
- encodeAddress: (key: string | Uint8Array) => string;
68
- encryptAccount: (pair: KeyringPair, password: string) => void;
69
- forgetAccount: (address: string) => void;
70
- forgetAddress: (address: string) => void;
71
- forgetContract: (address: string) => void;
72
- getAccount: (address: string | Uint8Array) => KeyringAddress | undefined;
73
- getAccounts: () => KeyringAddress[];
74
- getAddress: (address: string | Uint8Array, type: KeyringItemType | null) => KeyringAddress | undefined;
75
- getAddresses: () => KeyringAddress[];
76
- getContract: (address: string | Uint8Array) => KeyringAddress | undefined;
77
- getContracts: (genesisHash?: string) => KeyringAddress[];
78
- getPair: (address: string | Uint8Array) => KeyringPair;
79
- getPairs: () => KeyringPair[];
80
- isAvailable: (address: string | Uint8Array) => boolean;
81
- isPassValid: (password: string) => boolean;
82
- loadAll: (options: KeyringOptions) => void;
83
- restoreAccount: (json: KeyringPair$Json, password: string) => KeyringPair;
84
- restoreAccounts: (json: EncryptedJson, password: string) => void;
85
- saveAccount: (pair: KeyringPair, password?: string) => KeyringPair$Json;
86
- saveAccountMeta: (pair: KeyringPair, meta: KeyringPair$Meta) => void;
87
- saveAddress: (address: string, meta: KeyringPair$Meta) => KeyringPair$Json;
88
- saveContract: (address: string, meta: KeyringPair$Meta) => KeyringPair$Json;
89
- saveRecent: (address: string) => SingleAddress;
90
- setDevMode: (isDevelopment: boolean) => void;
91
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "baseUrl": "..",
5
- "outDir": "./build",
6
- "rootDir": "./src"
7
- },
8
- "exclude": [
9
- "**/*.spec.ts"
10
- ],
11
- "references": [
12
- { "path": "../ui-settings/tsconfig.build.json" }
13
- ]
14
- }