@typeberry/native 0.2.0-173c341 → 0.2.0-bd1a174
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/bandersnatch_wasm-CKJzeiX9.js +344 -0
- package/index.d.ts +48 -12
- package/index.js +124 -7
- package/native-DwnxR2Io.js +34 -0
- package/package.json +3 -3
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
//#region bandersnatch/wasm-binding/pkg/bandersnatch_wasm.js
|
|
2
|
+
/**
|
|
3
|
+
* @param {number} ring_size
|
|
4
|
+
* @param {Uint8Array} commitment
|
|
5
|
+
* @param {Uint8Array} tickets_data
|
|
6
|
+
* @param {number} vrf_input_data_len
|
|
7
|
+
* @returns {Uint8Array}
|
|
8
|
+
*/
|
|
9
|
+
function batch_verify_tickets(ring_size, commitment, tickets_data, vrf_input_data_len) {
|
|
10
|
+
const ptr0 = passArray8ToWasm0(commitment, wasm.__wbindgen_malloc);
|
|
11
|
+
const len0 = WASM_VECTOR_LEN;
|
|
12
|
+
const ptr1 = passArray8ToWasm0(tickets_data, wasm.__wbindgen_malloc);
|
|
13
|
+
const len1 = WASM_VECTOR_LEN;
|
|
14
|
+
const ret = wasm.batch_verify_tickets(ring_size, ptr0, len0, ptr1, len1, vrf_input_data_len);
|
|
15
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
16
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
17
|
+
return v3;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @param {Uint8Array} seed
|
|
21
|
+
* @returns {Uint8Array}
|
|
22
|
+
*/
|
|
23
|
+
function derive_public_key(seed) {
|
|
24
|
+
const ptr0 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc);
|
|
25
|
+
const len0 = WASM_VECTOR_LEN;
|
|
26
|
+
const ret = wasm.derive_public_key(ptr0, len0);
|
|
27
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
28
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
29
|
+
return v2;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param {Uint8Array} secret_seed
|
|
33
|
+
* @param {Uint8Array} input
|
|
34
|
+
* @param {Uint8Array} aux_data
|
|
35
|
+
* @returns {Uint8Array}
|
|
36
|
+
*/
|
|
37
|
+
function generate_seal(secret_seed, input, aux_data) {
|
|
38
|
+
const ptr0 = passArray8ToWasm0(secret_seed, wasm.__wbindgen_malloc);
|
|
39
|
+
const len0 = WASM_VECTOR_LEN;
|
|
40
|
+
const ptr1 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
41
|
+
const len1 = WASM_VECTOR_LEN;
|
|
42
|
+
const ptr2 = passArray8ToWasm0(aux_data, wasm.__wbindgen_malloc);
|
|
43
|
+
const len2 = WASM_VECTOR_LEN;
|
|
44
|
+
const ret = wasm.generate_seal(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
45
|
+
var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
46
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
47
|
+
return v4;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @param {Uint8Array} keys
|
|
51
|
+
* @returns {Uint8Array}
|
|
52
|
+
*/
|
|
53
|
+
function ring_commitment(keys) {
|
|
54
|
+
const ptr0 = passArray8ToWasm0(keys, wasm.__wbindgen_malloc);
|
|
55
|
+
const len0 = WASM_VECTOR_LEN;
|
|
56
|
+
const ret = wasm.ring_commitment(ptr0, len0);
|
|
57
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
58
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
59
|
+
return v2;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @param {Uint8Array} signer_key
|
|
63
|
+
* @param {Uint8Array} seal_data
|
|
64
|
+
* @param {Uint8Array} seal_payload
|
|
65
|
+
* @param {Uint8Array} unsealed_header
|
|
66
|
+
* @param {Uint8Array} entropy_data
|
|
67
|
+
* @param {Uint8Array} entropy_prefix
|
|
68
|
+
* @returns {Uint8Array}
|
|
69
|
+
*/
|
|
70
|
+
function verify_header_seals(signer_key, seal_data, seal_payload, unsealed_header, entropy_data, entropy_prefix) {
|
|
71
|
+
const ptr0 = passArray8ToWasm0(signer_key, wasm.__wbindgen_malloc);
|
|
72
|
+
const len0 = WASM_VECTOR_LEN;
|
|
73
|
+
const ptr1 = passArray8ToWasm0(seal_data, wasm.__wbindgen_malloc);
|
|
74
|
+
const len1 = WASM_VECTOR_LEN;
|
|
75
|
+
const ptr2 = passArray8ToWasm0(seal_payload, wasm.__wbindgen_malloc);
|
|
76
|
+
const len2 = WASM_VECTOR_LEN;
|
|
77
|
+
const ptr3 = passArray8ToWasm0(unsealed_header, wasm.__wbindgen_malloc);
|
|
78
|
+
const len3 = WASM_VECTOR_LEN;
|
|
79
|
+
const ptr4 = passArray8ToWasm0(entropy_data, wasm.__wbindgen_malloc);
|
|
80
|
+
const len4 = WASM_VECTOR_LEN;
|
|
81
|
+
const ptr5 = passArray8ToWasm0(entropy_prefix, wasm.__wbindgen_malloc);
|
|
82
|
+
const len5 = WASM_VECTOR_LEN;
|
|
83
|
+
const ret = wasm.verify_header_seals(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
|
|
84
|
+
var v7 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
85
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
86
|
+
return v7;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @param {Uint8Array} signer_key
|
|
90
|
+
* @param {Uint8Array} seal_data
|
|
91
|
+
* @param {Uint8Array} payload
|
|
92
|
+
* @param {Uint8Array} aux_data
|
|
93
|
+
* @returns {Uint8Array}
|
|
94
|
+
*/
|
|
95
|
+
function verify_seal(signer_key, seal_data, payload, aux_data) {
|
|
96
|
+
const ptr0 = passArray8ToWasm0(signer_key, wasm.__wbindgen_malloc);
|
|
97
|
+
const len0 = WASM_VECTOR_LEN;
|
|
98
|
+
const ptr1 = passArray8ToWasm0(seal_data, wasm.__wbindgen_malloc);
|
|
99
|
+
const len1 = WASM_VECTOR_LEN;
|
|
100
|
+
const ptr2 = passArray8ToWasm0(payload, wasm.__wbindgen_malloc);
|
|
101
|
+
const len2 = WASM_VECTOR_LEN;
|
|
102
|
+
const ptr3 = passArray8ToWasm0(aux_data, wasm.__wbindgen_malloc);
|
|
103
|
+
const len3 = WASM_VECTOR_LEN;
|
|
104
|
+
const ret = wasm.verify_seal(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
105
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
106
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
107
|
+
return v5;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @param {Uint8Array} secret_seed
|
|
111
|
+
* @param {Uint8Array} input
|
|
112
|
+
* @returns {Uint8Array}
|
|
113
|
+
*/
|
|
114
|
+
function vrf_output_hash(secret_seed, input) {
|
|
115
|
+
const ptr0 = passArray8ToWasm0(secret_seed, wasm.__wbindgen_malloc);
|
|
116
|
+
const len0 = WASM_VECTOR_LEN;
|
|
117
|
+
const ptr1 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
118
|
+
const len1 = WASM_VECTOR_LEN;
|
|
119
|
+
const ret = wasm.vrf_output_hash(ptr0, len0, ptr1, len1);
|
|
120
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
121
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
122
|
+
return v3;
|
|
123
|
+
}
|
|
124
|
+
function __wbg_get_imports() {
|
|
125
|
+
const import0 = {
|
|
126
|
+
__proto__: null,
|
|
127
|
+
__wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
|
|
128
|
+
return typeof arg0 === "function";
|
|
129
|
+
},
|
|
130
|
+
__wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
|
|
131
|
+
const val = arg0;
|
|
132
|
+
return typeof val === "object" && val !== null;
|
|
133
|
+
},
|
|
134
|
+
__wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
|
|
135
|
+
return typeof arg0 === "string";
|
|
136
|
+
},
|
|
137
|
+
__wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
|
|
138
|
+
return arg0 === void 0;
|
|
139
|
+
},
|
|
140
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
141
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
142
|
+
},
|
|
143
|
+
__wbg_call_389efe28435a9388: function() {
|
|
144
|
+
return handleError(function(arg0, arg1) {
|
|
145
|
+
return arg0.call(arg1);
|
|
146
|
+
}, arguments);
|
|
147
|
+
},
|
|
148
|
+
__wbg_call_4708e0c13bdc8e95: function() {
|
|
149
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
150
|
+
return arg0.call(arg1, arg2);
|
|
151
|
+
}, arguments);
|
|
152
|
+
},
|
|
153
|
+
__wbg_crypto_86f2631e91b51511: function(arg0) {
|
|
154
|
+
return arg0.crypto;
|
|
155
|
+
},
|
|
156
|
+
__wbg_getRandomValues_b3f15fcbfabb0f8b: function() {
|
|
157
|
+
return handleError(function(arg0, arg1) {
|
|
158
|
+
arg0.getRandomValues(arg1);
|
|
159
|
+
}, arguments);
|
|
160
|
+
},
|
|
161
|
+
__wbg_length_32ed9a279acd054c: function(arg0) {
|
|
162
|
+
return arg0.length;
|
|
163
|
+
},
|
|
164
|
+
__wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
|
|
165
|
+
return arg0.msCrypto;
|
|
166
|
+
},
|
|
167
|
+
__wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
|
|
168
|
+
return new Function(getStringFromWasm0(arg0, arg1));
|
|
169
|
+
},
|
|
170
|
+
__wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
|
|
171
|
+
return new Uint8Array(arg0 >>> 0);
|
|
172
|
+
},
|
|
173
|
+
__wbg_node_e1f24f89a7336c2e: function(arg0) {
|
|
174
|
+
return arg0.node;
|
|
175
|
+
},
|
|
176
|
+
__wbg_process_3975fd6c72f520aa: function(arg0) {
|
|
177
|
+
return arg0.process;
|
|
178
|
+
},
|
|
179
|
+
__wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
|
|
180
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
181
|
+
},
|
|
182
|
+
__wbg_randomFillSync_f8c153b79f285817: function() {
|
|
183
|
+
return handleError(function(arg0, arg1) {
|
|
184
|
+
arg0.randomFillSync(arg1);
|
|
185
|
+
}, arguments);
|
|
186
|
+
},
|
|
187
|
+
__wbg_require_b74f47fc2d022fd6: function() {
|
|
188
|
+
return handleError(function() {
|
|
189
|
+
return module.require;
|
|
190
|
+
}, arguments);
|
|
191
|
+
},
|
|
192
|
+
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
193
|
+
const ret = typeof global === "undefined" ? null : global;
|
|
194
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
195
|
+
},
|
|
196
|
+
__wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
|
|
197
|
+
const ret = typeof globalThis === "undefined" ? null : globalThis;
|
|
198
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
199
|
+
},
|
|
200
|
+
__wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
|
|
201
|
+
const ret = typeof self === "undefined" ? null : self;
|
|
202
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
203
|
+
},
|
|
204
|
+
__wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
|
|
205
|
+
const ret = typeof window === "undefined" ? null : window;
|
|
206
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
207
|
+
},
|
|
208
|
+
__wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
|
|
209
|
+
return arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
210
|
+
},
|
|
211
|
+
__wbg_versions_4e31226f5e8dc909: function(arg0) {
|
|
212
|
+
return arg0.versions;
|
|
213
|
+
},
|
|
214
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
215
|
+
return getArrayU8FromWasm0(arg0, arg1);
|
|
216
|
+
},
|
|
217
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
218
|
+
return getStringFromWasm0(arg0, arg1);
|
|
219
|
+
},
|
|
220
|
+
__wbindgen_init_externref_table: function() {
|
|
221
|
+
const table = wasm.__wbindgen_externrefs;
|
|
222
|
+
const offset = table.grow(4);
|
|
223
|
+
table.set(0, void 0);
|
|
224
|
+
table.set(offset + 0, void 0);
|
|
225
|
+
table.set(offset + 1, null);
|
|
226
|
+
table.set(offset + 2, true);
|
|
227
|
+
table.set(offset + 3, false);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
return {
|
|
231
|
+
__proto__: null,
|
|
232
|
+
"./bandersnatch_wasm_bg.js": import0
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function addToExternrefTable0(obj) {
|
|
236
|
+
const idx = wasm.__externref_table_alloc();
|
|
237
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
238
|
+
return idx;
|
|
239
|
+
}
|
|
240
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
241
|
+
ptr = ptr >>> 0;
|
|
242
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
243
|
+
}
|
|
244
|
+
function getStringFromWasm0(ptr, len) {
|
|
245
|
+
ptr = ptr >>> 0;
|
|
246
|
+
return decodeText(ptr, len);
|
|
247
|
+
}
|
|
248
|
+
let cachedUint8ArrayMemory0 = null;
|
|
249
|
+
function getUint8ArrayMemory0() {
|
|
250
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
251
|
+
return cachedUint8ArrayMemory0;
|
|
252
|
+
}
|
|
253
|
+
function handleError(f, args) {
|
|
254
|
+
try {
|
|
255
|
+
return f.apply(this, args);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
const idx = addToExternrefTable0(e);
|
|
258
|
+
wasm.__wbindgen_exn_store(idx);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function isLikeNone(x) {
|
|
262
|
+
return x === void 0 || x === null;
|
|
263
|
+
}
|
|
264
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
265
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
266
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
267
|
+
WASM_VECTOR_LEN = arg.length;
|
|
268
|
+
return ptr;
|
|
269
|
+
}
|
|
270
|
+
let cachedTextDecoder = new TextDecoder("utf-8", {
|
|
271
|
+
ignoreBOM: true,
|
|
272
|
+
fatal: true
|
|
273
|
+
});
|
|
274
|
+
cachedTextDecoder.decode();
|
|
275
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
276
|
+
let numBytesDecoded = 0;
|
|
277
|
+
function decodeText(ptr, len) {
|
|
278
|
+
numBytesDecoded += len;
|
|
279
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
280
|
+
cachedTextDecoder = new TextDecoder("utf-8", {
|
|
281
|
+
ignoreBOM: true,
|
|
282
|
+
fatal: true
|
|
283
|
+
});
|
|
284
|
+
cachedTextDecoder.decode();
|
|
285
|
+
numBytesDecoded = len;
|
|
286
|
+
}
|
|
287
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
288
|
+
}
|
|
289
|
+
let WASM_VECTOR_LEN = 0, wasm;
|
|
290
|
+
function __wbg_finalize_init(instance, module$1) {
|
|
291
|
+
wasm = instance.exports;
|
|
292
|
+
cachedUint8ArrayMemory0 = null;
|
|
293
|
+
wasm.__wbindgen_start();
|
|
294
|
+
return wasm;
|
|
295
|
+
}
|
|
296
|
+
async function __wbg_load(module$1, imports) {
|
|
297
|
+
if (typeof Response === "function" && module$1 instanceof Response) {
|
|
298
|
+
if (typeof WebAssembly.instantiateStreaming === "function") try {
|
|
299
|
+
return await WebAssembly.instantiateStreaming(module$1, imports);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
if (module$1.ok && expectedResponseType(module$1.type) && module$1.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
302
|
+
else throw e;
|
|
303
|
+
}
|
|
304
|
+
const bytes = await module$1.arrayBuffer();
|
|
305
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
306
|
+
} else {
|
|
307
|
+
const instance = await WebAssembly.instantiate(module$1, imports);
|
|
308
|
+
if (instance instanceof WebAssembly.Instance) return {
|
|
309
|
+
instance,
|
|
310
|
+
module: module$1
|
|
311
|
+
};
|
|
312
|
+
else return instance;
|
|
313
|
+
}
|
|
314
|
+
function expectedResponseType(type) {
|
|
315
|
+
switch (type) {
|
|
316
|
+
case "basic":
|
|
317
|
+
case "cors":
|
|
318
|
+
case "default": return true;
|
|
319
|
+
}
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function initSync(module$1) {
|
|
324
|
+
if (wasm !== void 0) return wasm;
|
|
325
|
+
if (module$1 !== void 0) if (Object.getPrototypeOf(module$1) === Object.prototype) ({module: module$1} = module$1);
|
|
326
|
+
else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
|
|
327
|
+
const imports = __wbg_get_imports();
|
|
328
|
+
if (!(module$1 instanceof WebAssembly.Module)) module$1 = new WebAssembly.Module(module$1);
|
|
329
|
+
const instance = new WebAssembly.Instance(module$1, imports);
|
|
330
|
+
return __wbg_finalize_init(instance, module$1);
|
|
331
|
+
}
|
|
332
|
+
async function __wbg_init(module_or_path) {
|
|
333
|
+
if (wasm !== void 0) return wasm;
|
|
334
|
+
if (module_or_path !== void 0) if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
|
|
335
|
+
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
336
|
+
if (module_or_path === void 0) module_or_path = new URL("bandersnatch_wasm_bg.wasm", import.meta.url);
|
|
337
|
+
const imports = __wbg_get_imports();
|
|
338
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
|
|
339
|
+
const { instance, module: module$1 } = await __wbg_load(await module_or_path, imports);
|
|
340
|
+
return __wbg_finalize_init(instance, module$1);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
//#endregion
|
|
344
|
+
export { batch_verify_tickets, __wbg_init as default, derive_public_key, generate_seal, initSync, ring_commitment, verify_header_seals, verify_seal, vrf_output_hash };
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as bandersnatch from "@typeberry/bandersnatch";
|
|
2
|
-
|
|
3
|
-
//#region ed25519/pkg/ed25519_wasm.d.ts
|
|
4
1
|
declare namespace ed25519_wasm_d_exports {
|
|
5
|
-
export { InitInput$
|
|
2
|
+
export { InitInput$2 as InitInput, InitOutput$1 as InitOutput, SyncInitInput$1 as SyncInitInput, __wbg_init$1 as default, initSync$1 as initSync, verify_ed25519, verify_ed25519_batch };
|
|
6
3
|
}
|
|
7
4
|
/* tslint:disable */
|
|
8
5
|
/* eslint-disable */
|
|
@@ -19,7 +16,7 @@ declare function verify_ed25519(data: Uint8Array): Uint8Array;
|
|
|
19
16
|
*
|
|
20
17
|
*/
|
|
21
18
|
declare function verify_ed25519_batch(data: Uint8Array): boolean;
|
|
22
|
-
type InitInput$
|
|
19
|
+
type InitInput$2 = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
23
20
|
interface InitOutput$1 {
|
|
24
21
|
readonly memory: WebAssembly.Memory;
|
|
25
22
|
readonly verify_ed25519: (a: number, b: number) => [number, number];
|
|
@@ -51,10 +48,10 @@ declare function initSync$1(module: {
|
|
|
51
48
|
* @returns {Promise<InitOutput>}
|
|
52
49
|
*/
|
|
53
50
|
declare function __wbg_init$1(module_or_path?: {
|
|
54
|
-
module_or_path: InitInput$
|
|
55
|
-
} | InitInput$
|
|
51
|
+
module_or_path: InitInput$2 | Promise<InitInput$2>;
|
|
52
|
+
} | InitInput$2 | Promise<InitInput$2>): Promise<InitOutput$1>;
|
|
56
53
|
declare namespace reed_solomon_wasm_d_exports {
|
|
57
|
-
export { InitInput, InitOutput, ShardsCollection, SyncInitInput, decode, __wbg_init as default, encode, initSync };
|
|
54
|
+
export { InitInput$1 as InitInput, InitOutput, ShardsCollection, SyncInitInput, decode, __wbg_init as default, encode, initSync };
|
|
58
55
|
}
|
|
59
56
|
/* tslint:disable */
|
|
60
57
|
/* eslint-disable */
|
|
@@ -102,7 +99,7 @@ declare class ShardsCollection {
|
|
|
102
99
|
*/
|
|
103
100
|
shard_len: number;
|
|
104
101
|
}
|
|
105
|
-
type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
102
|
+
type InitInput$1 = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
106
103
|
interface InitOutput {
|
|
107
104
|
readonly memory: WebAssembly.Memory;
|
|
108
105
|
readonly __wbg_get_shardscollection_length: (a: number) => number;
|
|
@@ -142,8 +139,47 @@ declare function initSync(module: {
|
|
|
142
139
|
* @returns {Promise<InitOutput>}
|
|
143
140
|
*/
|
|
144
141
|
declare function __wbg_init(module_or_path?: {
|
|
145
|
-
module_or_path: InitInput | Promise<InitInput>;
|
|
146
|
-
} | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
142
|
+
module_or_path: InitInput$1 | Promise<InitInput$1>;
|
|
143
|
+
} | InitInput$1 | Promise<InitInput$1>): Promise<InitOutput>;
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region bandersnatch/wasm-binding/pkg/bandersnatch_wasm.d.ts
|
|
146
|
+
type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
147
|
+
declare namespace index_d_exports {
|
|
148
|
+
export { BandersnatchApi, InitOptions, batchVerifyTickets, init$1 as default, derivePublicKey, generateSeal, getNativeBindingError, isInitialized, isNativeBinding, ringCommitment, verifyHeaderSeals, verifySeal, vrfOutputHash };
|
|
149
|
+
}
|
|
150
|
+
type BandersnatchApi = {
|
|
151
|
+
isNativeBinding: () => boolean;
|
|
152
|
+
ringCommitment: (keys: Uint8Array) => Uint8Array;
|
|
153
|
+
derivePublicKey: (seed: Uint8Array) => Uint8Array;
|
|
154
|
+
verifyHeaderSeals: (signerKey: Uint8Array, sealData: Uint8Array, sealPayload: Uint8Array, unsealedHeader: Uint8Array, entropyData: Uint8Array, entropyPrefix: Uint8Array) => Uint8Array;
|
|
155
|
+
verifySeal: (signerKey: Uint8Array, sealData: Uint8Array, payload: Uint8Array, auxData: Uint8Array) => Uint8Array;
|
|
156
|
+
generateSeal: (secretSeed: Uint8Array, input: Uint8Array, auxData: Uint8Array) => Uint8Array;
|
|
157
|
+
vrfOutputHash: (secretSeed: Uint8Array, input: Uint8Array) => Uint8Array;
|
|
158
|
+
batchVerifyTickets: (ringSize: number, commitment: Uint8Array, ticketsData: Uint8Array, vrfInputDataLen: number) => Uint8Array;
|
|
159
|
+
};
|
|
160
|
+
type InitOptions = {
|
|
161
|
+
module_or_path?: InitInput | Promise<InitInput>;
|
|
162
|
+
};
|
|
163
|
+
declare function init$1(options?: InitOptions): Promise<BandersnatchApi>;
|
|
164
|
+
/**
|
|
165
|
+
* Check if the binding is initialized already.
|
|
166
|
+
*/
|
|
167
|
+
declare function isInitialized(): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Returns true if native binding is used.
|
|
170
|
+
*/
|
|
171
|
+
declare function isNativeBinding(): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Returns native binding initialisation error (if any).
|
|
174
|
+
*/
|
|
175
|
+
declare function getNativeBindingError(): string | null;
|
|
176
|
+
declare function ringCommitment(keys: Uint8Array): Uint8Array;
|
|
177
|
+
declare function derivePublicKey(seed: Uint8Array): Uint8Array;
|
|
178
|
+
declare function verifyHeaderSeals(signerKey: Uint8Array, sealData: Uint8Array, sealPayload: Uint8Array, unsealedHeader: Uint8Array, entropyData: Uint8Array, entropyPrefix: Uint8Array): Uint8Array;
|
|
179
|
+
declare function verifySeal(signerKey: Uint8Array, sealData: Uint8Array, payload: Uint8Array, auxData: Uint8Array): Uint8Array;
|
|
180
|
+
declare function generateSeal(secretSeed: Uint8Array, input: Uint8Array, auxData: Uint8Array): Uint8Array;
|
|
181
|
+
declare function vrfOutputHash(secretSeed: Uint8Array, input: Uint8Array): Uint8Array;
|
|
182
|
+
declare function batchVerifyTickets(ringSize: number, commitment: Uint8Array, ticketsData: Uint8Array, vrfInputDataLen: number): Uint8Array;
|
|
147
183
|
//#endregion
|
|
148
184
|
//#region native/index.d.ts
|
|
149
185
|
declare function initAll(): Promise<void>;
|
|
@@ -153,4 +189,4 @@ declare const init: {
|
|
|
153
189
|
reedSolomon: () => Promise<InitOutput>;
|
|
154
190
|
};
|
|
155
191
|
//#endregion
|
|
156
|
-
export { bandersnatch, ed25519_wasm_d_exports as ed25519, init, initAll, reed_solomon_wasm_d_exports as reedSolomon };
|
|
192
|
+
export { index_d_exports as bandersnatch, ed25519_wasm_d_exports as ed25519, init, initAll, reed_solomon_wasm_d_exports as reedSolomon };
|
package/index.js
CHANGED
|
@@ -1,7 +1,124 @@
|
|
|
1
1
|
import { __export, __require } from "./chunk-CPmnHcRE.js";
|
|
2
|
-
import * as bandersnatch from "@typeberry/bandersnatch";
|
|
3
|
-
import bandersnatchInit from "@typeberry/bandersnatch";
|
|
4
2
|
|
|
3
|
+
//#region bandersnatch/src/index.ts
|
|
4
|
+
var src_exports = {};
|
|
5
|
+
__export(src_exports, {
|
|
6
|
+
batchVerifyTickets: () => batchVerifyTickets,
|
|
7
|
+
default: () => init$1,
|
|
8
|
+
derivePublicKey: () => derivePublicKey,
|
|
9
|
+
generateSeal: () => generateSeal,
|
|
10
|
+
getNativeBindingError: () => getNativeBindingError,
|
|
11
|
+
isInitialized: () => isInitialized,
|
|
12
|
+
isNativeBinding: () => isNativeBinding,
|
|
13
|
+
ringCommitment: () => ringCommitment,
|
|
14
|
+
verifyHeaderSeals: () => verifyHeaderSeals,
|
|
15
|
+
verifySeal: () => verifySeal,
|
|
16
|
+
vrfOutputHash: () => vrfOutputHash
|
|
17
|
+
});
|
|
18
|
+
let wasmBinding = null;
|
|
19
|
+
let nativeBinding = null;
|
|
20
|
+
let nativeBindingError = null;
|
|
21
|
+
function isNode() {
|
|
22
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
23
|
+
}
|
|
24
|
+
async function loadNativeBinding() {
|
|
25
|
+
if (!isNode()) {
|
|
26
|
+
nativeBindingError = "Invalid environment";
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const native = await import("./native-DwnxR2Io.js");
|
|
31
|
+
return native.default || native;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
nativeBindingError = `${e}`;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function loadWasmBinding(wasmModule) {
|
|
38
|
+
const wasmBindingModule = await import("./bandersnatch_wasm-CKJzeiX9.js");
|
|
39
|
+
await wasmBindingModule.default({ module_or_path: wasmModule });
|
|
40
|
+
return wasmBindingModule;
|
|
41
|
+
}
|
|
42
|
+
function createApi() {
|
|
43
|
+
return {
|
|
44
|
+
isNativeBinding,
|
|
45
|
+
ringCommitment,
|
|
46
|
+
derivePublicKey,
|
|
47
|
+
verifyHeaderSeals,
|
|
48
|
+
verifySeal,
|
|
49
|
+
generateSeal,
|
|
50
|
+
vrfOutputHash,
|
|
51
|
+
batchVerifyTickets
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function init$1(options) {
|
|
55
|
+
if (wasmBinding !== null || nativeBinding !== null) return createApi();
|
|
56
|
+
const native = await loadNativeBinding();
|
|
57
|
+
if (native) {
|
|
58
|
+
nativeBinding = native;
|
|
59
|
+
return createApi();
|
|
60
|
+
}
|
|
61
|
+
wasmBinding = await loadWasmBinding(options?.module_or_path);
|
|
62
|
+
return createApi();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if the binding is initialized already.
|
|
66
|
+
*/
|
|
67
|
+
function isInitialized() {
|
|
68
|
+
return wasmBinding !== null || nativeBinding !== null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns true if native binding is used.
|
|
72
|
+
*/
|
|
73
|
+
function isNativeBinding() {
|
|
74
|
+
return nativeBinding !== null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns native binding initialisation error (if any).
|
|
78
|
+
*/
|
|
79
|
+
function getNativeBindingError() {
|
|
80
|
+
return nativeBindingError;
|
|
81
|
+
}
|
|
82
|
+
function assertInitialized() {
|
|
83
|
+
if (!isInitialized()) throw new Error("Bandersnatch binding not initialized. Call init() first.");
|
|
84
|
+
}
|
|
85
|
+
function ringCommitment(keys) {
|
|
86
|
+
assertInitialized();
|
|
87
|
+
if (nativeBinding) return nativeBinding.ringCommitment(keys);
|
|
88
|
+
return wasmBinding.ring_commitment(keys);
|
|
89
|
+
}
|
|
90
|
+
function derivePublicKey(seed) {
|
|
91
|
+
assertInitialized();
|
|
92
|
+
if (nativeBinding) return nativeBinding.derivePublicKey(seed);
|
|
93
|
+
return wasmBinding.derive_public_key(seed);
|
|
94
|
+
}
|
|
95
|
+
function verifyHeaderSeals(signerKey, sealData, sealPayload, unsealedHeader, entropyData, entropyPrefix) {
|
|
96
|
+
assertInitialized();
|
|
97
|
+
if (nativeBinding) return nativeBinding.verifyHeaderSeals(signerKey, sealData, sealPayload, unsealedHeader, entropyData, entropyPrefix);
|
|
98
|
+
return wasmBinding.verify_header_seals(signerKey, sealData, sealPayload, unsealedHeader, entropyData, entropyPrefix);
|
|
99
|
+
}
|
|
100
|
+
function verifySeal(signerKey, sealData, payload, auxData) {
|
|
101
|
+
assertInitialized();
|
|
102
|
+
if (nativeBinding) return nativeBinding.verifySeal(signerKey, sealData, payload, auxData);
|
|
103
|
+
return wasmBinding.verify_seal(signerKey, sealData, payload, auxData);
|
|
104
|
+
}
|
|
105
|
+
function generateSeal(secretSeed, input, auxData) {
|
|
106
|
+
assertInitialized();
|
|
107
|
+
if (nativeBinding) return nativeBinding.generateSeal(secretSeed, input, auxData);
|
|
108
|
+
return wasmBinding.generate_seal(secretSeed, input, auxData);
|
|
109
|
+
}
|
|
110
|
+
function vrfOutputHash(secretSeed, input) {
|
|
111
|
+
assertInitialized();
|
|
112
|
+
if (nativeBinding) return nativeBinding.vrfOutputHash(secretSeed, input);
|
|
113
|
+
return wasmBinding.vrf_output_hash(secretSeed, input);
|
|
114
|
+
}
|
|
115
|
+
function batchVerifyTickets(ringSize, commitment, ticketsData, vrfInputDataLen) {
|
|
116
|
+
assertInitialized();
|
|
117
|
+
if (nativeBinding) return nativeBinding.batchVerifyTickets(ringSize, commitment, ticketsData, vrfInputDataLen);
|
|
118
|
+
return wasmBinding.batch_verify_tickets(ringSize, commitment, ticketsData, vrfInputDataLen);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
5
122
|
//#region ed25519/pkg/ed25519_wasm.js
|
|
6
123
|
var ed25519_wasm_exports = {};
|
|
7
124
|
__export(ed25519_wasm_exports, {
|
|
@@ -416,8 +533,8 @@ function _loadWasmModule(sync, filepath, src, imports) {
|
|
|
416
533
|
else return compileFunc(source);
|
|
417
534
|
}
|
|
418
535
|
var buf = null;
|
|
419
|
-
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
420
|
-
if (filepath && isNode) {
|
|
536
|
+
var isNode$1 = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
537
|
+
if (filepath && isNode$1) {
|
|
421
538
|
var fs = __require("fs");
|
|
422
539
|
var path = __require("path");
|
|
423
540
|
return new Promise((resolve, reject) => {
|
|
@@ -427,7 +544,7 @@ function _loadWasmModule(sync, filepath, src, imports) {
|
|
|
427
544
|
});
|
|
428
545
|
});
|
|
429
546
|
} else if (filepath) return _instantiateOrCompile(fetch(filepath), imports, true);
|
|
430
|
-
if (isNode) buf = Buffer.from(src, "base64");
|
|
547
|
+
if (isNode$1) buf = Buffer.from(src, "base64");
|
|
431
548
|
else {
|
|
432
549
|
var raw = globalThis.atob(src);
|
|
433
550
|
var rawLength = raw.length;
|
|
@@ -473,10 +590,10 @@ function initOnce(doInit) {
|
|
|
473
590
|
};
|
|
474
591
|
}
|
|
475
592
|
const init = {
|
|
476
|
-
bandersnatch: initOnce(async () => await
|
|
593
|
+
bandersnatch: initOnce(async () => await init$1({ module_or_path: await bandersnatch_wasm_bg_default() })),
|
|
477
594
|
ed25519: initOnce(async () => await ed25519_wasm_default({ module_or_path: await ed25519_wasm_bg_default() })),
|
|
478
595
|
reedSolomon: initOnce(async () => await reed_solomon_wasm_default({ module_or_path: await reed_solomon_wasm_bg_default() }))
|
|
479
596
|
};
|
|
480
597
|
|
|
481
598
|
//#endregion
|
|
482
|
-
export { bandersnatch, ed25519_wasm_exports as ed25519, init, initAll, reed_solomon_wasm_exports as reedSolomon };
|
|
599
|
+
export { src_exports as bandersnatch, ed25519_wasm_exports as ed25519, init, initAll, reed_solomon_wasm_exports as reedSolomon };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
|
|
3
|
+
//#region bandersnatch/src/native.ts
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
function loadNativeBinding() {
|
|
6
|
+
const platform = process?.platform;
|
|
7
|
+
const arch = process?.arch;
|
|
8
|
+
let nativeBinding = null;
|
|
9
|
+
let loadError = null;
|
|
10
|
+
const platformArch = platform && arch ? {
|
|
11
|
+
darwin: { arm64: "@typeberry/bandersnatch-native-darwin-arm64" },
|
|
12
|
+
linux: { x64: "@typeberry/bandersnatch-native-linux-x64-gnu" }
|
|
13
|
+
}[platform]?.[arch] : void 0;
|
|
14
|
+
if (platformArch) try {
|
|
15
|
+
nativeBinding = require(platformArch);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
loadError = e;
|
|
18
|
+
}
|
|
19
|
+
else loadError = /* @__PURE__ */ new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
20
|
+
if (!nativeBinding) throw loadError || /* @__PURE__ */ new Error("Failed to load native binding");
|
|
21
|
+
return nativeBinding;
|
|
22
|
+
}
|
|
23
|
+
const binding = loadNativeBinding();
|
|
24
|
+
const ringCommitment = binding.ringCommitment;
|
|
25
|
+
const derivePublicKey = binding.derivePublicKey;
|
|
26
|
+
const verifyHeaderSeals = binding.verifyHeaderSeals;
|
|
27
|
+
const verifySeal = binding.verifySeal;
|
|
28
|
+
const generateSeal = binding.generateSeal;
|
|
29
|
+
const vrfOutputHash = binding.vrfOutputHash;
|
|
30
|
+
const batchVerifyTickets = binding.batchVerifyTickets;
|
|
31
|
+
var native_default = binding;
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { batchVerifyTickets, native_default as default, derivePublicKey, generateSeal, ringCommitment, verifyHeaderSeals, verifySeal, vrfOutputHash };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typeberry/native",
|
|
3
|
-
"version": "0.2.0-
|
|
3
|
+
"version": "0.2.0-bd1a174",
|
|
4
4
|
"description": "Native libraries for typeberry - bundles bandersnatch, ed25519 and reed-solomon with WASM and optional native bindings",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"node": ">=18"
|
|
24
24
|
},
|
|
25
25
|
"optionalDependencies": {
|
|
26
|
-
"@typeberry/bandersnatch-native-darwin-arm64": "0.2.0-
|
|
27
|
-
"@typeberry/bandersnatch-native-linux-x64-gnu": "0.2.0-
|
|
26
|
+
"@typeberry/bandersnatch-native-darwin-arm64": "0.2.0-bd1a174",
|
|
27
|
+
"@typeberry/bandersnatch-native-linux-x64-gnu": "0.2.0-bd1a174"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"lint": "true",
|