@pezkuwi/keyring 14.0.7 → 14.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/LICENSE +201 -0
- package/build/README.md +17 -0
- package/build/bundle-pezkuwi-keyring.js +553 -0
- package/build/bundle.d.ts +7 -0
- package/build/bundle.js +7 -0
- package/build/cjs/bundle.d.ts +7 -0
- package/build/cjs/bundle.js +19 -0
- package/build/cjs/defaults.d.ts +2 -0
- package/build/cjs/defaults.js +5 -0
- package/build/cjs/index.d.ts +4 -0
- package/build/cjs/index.js +7 -0
- package/build/cjs/keyring.d.ts +145 -0
- package/build/cjs/keyring.js +261 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/packageDetect.d.ts +1 -0
- package/build/cjs/packageDetect.js +7 -0
- package/build/cjs/packageInfo.d.ts +6 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/pair/decode.d.ts +12 -0
- package/build/cjs/pair/decode.js +45 -0
- package/build/cjs/pair/defaults.d.ts +12 -0
- package/build/cjs/pair/defaults.js +15 -0
- package/build/cjs/pair/encode.d.ts +5 -0
- package/build/cjs/pair/encode.js +22 -0
- package/build/cjs/pair/index.d.ts +40 -0
- package/build/cjs/pair/index.js +183 -0
- package/build/cjs/pair/nobody.d.ts +2 -0
- package/build/cjs/pair/nobody.js +43 -0
- package/build/cjs/pair/toJson.d.ts +8 -0
- package/build/cjs/pair/toJson.js +11 -0
- package/build/cjs/pair/types.d.ts +5 -0
- package/build/cjs/pair/types.js +2 -0
- package/build/cjs/pairs.d.ts +8 -0
- package/build/cjs/pairs.js +28 -0
- package/build/cjs/testing.d.ts +20 -0
- package/build/cjs/testing.js +126 -0
- package/build/cjs/testingPairs.d.ts +25 -0
- package/build/cjs/testingPairs.js +16 -0
- package/build/cjs/types.d.ts +111 -0
- package/build/cjs/types.js +2 -0
- package/build/defaults.d.ts +2 -0
- package/build/defaults.js +2 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/build/keyring.d.ts +145 -0
- package/build/keyring.js +257 -0
- package/build/package.json +294 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +5 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/pair/decode.d.ts +12 -0
- package/build/pair/decode.js +42 -0
- package/build/pair/defaults.d.ts +12 -0
- package/build/pair/defaults.js +12 -0
- package/build/pair/encode.d.ts +5 -0
- package/build/pair/encode.js +19 -0
- package/build/pair/index.d.ts +40 -0
- package/build/pair/index.js +180 -0
- package/build/pair/nobody.d.ts +2 -0
- package/build/pair/nobody.js +40 -0
- package/build/pair/toJson.d.ts +8 -0
- package/build/pair/toJson.js +8 -0
- package/build/pair/types.d.ts +5 -0
- package/build/pair/types.js +1 -0
- package/build/pairs.d.ts +8 -0
- package/build/pairs.js +24 -0
- package/build/testing.d.ts +20 -0
- package/build/testing.js +122 -0
- package/build/testingPairs.d.ts +25 -0
- package/build/testingPairs.js +13 -0
- package/build/types.d.ts +111 -0
- package/build/types.js +1 -0
- package/build-deno/README.md +17 -0
- package/build-deno/bundle.ts +10 -0
- package/build-deno/defaults.ts +4 -0
- package/build-deno/index.ts +8 -0
- package/build-deno/keyring.ts +305 -0
- package/build-deno/mod.ts +2 -0
- package/build-deno/packageDetect.ts +9 -0
- package/build-deno/packageInfo.ts +3 -0
- package/build-deno/pair/decode.ts +54 -0
- package/build-deno/pair/defaults.ts +18 -0
- package/build-deno/pair/encode.ts +28 -0
- package/build-deno/pair/index.ts +218 -0
- package/build-deno/pair/nobody.ts +58 -0
- package/build-deno/pair/toJson.ts +18 -0
- package/build-deno/pair/types.ts +6 -0
- package/build-deno/pairs.ts +39 -0
- package/build-deno/testing.ts +150 -0
- package/build-deno/testingPairs.ts +54 -0
- package/build-deno/types.ts +129 -0
- package/build-tsc/bundle.d.ts +7 -0
- package/build-tsc/defaults.d.ts +2 -0
- package/build-tsc/index.d.ts +4 -0
- package/build-tsc/keyring.d.ts +145 -0
- package/build-tsc/packageDetect.d.ts +1 -0
- package/build-tsc/packageInfo.d.ts +6 -0
- package/build-tsc/pair/decode.d.ts +12 -0
- package/build-tsc/pair/defaults.d.ts +12 -0
- package/build-tsc/pair/encode.d.ts +5 -0
- package/build-tsc/pair/index.d.ts +40 -0
- package/build-tsc/pair/nobody.d.ts +2 -0
- package/build-tsc/pair/toJson.d.ts +8 -0
- package/build-tsc/pair/types.d.ts +5 -0
- package/build-tsc/pairs.d.ts +8 -0
- package/build-tsc/testing.d.ts +20 -0
- package/build-tsc/testingPairs.d.ts +25 -0
- package/build-tsc/types.d.ts +111 -0
- package/build-tsc-cjs/bundle.js +19 -0
- package/build-tsc-cjs/defaults.js +5 -0
- package/build-tsc-cjs/index.js +7 -0
- package/build-tsc-cjs/keyring.js +261 -0
- package/build-tsc-cjs/packageDetect.js +7 -0
- package/build-tsc-cjs/packageInfo.js +4 -0
- package/build-tsc-cjs/pair/decode.js +45 -0
- package/build-tsc-cjs/pair/defaults.js +15 -0
- package/build-tsc-cjs/pair/encode.js +22 -0
- package/build-tsc-cjs/pair/index.js +183 -0
- package/build-tsc-cjs/pair/nobody.js +43 -0
- package/build-tsc-cjs/pair/toJson.js +11 -0
- package/build-tsc-cjs/pair/types.js +2 -0
- package/build-tsc-cjs/pairs.js +28 -0
- package/build-tsc-cjs/testing.js +126 -0
- package/build-tsc-cjs/testingPairs.js +16 -0
- package/build-tsc-cjs/types.js +2 -0
- package/build-tsc-esm/bundle.js +7 -0
- package/build-tsc-esm/defaults.js +2 -0
- package/build-tsc-esm/index.js +4 -0
- package/build-tsc-esm/keyring.js +257 -0
- package/build-tsc-esm/packageDetect.js +5 -0
- package/build-tsc-esm/packageInfo.js +1 -0
- package/build-tsc-esm/pair/decode.js +42 -0
- package/build-tsc-esm/pair/defaults.js +12 -0
- package/build-tsc-esm/pair/encode.js +19 -0
- package/build-tsc-esm/pair/index.js +180 -0
- package/build-tsc-esm/pair/nobody.js +40 -0
- package/build-tsc-esm/pair/toJson.js +8 -0
- package/build-tsc-esm/pair/types.js +1 -0
- package/build-tsc-esm/pairs.js +24 -0
- package/build-tsc-esm/testing.js +122 -0
- package/build-tsc-esm/testingPairs.js +13 -0
- package/build-tsc-esm/types.js +1 -0
- package/bundle-pezkuwi-keyring.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/package.json +6 -6
- package/packageInfo.js +1 -1
- package/src/bundle.ts +16 -0
- package/src/defaults.ts +8 -0
- package/src/index.spec.ts +609 -0
- package/src/index.ts +10 -0
- package/src/keyring.ts +307 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +13 -0
- package/src/packageInfo.ts +6 -0
- package/src/pair/decode.spec.ts +26 -0
- package/src/pair/decode.ts +56 -0
- package/src/pair/defaults.ts +20 -0
- package/src/pair/encode.spec.ts +28 -0
- package/src/pair/encode.ts +30 -0
- package/src/pair/index.spec.ts +189 -0
- package/src/pair/index.ts +220 -0
- package/src/pair/nobody.ts +62 -0
- package/src/pair/toJson.spec.ts +42 -0
- package/src/pair/toJson.ts +20 -0
- package/src/pair/types.ts +8 -0
- package/src/pair/vrf.spec.ts +47 -0
- package/src/pairs.ts +41 -0
- package/src/suri.spec.ts +109 -0
- package/src/testing.ts +156 -0
- package/src/testingPairs.spec.ts +79 -0
- package/src/testingPairs.ts +56 -0
- package/src/types.ts +131 -0
- package/tsconfig.build.json +16 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +18 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Pezkuwi Team <team@pezkuwichain.app>",
|
|
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.10",
|
|
22
|
+
"main": "./cjs/index.js",
|
|
23
|
+
"module": "./index.js",
|
|
24
|
+
"types": "./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": "workspace:*",
|
|
287
|
+
"@pezkuwi/util-crypto": "workspace:*",
|
|
288
|
+
"tslib": "^2.8.0"
|
|
289
|
+
},
|
|
290
|
+
"peerDependencies": {
|
|
291
|
+
"@pezkuwi/util": "workspace:*",
|
|
292
|
+
"@pezkuwi/util-crypto": "workspace:*"
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
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]);
|
|
@@ -0,0 +1 @@
|
|
|
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.10' };
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
|
|
2
|
+
export declare const PAIR_DIV: Uint8Array;
|
|
3
|
+
/** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
|
|
4
|
+
export declare const PAIR_HDR: Uint8Array;
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,180 @@
|
|
|
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
|
+
}
|