@pezkuwi/keyring 14.0.13 → 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,294 +0,0 @@
1
- {
2
- "author": "Dijital Kurdistan Tech Institute <dev@pezkuwichain.io>",
3
- "bugs": "https://github.com/pezkuwichain/pezkuwi-common/issues",
4
- "description": "Keyring management",
5
- "engines": {
6
- "node": ">=18"
7
- },
8
- "homepage": "https://github.com/pezkuwichain/pezkuwi-common/tree/master/packages/keyring#readme",
9
- "license": "Apache-2.0",
10
- "name": "@pezkuwi/keyring",
11
- "repository": {
12
- "directory": "packages/keyring",
13
- "type": "git",
14
- "url": "https://github.com/pezkuwichain/pezkuwi-common.git"
15
- },
16
- "sideEffects": [
17
- "./packageDetect.js",
18
- "./cjs/packageDetect.js"
19
- ],
20
- "type": "module",
21
- "version": "14.0.13",
22
- "main": "./cjs/index.js",
23
- "module": "./cjs/index.js",
24
- "types": "./cjs/index.d.ts",
25
- "exports": {
26
- "./cjs/package.json": "./cjs/package.json",
27
- "./cjs/*": "./cjs/*.js",
28
- ".": {
29
- "module": {
30
- "types": "./index.d.ts",
31
- "default": "./index.js"
32
- },
33
- "require": {
34
- "types": "./cjs/index.d.ts",
35
- "default": "./cjs/index.js"
36
- },
37
- "default": {
38
- "types": "./index.d.ts",
39
- "default": "./index.js"
40
- }
41
- },
42
- "./bundle": {
43
- "module": {
44
- "types": "./bundle.d.ts",
45
- "default": "./bundle.js"
46
- },
47
- "require": {
48
- "types": "./cjs/bundle.d.ts",
49
- "default": "./cjs/bundle.js"
50
- },
51
- "default": {
52
- "types": "./bundle.d.ts",
53
- "default": "./bundle.js"
54
- }
55
- },
56
- "./defaults": {
57
- "module": {
58
- "types": "./defaults.d.ts",
59
- "default": "./defaults.js"
60
- },
61
- "require": {
62
- "types": "./cjs/defaults.d.ts",
63
- "default": "./cjs/defaults.js"
64
- },
65
- "default": {
66
- "types": "./defaults.d.ts",
67
- "default": "./defaults.js"
68
- }
69
- },
70
- "./keyring": {
71
- "module": {
72
- "types": "./keyring.d.ts",
73
- "default": "./keyring.js"
74
- },
75
- "require": {
76
- "types": "./cjs/keyring.d.ts",
77
- "default": "./cjs/keyring.js"
78
- },
79
- "default": {
80
- "types": "./keyring.d.ts",
81
- "default": "./keyring.js"
82
- }
83
- },
84
- "./package.json": {
85
- "require": "./cjs/package.json",
86
- "default": "./package.json"
87
- },
88
- "./packageDetect": {
89
- "module": {
90
- "types": "./packageDetect.d.ts",
91
- "default": "./packageDetect.js"
92
- },
93
- "require": {
94
- "types": "./cjs/packageDetect.d.ts",
95
- "default": "./cjs/packageDetect.js"
96
- },
97
- "default": {
98
- "types": "./packageDetect.d.ts",
99
- "default": "./packageDetect.js"
100
- }
101
- },
102
- "./packageInfo.js": {
103
- "module": {
104
- "types": "./packageInfo.d.ts",
105
- "default": "./packageInfo.js"
106
- },
107
- "require": {
108
- "types": "./cjs/packageInfo.d.ts",
109
- "default": "./cjs/packageInfo.js"
110
- },
111
- "default": {
112
- "types": "./packageInfo.d.ts",
113
- "default": "./packageInfo.js"
114
- }
115
- },
116
- "./packageInfo": {
117
- "module": {
118
- "types": "./packageInfo.d.ts",
119
- "default": "./packageInfo.js"
120
- },
121
- "require": {
122
- "types": "./cjs/packageInfo.d.ts",
123
- "default": "./cjs/packageInfo.js"
124
- },
125
- "default": {
126
- "types": "./packageInfo.d.ts",
127
- "default": "./packageInfo.js"
128
- }
129
- },
130
- "./pair": {
131
- "module": {
132
- "types": "./pair/index.d.ts",
133
- "default": "./pair/index.js"
134
- },
135
- "require": {
136
- "types": "./cjs/pair/index.d.ts",
137
- "default": "./cjs/pair/index.js"
138
- },
139
- "default": {
140
- "types": "./pair/index.d.ts",
141
- "default": "./pair/index.js"
142
- }
143
- },
144
- "./pair/decode": {
145
- "module": {
146
- "types": "./pair/decode.d.ts",
147
- "default": "./pair/decode.js"
148
- },
149
- "require": {
150
- "types": "./cjs/pair/decode.d.ts",
151
- "default": "./cjs/pair/decode.js"
152
- },
153
- "default": {
154
- "types": "./pair/decode.d.ts",
155
- "default": "./pair/decode.js"
156
- }
157
- },
158
- "./pair/defaults": {
159
- "module": {
160
- "types": "./pair/defaults.d.ts",
161
- "default": "./pair/defaults.js"
162
- },
163
- "require": {
164
- "types": "./cjs/pair/defaults.d.ts",
165
- "default": "./cjs/pair/defaults.js"
166
- },
167
- "default": {
168
- "types": "./pair/defaults.d.ts",
169
- "default": "./pair/defaults.js"
170
- }
171
- },
172
- "./pair/encode": {
173
- "module": {
174
- "types": "./pair/encode.d.ts",
175
- "default": "./pair/encode.js"
176
- },
177
- "require": {
178
- "types": "./cjs/pair/encode.d.ts",
179
- "default": "./cjs/pair/encode.js"
180
- },
181
- "default": {
182
- "types": "./pair/encode.d.ts",
183
- "default": "./pair/encode.js"
184
- }
185
- },
186
- "./pair/nobody": {
187
- "module": {
188
- "types": "./pair/nobody.d.ts",
189
- "default": "./pair/nobody.js"
190
- },
191
- "require": {
192
- "types": "./cjs/pair/nobody.d.ts",
193
- "default": "./cjs/pair/nobody.js"
194
- },
195
- "default": {
196
- "types": "./pair/nobody.d.ts",
197
- "default": "./pair/nobody.js"
198
- }
199
- },
200
- "./pair/toJson": {
201
- "module": {
202
- "types": "./pair/toJson.d.ts",
203
- "default": "./pair/toJson.js"
204
- },
205
- "require": {
206
- "types": "./cjs/pair/toJson.d.ts",
207
- "default": "./cjs/pair/toJson.js"
208
- },
209
- "default": {
210
- "types": "./pair/toJson.d.ts",
211
- "default": "./pair/toJson.js"
212
- }
213
- },
214
- "./pair/types": {
215
- "module": {
216
- "types": "./pair/types.d.ts",
217
- "default": "./pair/types.js"
218
- },
219
- "require": {
220
- "types": "./cjs/pair/types.d.ts",
221
- "default": "./cjs/pair/types.js"
222
- },
223
- "default": {
224
- "types": "./pair/types.d.ts",
225
- "default": "./pair/types.js"
226
- }
227
- },
228
- "./pairs": {
229
- "module": {
230
- "types": "./pairs.d.ts",
231
- "default": "./pairs.js"
232
- },
233
- "require": {
234
- "types": "./cjs/pairs.d.ts",
235
- "default": "./cjs/pairs.js"
236
- },
237
- "default": {
238
- "types": "./pairs.d.ts",
239
- "default": "./pairs.js"
240
- }
241
- },
242
- "./testing": {
243
- "module": {
244
- "types": "./testing.d.ts",
245
- "default": "./testing.js"
246
- },
247
- "require": {
248
- "types": "./cjs/testing.d.ts",
249
- "default": "./cjs/testing.js"
250
- },
251
- "default": {
252
- "types": "./testing.d.ts",
253
- "default": "./testing.js"
254
- }
255
- },
256
- "./testingPairs": {
257
- "module": {
258
- "types": "./testingPairs.d.ts",
259
- "default": "./testingPairs.js"
260
- },
261
- "require": {
262
- "types": "./cjs/testingPairs.d.ts",
263
- "default": "./cjs/testingPairs.js"
264
- },
265
- "default": {
266
- "types": "./testingPairs.d.ts",
267
- "default": "./testingPairs.js"
268
- }
269
- },
270
- "./types": {
271
- "module": {
272
- "types": "./types.d.ts",
273
- "default": "./types.js"
274
- },
275
- "require": {
276
- "types": "./cjs/types.d.ts",
277
- "default": "./cjs/types.js"
278
- },
279
- "default": {
280
- "types": "./types.d.ts",
281
- "default": "./types.js"
282
- }
283
- }
284
- },
285
- "dependencies": {
286
- "@pezkuwi/util": "14.0.12",
287
- "@pezkuwi/util-crypto": "14.0.12",
288
- "tslib": "^2.8.0"
289
- },
290
- "peerDependencies": {
291
- "@pezkuwi/util": "14.0.12",
292
- "@pezkuwi/util-crypto": "14.0.12"
293
- }
294
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import { detectPackage } from '@pezkuwi/util';
2
- import { packageInfo as utilInfo } from '@pezkuwi/util/packageInfo';
3
- import { packageInfo as cryptoInfo } from '@pezkuwi/util-crypto/packageInfo';
4
- import { packageInfo } from './packageInfo.js';
5
- detectPackage(packageInfo, null, [cryptoInfo, utilInfo]);
@@ -1,6 +0,0 @@
1
- export declare const packageInfo: {
2
- name: string;
3
- path: string;
4
- type: string;
5
- version: string;
6
- };
@@ -1 +0,0 @@
1
- export const packageInfo = { name: '@pezkuwi/keyring', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.13' };
@@ -1,12 +0,0 @@
1
- import type { EncryptedJsonEncoding } from '@pezkuwi/util-crypto/types';
2
- /**
3
- * Decode a pair, taking into account the generation-specific formats and headers
4
- *
5
- * For divisor/headers, don't rely on the magic being static. These will
6
- * change between generations, aka with the long-awaited 4th generation
7
- * of the format. The external decode interface is the only way to use and decode these.
8
- **/
9
- export declare function decodePair(passphrase?: string, encrypted?: Uint8Array | null, _encType?: EncryptedJsonEncoding | EncryptedJsonEncoding[]): {
10
- publicKey: Uint8Array;
11
- secretKey: Uint8Array;
12
- };
@@ -1,42 +0,0 @@
1
- import { u8aEq } from '@pezkuwi/util';
2
- import { jsonDecryptData } from '@pezkuwi/util-crypto';
3
- import { PAIR_DIV, PAIR_HDR, PUB_LENGTH, SEC_LENGTH, SEED_LENGTH } from './defaults.js';
4
- const SEED_OFFSET = PAIR_HDR.length;
5
- /**
6
- * Decode a pair, taking into account the generation-specific formats and headers
7
- *
8
- * For divisor/headers, don't rely on the magic being static. These will
9
- * change between generations, aka with the long-awaited 4th generation
10
- * of the format. The external decode interface is the only way to use and decode these.
11
- **/
12
- export function decodePair(passphrase, encrypted, _encType) {
13
- const encType = Array.isArray(_encType) || _encType === undefined
14
- ? _encType
15
- : [_encType];
16
- const decrypted = jsonDecryptData(encrypted, passphrase, encType);
17
- const header = decrypted.subarray(0, PAIR_HDR.length);
18
- // check the start header (generations 1-3)
19
- if (!u8aEq(header, PAIR_HDR)) {
20
- throw new Error('Invalid encoding header found in body');
21
- }
22
- // setup for generation 3 format
23
- let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
24
- let divOffset = SEED_OFFSET + SEC_LENGTH;
25
- let divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
26
- // old-style (generation 1 & 2), we have the seed here
27
- if (!u8aEq(divider, PAIR_DIV)) {
28
- divOffset = SEED_OFFSET + SEED_LENGTH;
29
- secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
30
- divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
31
- // check the divisior at this point (already checked for generation 3)
32
- if (!u8aEq(divider, PAIR_DIV)) {
33
- throw new Error('Invalid encoding divider found in body');
34
- }
35
- }
36
- const pubOffset = divOffset + PAIR_DIV.length;
37
- const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
38
- return {
39
- publicKey,
40
- secretKey
41
- };
42
- }
@@ -1,12 +0,0 @@
1
- /** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
2
- export declare const PAIR_DIV: Uint8Array<ArrayBuffer>;
3
- /** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
4
- export declare const PAIR_HDR: Uint8Array<ArrayBuffer>;
5
- /** length of a public key */
6
- export declare const PUB_LENGTH = 32;
7
- /** length of a salt */
8
- export declare const SALT_LENGTH = 32;
9
- /** length of a secret key */
10
- export declare const SEC_LENGTH = 64;
11
- /** length of a user-input seed */
12
- export declare const SEED_LENGTH = 32;
@@ -1,12 +0,0 @@
1
- /** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
2
- export const PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
3
- /** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
4
- export const PAIR_HDR = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
5
- /** length of a public key */
6
- export const PUB_LENGTH = 32;
7
- /** length of a salt */
8
- export const SALT_LENGTH = 32;
9
- /** length of a secret key */
10
- export const SEC_LENGTH = 64;
11
- /** length of a user-input seed */
12
- export const SEED_LENGTH = 32;
@@ -1,5 +0,0 @@
1
- import type { PairInfo } from './types.js';
2
- /**
3
- * Encode a pair with the latest generation format (generation 3)
4
- **/
5
- export declare function encodePair({ publicKey, secretKey }: PairInfo, passphrase?: string): Uint8Array;
@@ -1,19 +0,0 @@
1
- import { u8aConcat } from '@pezkuwi/util';
2
- import { naclEncrypt, scryptEncode, scryptToU8a } from '@pezkuwi/util-crypto';
3
- import { PAIR_DIV, PAIR_HDR } from './defaults.js';
4
- /**
5
- * Encode a pair with the latest generation format (generation 3)
6
- **/
7
- export function encodePair({ publicKey, secretKey }, passphrase) {
8
- if (!secretKey) {
9
- throw new Error('Expected a valid secretKey to be passed to encode');
10
- }
11
- const encoded = u8aConcat(PAIR_HDR, secretKey, PAIR_DIV, publicKey);
12
- if (!passphrase) {
13
- return encoded;
14
- }
15
- // this is only for generation 3 (previous generations are only handled in decoding)
16
- const { params, password, salt } = scryptEncode(passphrase);
17
- const { encrypted, nonce } = naclEncrypt(encoded, password.subarray(0, 32));
18
- return u8aConcat(scryptToU8a(salt, params), nonce, encrypted);
19
- }
@@ -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,180 +0,0 @@
1
- import { objectSpread, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@pezkuwi/util';
2
- import { blake2AsU8a, ed25519PairFromSeed as ed25519FromSeed, ed25519Sign, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, secp256k1Compress, secp256k1Expand, secp256k1PairFromSeed as secp256k1FromSeed, secp256k1Sign, signatureVerify, sr25519PairFromSeed as sr25519FromSeed, sr25519Sign, sr25519VrfSign, sr25519VrfVerify } from '@pezkuwi/util-crypto';
3
- import { decodePair } from './decode.js';
4
- import { encodePair } from './encode.js';
5
- import { pairToJson } from './toJson.js';
6
- const SIG_TYPE_NONE = new Uint8Array();
7
- const TYPE_FROM_SEED = {
8
- ecdsa: secp256k1FromSeed,
9
- ed25519: ed25519FromSeed,
10
- ethereum: secp256k1FromSeed,
11
- sr25519: sr25519FromSeed
12
- };
13
- const TYPE_PREFIX = {
14
- ecdsa: new Uint8Array([2]),
15
- ed25519: new Uint8Array([0]),
16
- ethereum: new Uint8Array([2]),
17
- sr25519: new Uint8Array([1])
18
- };
19
- const TYPE_SIGNATURE = {
20
- ecdsa: (m, p) => secp256k1Sign(m, p, 'blake2'),
21
- ed25519: ed25519Sign,
22
- ethereum: (m, p) => secp256k1Sign(m, p, 'keccak'),
23
- sr25519: sr25519Sign
24
- };
25
- const TYPE_ADDRESS = {
26
- ecdsa: (p) => p.length > 32 ? blake2AsU8a(p) : p,
27
- ed25519: (p) => p,
28
- ethereum: (p) => p.length === 20 ? p : keccakAsU8a(secp256k1Expand(p)),
29
- sr25519: (p) => p
30
- };
31
- function isLocked(secretKey) {
32
- return !secretKey || u8aEmpty(secretKey);
33
- }
34
- function vrfHash(proof, context, extra) {
35
- return blake2AsU8a(u8aConcat(context || '', extra || '', proof));
36
- }
37
- /**
38
- * @name createPair
39
- * @summary Creates a keyring pair object
40
- * @description Creates a keyring pair object with provided account public key, metadata, and encoded arguments.
41
- * The keyring pair stores the account state including the encoded address and associated metadata.
42
- *
43
- * It has properties whose values are functions that may be called to perform account actions:
44
- *
45
- * - `address` function retrieves the address associated with the account.
46
- * - `decodedPkcs8` function is called with the account passphrase and account encoded public key.
47
- * It decodes the encoded public key using the passphrase provided to obtain the decoded account public key
48
- * and associated secret key that are then available in memory, and changes the account address stored in the
49
- * state of the pair to correspond to the address of the decoded public key.
50
- * - `encodePkcs8` function when provided with the correct passphrase associated with the account pair
51
- * and when the secret key is in memory (when the account pair is not locked) it returns an encoded
52
- * public key of the account.
53
- * - `meta` is the metadata that is stored in the state of the pair, either when it was originally
54
- * created or set via `setMeta`.
55
- * - `publicKey` returns the public key stored in memory for the pair.
56
- * - `sign` may be used to return a signature by signing a provided message with the secret
57
- * key (if it is in memory) using Nacl.
58
- * - `toJson` calls another `toJson` function and provides the state of the pair,
59
- * it generates arguments to be passed to the other `toJson` function including an encoded public key of the account
60
- * that it generates using the secret key from memory (if it has been made available in memory)
61
- * and the optionally provided passphrase argument. It passes a third boolean argument to `toJson`
62
- * indicating whether the public key has been encoded or not (if a passphrase argument was provided then it is encoded).
63
- * The `toJson` function that it calls returns a JSON object with properties including the `address`
64
- * and `meta` that are assigned with the values stored in the corresponding state variables of the account pair,
65
- * an `encoded` property that is assigned with the encoded public key in hex format, and an `encoding`
66
- * property that indicates whether the public key value of the `encoded` property is encoded or not.
67
- */
68
- export function createPair({ toSS58, type }, { publicKey, secretKey }, meta = {}, encoded = null, encTypes) {
69
- const decodePkcs8 = (passphrase, userEncoded) => {
70
- const decoded = decodePair(passphrase, userEncoded || encoded, encTypes);
71
- if (decoded.secretKey.length === 64) {
72
- publicKey = decoded.publicKey;
73
- secretKey = decoded.secretKey;
74
- }
75
- else {
76
- const pair = TYPE_FROM_SEED[type](decoded.secretKey);
77
- publicKey = pair.publicKey;
78
- secretKey = pair.secretKey;
79
- }
80
- };
81
- const recode = (passphrase) => {
82
- isLocked(secretKey) && encoded && decodePkcs8(passphrase, encoded);
83
- encoded = encodePair({ publicKey, secretKey }, passphrase); // re-encode, latest version
84
- encTypes = undefined; // swap to defaults, latest version follows
85
- return encoded;
86
- };
87
- const encodeAddress = () => {
88
- const raw = TYPE_ADDRESS[type](publicKey);
89
- return type === 'ethereum'
90
- ? ethereumEncode(raw)
91
- : toSS58(raw);
92
- };
93
- return {
94
- get address() {
95
- return encodeAddress();
96
- },
97
- get addressRaw() {
98
- const raw = TYPE_ADDRESS[type](publicKey);
99
- return type === 'ethereum'
100
- ? raw.slice(-20)
101
- : raw;
102
- },
103
- get isLocked() {
104
- return isLocked(secretKey);
105
- },
106
- get meta() {
107
- return meta;
108
- },
109
- get publicKey() {
110
- return publicKey;
111
- },
112
- get type() {
113
- return type;
114
- },
115
- // eslint-disable-next-line sort-keys
116
- decodePkcs8,
117
- derive: (suri, meta) => {
118
- if (type === 'ethereum') {
119
- throw new Error('Unable to derive on this keypair');
120
- }
121
- else if (isLocked(secretKey)) {
122
- throw new Error('Cannot derive on a locked keypair');
123
- }
124
- const { path } = keyExtractPath(suri);
125
- const derived = keyFromPath({ publicKey, secretKey }, path, type);
126
- return createPair({ toSS58, type }, derived, meta, null);
127
- },
128
- encodePkcs8: (passphrase) => {
129
- return recode(passphrase);
130
- },
131
- lock: () => {
132
- secretKey = new Uint8Array();
133
- },
134
- setMeta: (additional) => {
135
- meta = objectSpread({}, meta, additional);
136
- },
137
- sign: (message, options = {}) => {
138
- if (isLocked(secretKey)) {
139
- throw new Error('Cannot sign with a locked key pair');
140
- }
141
- return u8aConcat(options.withType
142
- ? TYPE_PREFIX[type]
143
- : SIG_TYPE_NONE, TYPE_SIGNATURE[type](u8aToU8a(message), { publicKey, secretKey }));
144
- },
145
- toJson: (passphrase) => {
146
- // NOTE: For ecdsa and ethereum, the publicKey cannot be extracted from the address. For these
147
- // pass the hex-encoded publicKey through to the address portion of the JSON (before decoding)
148
- // unless the publicKey is already an address
149
- const address = ['ecdsa', 'ethereum'].includes(type)
150
- ? publicKey.length === 20
151
- ? u8aToHex(publicKey)
152
- : u8aToHex(secp256k1Compress(publicKey))
153
- : encodeAddress();
154
- return pairToJson(type, { address, meta }, recode(passphrase), !!passphrase);
155
- },
156
- unlock: (passphrase) => {
157
- return decodePkcs8(passphrase);
158
- },
159
- verify: (message, signature, signerPublic) => {
160
- return signatureVerify(message, signature, TYPE_ADDRESS[type](u8aToU8a(signerPublic))).isValid;
161
- },
162
- vrfSign: (message, context, extra) => {
163
- if (isLocked(secretKey)) {
164
- throw new Error('Cannot sign with a locked key pair');
165
- }
166
- if (type === 'sr25519') {
167
- return sr25519VrfSign(message, { secretKey }, context, extra);
168
- }
169
- const proof = TYPE_SIGNATURE[type](u8aToU8a(message), { publicKey, secretKey });
170
- return u8aConcat(vrfHash(proof, context, extra), proof);
171
- },
172
- vrfVerify: (message, vrfResult, signerPublic, context, extra) => {
173
- if (type === 'sr25519') {
174
- return sr25519VrfVerify(message, vrfResult, publicKey, context, extra);
175
- }
176
- const result = signatureVerify(message, u8aConcat(TYPE_PREFIX[type], vrfResult.subarray(32)), TYPE_ADDRESS[type](u8aToU8a(signerPublic)));
177
- return result.isValid && u8aEq(vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra));
178
- }
179
- };
180
- }
@@ -1,2 +0,0 @@
1
- import type { KeyringPair } from '../types.js';
2
- export declare function nobody(): KeyringPair;