@anycon/protocol 0.1.0
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/LICENSE +176 -0
- package/README.md +146 -0
- package/README.zh-CN.md +118 -0
- package/dist/constants.d.ts +151 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +159 -0
- package/dist/constants.js.map +1 -0
- package/dist/crypto.d.ts +202 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +218 -0
- package/dist/crypto.js.map +1 -0
- package/dist/envelope.d.ts +105 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +390 -0
- package/dist/envelope.js.map +1 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +5 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated.d.ts +2007 -0
- package/dist/generated.d.ts.map +1 -0
- package/dist/generated.js +4 -0
- package/dist/generated.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/method-types.d.ts +293 -0
- package/dist/method-types.d.ts.map +1 -0
- package/dist/method-types.js +2 -0
- package/dist/method-types.js.map +1 -0
- package/dist/rpc.d.ts +70 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +310 -0
- package/dist/rpc.js.map +1 -0
- package/package.json +62 -0
- package/src/constants.ts +173 -0
- package/src/crypto.ts +427 -0
- package/src/envelope.ts +469 -0
- package/src/errors.ts +4 -0
- package/src/generated.ts +2094 -0
- package/src/index.ts +18 -0
- package/src/method-types.ts +183 -0
- package/src/rpc.ts +377 -0
- package/wasm/THIRD-PARTY-LICENSES.txt +1957 -0
- package/wasm/anycon_crypto.d.ts +248 -0
- package/wasm/anycon_crypto.js +1250 -0
- package/wasm/anycon_crypto_bg.wasm +0 -0
- package/wasm/anycon_crypto_bg.wasm.d.ts +48 -0
|
@@ -0,0 +1,1250 @@
|
|
|
1
|
+
/* @ts-self-types="./anycon_crypto.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 一方的 CPace 状态。新设备用 `"initiator"`。`finish` 会消费本对象(之后再碰会抛 null pointer 错误)。
|
|
5
|
+
*/
|
|
6
|
+
export class WasmCpace {
|
|
7
|
+
__destroy_into_raw() {
|
|
8
|
+
const ptr = this.__wbg_ptr;
|
|
9
|
+
this.__wbg_ptr = 0;
|
|
10
|
+
WasmCpaceFinalization.unregister(this);
|
|
11
|
+
return ptr;
|
|
12
|
+
}
|
|
13
|
+
free() {
|
|
14
|
+
const ptr = this.__destroy_into_raw();
|
|
15
|
+
wasm.__wbg_wasmcpace_free(ptr, 0);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 用对方的份额得到 32 字节 PSK。份额不合法时抛 `invalid key`。
|
|
19
|
+
* @param {string} role
|
|
20
|
+
* @param {Uint8Array} peerShare
|
|
21
|
+
* @returns {Uint8Array}
|
|
22
|
+
*/
|
|
23
|
+
finish(role, peerShare) {
|
|
24
|
+
try {
|
|
25
|
+
const ptr = this.__destroy_into_raw();
|
|
26
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
27
|
+
const ptr0 = passStringToWasm0(role, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
28
|
+
const len0 = WASM_VECTOR_LEN;
|
|
29
|
+
const ptr1 = passArray8ToWasm0(peerShare, wasm.__wbindgen_export2);
|
|
30
|
+
const len1 = WASM_VECTOR_LEN;
|
|
31
|
+
wasm.wasmcpace_finish(retptr, ptr, ptr0, len0, ptr1, len1);
|
|
32
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
33
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
34
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
35
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
36
|
+
if (r3) {
|
|
37
|
+
throw takeObject(r2);
|
|
38
|
+
}
|
|
39
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
40
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
41
|
+
return v3;
|
|
42
|
+
} finally {
|
|
43
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* `prs`:口令的 `deriveEnrollPasswordPrs`,或规范化后 6 位码的 ASCII 字节;`ci`:`enrollChannelId`;`sid`:`enrollSid`。
|
|
48
|
+
* @param {Uint8Array} prs
|
|
49
|
+
* @param {Uint8Array} ci
|
|
50
|
+
* @param {Uint8Array} sid
|
|
51
|
+
*/
|
|
52
|
+
constructor(prs, ci, sid) {
|
|
53
|
+
try {
|
|
54
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
55
|
+
const ptr0 = passArray8ToWasm0(prs, wasm.__wbindgen_export2);
|
|
56
|
+
const len0 = WASM_VECTOR_LEN;
|
|
57
|
+
const ptr1 = passArray8ToWasm0(ci, wasm.__wbindgen_export2);
|
|
58
|
+
const len1 = WASM_VECTOR_LEN;
|
|
59
|
+
const ptr2 = passArray8ToWasm0(sid, wasm.__wbindgen_export2);
|
|
60
|
+
const len2 = WASM_VECTOR_LEN;
|
|
61
|
+
wasm.wasmcpace_new(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
62
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
63
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
64
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
65
|
+
if (r2) {
|
|
66
|
+
throw takeObject(r1);
|
|
67
|
+
}
|
|
68
|
+
this.__wbg_ptr = r0;
|
|
69
|
+
WasmCpaceFinalization.register(this, this.__wbg_ptr, this);
|
|
70
|
+
return this;
|
|
71
|
+
} finally {
|
|
72
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 自己的份额(32 字节),发给对方。
|
|
77
|
+
* @returns {Uint8Array}
|
|
78
|
+
*/
|
|
79
|
+
get share() {
|
|
80
|
+
try {
|
|
81
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
82
|
+
wasm.wasmcpace_share(retptr, this.__wbg_ptr);
|
|
83
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
84
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
85
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
86
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
87
|
+
return v1;
|
|
88
|
+
} finally {
|
|
89
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (Symbol.dispose) WasmCpace.prototype[Symbol.dispose] = WasmCpace.prototype.free;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 进行中的握手。
|
|
97
|
+
*/
|
|
98
|
+
export class WasmHandshake {
|
|
99
|
+
static __wrap(ptr) {
|
|
100
|
+
const obj = Object.create(WasmHandshake.prototype);
|
|
101
|
+
obj.__wbg_ptr = ptr;
|
|
102
|
+
WasmHandshakeFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
103
|
+
return obj;
|
|
104
|
+
}
|
|
105
|
+
__destroy_into_raw() {
|
|
106
|
+
const ptr = this.__wbg_ptr;
|
|
107
|
+
this.__wbg_ptr = 0;
|
|
108
|
+
WasmHandshakeFinalization.unregister(this);
|
|
109
|
+
return ptr;
|
|
110
|
+
}
|
|
111
|
+
free() {
|
|
112
|
+
const ptr = this.__destroy_into_raw();
|
|
113
|
+
wasm.__wbg_wasmhandshake_free(ptr, 0);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 握手完成后换成传输通道。会消费本对象。
|
|
117
|
+
* @returns {WasmTransport}
|
|
118
|
+
*/
|
|
119
|
+
intoTransport() {
|
|
120
|
+
try {
|
|
121
|
+
const ptr = this.__destroy_into_raw();
|
|
122
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
123
|
+
wasm.wasmhandshake_intoTransport(retptr, ptr);
|
|
124
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
125
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
126
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
127
|
+
if (r2) {
|
|
128
|
+
throw takeObject(r1);
|
|
129
|
+
}
|
|
130
|
+
return WasmTransport.__wrap(r0);
|
|
131
|
+
} finally {
|
|
132
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @returns {boolean}
|
|
137
|
+
*/
|
|
138
|
+
isFinished() {
|
|
139
|
+
const ret = wasm.wasmhandshake_isFinished(this.__wbg_ptr);
|
|
140
|
+
return ret !== 0;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @returns {boolean}
|
|
144
|
+
*/
|
|
145
|
+
isMyTurn() {
|
|
146
|
+
const ret = wasm.wasmhandshake_isMyTurn(this.__wbg_ptr);
|
|
147
|
+
return ret !== 0;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 配对握手(XXpsk3)。joiner 传 `"initiator"`,host 传 `"responder"`。
|
|
151
|
+
* @param {string} role
|
|
152
|
+
* @param {WasmKeypair} kp
|
|
153
|
+
* @param {Uint8Array} psk
|
|
154
|
+
* @returns {WasmHandshake}
|
|
155
|
+
*/
|
|
156
|
+
static pairing(role, kp, psk) {
|
|
157
|
+
try {
|
|
158
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
159
|
+
const ptr0 = passStringToWasm0(role, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
160
|
+
const len0 = WASM_VECTOR_LEN;
|
|
161
|
+
_assertClass(kp, WasmKeypair);
|
|
162
|
+
const ptr1 = passArray8ToWasm0(psk, wasm.__wbindgen_export2);
|
|
163
|
+
const len1 = WASM_VECTOR_LEN;
|
|
164
|
+
wasm.wasmhandshake_pairing(retptr, ptr0, len0, kp.__wbg_ptr, ptr1, len1);
|
|
165
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
166
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
167
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
168
|
+
if (r2) {
|
|
169
|
+
throw takeObject(r1);
|
|
170
|
+
}
|
|
171
|
+
return WasmHandshake.__wrap(r0);
|
|
172
|
+
} finally {
|
|
173
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 读对方的握手消息,返回对方带的 payload。
|
|
178
|
+
* @param {Uint8Array} message
|
|
179
|
+
* @returns {Uint8Array}
|
|
180
|
+
*/
|
|
181
|
+
read(message) {
|
|
182
|
+
try {
|
|
183
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
184
|
+
const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_export2);
|
|
185
|
+
const len0 = WASM_VECTOR_LEN;
|
|
186
|
+
wasm.wasmhandshake_read(retptr, this.__wbg_ptr, ptr0, len0);
|
|
187
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
188
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
189
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
190
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
191
|
+
if (r3) {
|
|
192
|
+
throw takeObject(r2);
|
|
193
|
+
}
|
|
194
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
195
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
196
|
+
return v2;
|
|
197
|
+
} finally {
|
|
198
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 重连握手(IK)。initiator 必须传 `remotePublic`;responder 不传(或传期望的 initiator 公钥做钉扎)。
|
|
203
|
+
* @param {string} role
|
|
204
|
+
* @param {WasmKeypair} kp
|
|
205
|
+
* @param {Uint8Array | null} [remotePublic]
|
|
206
|
+
* @returns {WasmHandshake}
|
|
207
|
+
*/
|
|
208
|
+
static reconnect(role, kp, remotePublic) {
|
|
209
|
+
try {
|
|
210
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
211
|
+
const ptr0 = passStringToWasm0(role, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
212
|
+
const len0 = WASM_VECTOR_LEN;
|
|
213
|
+
_assertClass(kp, WasmKeypair);
|
|
214
|
+
var ptr1 = isLikeNone(remotePublic) ? 0 : passArray8ToWasm0(remotePublic, wasm.__wbindgen_export2);
|
|
215
|
+
var len1 = WASM_VECTOR_LEN;
|
|
216
|
+
wasm.wasmhandshake_reconnect(retptr, ptr0, len0, kp.__wbg_ptr, ptr1, len1);
|
|
217
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
218
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
219
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
220
|
+
if (r2) {
|
|
221
|
+
throw takeObject(r1);
|
|
222
|
+
}
|
|
223
|
+
return WasmHandshake.__wrap(r0);
|
|
224
|
+
} finally {
|
|
225
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* 对方静态公钥;还不知道时是 `undefined`。
|
|
230
|
+
* @returns {Uint8Array | undefined}
|
|
231
|
+
*/
|
|
232
|
+
remotePublic() {
|
|
233
|
+
try {
|
|
234
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
235
|
+
wasm.wasmhandshake_remotePublic(retptr, this.__wbg_ptr);
|
|
236
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
237
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
238
|
+
let v1;
|
|
239
|
+
if (r0 !== 0) {
|
|
240
|
+
v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
241
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
242
|
+
}
|
|
243
|
+
return v1;
|
|
244
|
+
} finally {
|
|
245
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 写下一条握手消息,返回要发给对方的字节。
|
|
250
|
+
* @param {Uint8Array} payload
|
|
251
|
+
* @returns {Uint8Array}
|
|
252
|
+
*/
|
|
253
|
+
write(payload) {
|
|
254
|
+
try {
|
|
255
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
256
|
+
const ptr0 = passArray8ToWasm0(payload, wasm.__wbindgen_export2);
|
|
257
|
+
const len0 = WASM_VECTOR_LEN;
|
|
258
|
+
wasm.wasmhandshake_write(retptr, this.__wbg_ptr, ptr0, len0);
|
|
259
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
260
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
261
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
262
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
263
|
+
if (r3) {
|
|
264
|
+
throw takeObject(r2);
|
|
265
|
+
}
|
|
266
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
267
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
268
|
+
return v2;
|
|
269
|
+
} finally {
|
|
270
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (Symbol.dispose) WasmHandshake.prototype[Symbol.dispose] = WasmHandshake.prototype.free;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* X25519 静态密钥对。
|
|
278
|
+
*/
|
|
279
|
+
export class WasmKeypair {
|
|
280
|
+
static __wrap(ptr) {
|
|
281
|
+
const obj = Object.create(WasmKeypair.prototype);
|
|
282
|
+
obj.__wbg_ptr = ptr;
|
|
283
|
+
WasmKeypairFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
284
|
+
return obj;
|
|
285
|
+
}
|
|
286
|
+
__destroy_into_raw() {
|
|
287
|
+
const ptr = this.__wbg_ptr;
|
|
288
|
+
this.__wbg_ptr = 0;
|
|
289
|
+
WasmKeypairFinalization.unregister(this);
|
|
290
|
+
return ptr;
|
|
291
|
+
}
|
|
292
|
+
free() {
|
|
293
|
+
const ptr = this.__destroy_into_raw();
|
|
294
|
+
wasm.__wbg_wasmkeypair_free(ptr, 0);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* 由 32 字节私钥还原。
|
|
298
|
+
* @param {Uint8Array} secret
|
|
299
|
+
* @returns {WasmKeypair}
|
|
300
|
+
*/
|
|
301
|
+
static fromSecret(secret) {
|
|
302
|
+
try {
|
|
303
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
304
|
+
const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_export2);
|
|
305
|
+
const len0 = WASM_VECTOR_LEN;
|
|
306
|
+
wasm.wasmkeypair_fromSecret(retptr, ptr0, len0);
|
|
307
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
308
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
309
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
310
|
+
if (r2) {
|
|
311
|
+
throw takeObject(r1);
|
|
312
|
+
}
|
|
313
|
+
return WasmKeypair.__wrap(r0);
|
|
314
|
+
} finally {
|
|
315
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* 用 `crypto.getRandomValues` 生成新密钥对。
|
|
320
|
+
* @returns {WasmKeypair}
|
|
321
|
+
*/
|
|
322
|
+
static generate() {
|
|
323
|
+
const ret = wasm.wasmkeypair_generate();
|
|
324
|
+
return WasmKeypair.__wrap(ret);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* @returns {Uint8Array}
|
|
328
|
+
*/
|
|
329
|
+
get public() {
|
|
330
|
+
try {
|
|
331
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
332
|
+
wasm.wasmkeypair_public(retptr, this.__wbg_ptr);
|
|
333
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
334
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
335
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
336
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
337
|
+
return v1;
|
|
338
|
+
} finally {
|
|
339
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* @returns {Uint8Array}
|
|
344
|
+
*/
|
|
345
|
+
get secret() {
|
|
346
|
+
try {
|
|
347
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
348
|
+
wasm.wasmkeypair_secret(retptr, this.__wbg_ptr);
|
|
349
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
350
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
351
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
352
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
353
|
+
return v1;
|
|
354
|
+
} finally {
|
|
355
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (Symbol.dispose) WasmKeypair.prototype[Symbol.dispose] = WasmKeypair.prototype.free;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* 一次 Argon2id 得到的 `matchId` + `psk`。用完 `.free()`(PSK 会被清零)。
|
|
363
|
+
*/
|
|
364
|
+
export class WasmPairSecrets {
|
|
365
|
+
static __wrap(ptr) {
|
|
366
|
+
const obj = Object.create(WasmPairSecrets.prototype);
|
|
367
|
+
obj.__wbg_ptr = ptr;
|
|
368
|
+
WasmPairSecretsFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
369
|
+
return obj;
|
|
370
|
+
}
|
|
371
|
+
__destroy_into_raw() {
|
|
372
|
+
const ptr = this.__wbg_ptr;
|
|
373
|
+
this.__wbg_ptr = 0;
|
|
374
|
+
WasmPairSecretsFinalization.unregister(this);
|
|
375
|
+
return ptr;
|
|
376
|
+
}
|
|
377
|
+
free() {
|
|
378
|
+
const ptr = this.__destroy_into_raw();
|
|
379
|
+
wasm.__wbg_wasmpairsecrets_free(ptr, 0);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* @returns {string}
|
|
383
|
+
*/
|
|
384
|
+
get matchId() {
|
|
385
|
+
let deferred1_0;
|
|
386
|
+
let deferred1_1;
|
|
387
|
+
try {
|
|
388
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
389
|
+
wasm.wasmpairsecrets_matchId(retptr, this.__wbg_ptr);
|
|
390
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
391
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
392
|
+
deferred1_0 = r0;
|
|
393
|
+
deferred1_1 = r1;
|
|
394
|
+
return getStringFromWasm0(r0, r1);
|
|
395
|
+
} finally {
|
|
396
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
397
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* 32 字节 PSK 的拷贝,调用方用完 `fill(0)`。
|
|
402
|
+
* @returns {Uint8Array}
|
|
403
|
+
*/
|
|
404
|
+
get psk() {
|
|
405
|
+
try {
|
|
406
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
407
|
+
wasm.wasmpairsecrets_psk(retptr, this.__wbg_ptr);
|
|
408
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
409
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
410
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
411
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
412
|
+
return v1;
|
|
413
|
+
} finally {
|
|
414
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (Symbol.dispose) WasmPairSecrets.prototype[Symbol.dispose] = WasmPairSecrets.prototype.free;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 握手完成后的双向加密通道。
|
|
422
|
+
*/
|
|
423
|
+
export class WasmTransport {
|
|
424
|
+
static __wrap(ptr) {
|
|
425
|
+
const obj = Object.create(WasmTransport.prototype);
|
|
426
|
+
obj.__wbg_ptr = ptr;
|
|
427
|
+
WasmTransportFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
428
|
+
return obj;
|
|
429
|
+
}
|
|
430
|
+
__destroy_into_raw() {
|
|
431
|
+
const ptr = this.__wbg_ptr;
|
|
432
|
+
this.__wbg_ptr = 0;
|
|
433
|
+
WasmTransportFinalization.unregister(this);
|
|
434
|
+
return ptr;
|
|
435
|
+
}
|
|
436
|
+
free() {
|
|
437
|
+
const ptr = this.__destroy_into_raw();
|
|
438
|
+
wasm.__wbg_wasmtransport_free(ptr, 0);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* @param {Uint8Array} ciphertext
|
|
442
|
+
* @returns {Uint8Array}
|
|
443
|
+
*/
|
|
444
|
+
decrypt(ciphertext) {
|
|
445
|
+
try {
|
|
446
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
447
|
+
const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_export2);
|
|
448
|
+
const len0 = WASM_VECTOR_LEN;
|
|
449
|
+
wasm.wasmtransport_decrypt(retptr, this.__wbg_ptr, ptr0, len0);
|
|
450
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
451
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
452
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
453
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
454
|
+
if (r3) {
|
|
455
|
+
throw takeObject(r2);
|
|
456
|
+
}
|
|
457
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
458
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
459
|
+
return v2;
|
|
460
|
+
} finally {
|
|
461
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* 加密任意长度明文;超过 65519 字节自动分片(`[u16 be 长度][密文]` 拼接)。
|
|
466
|
+
* @param {Uint8Array} plaintext
|
|
467
|
+
* @returns {Uint8Array}
|
|
468
|
+
*/
|
|
469
|
+
encrypt(plaintext) {
|
|
470
|
+
try {
|
|
471
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
472
|
+
const ptr0 = passArray8ToWasm0(plaintext, wasm.__wbindgen_export2);
|
|
473
|
+
const len0 = WASM_VECTOR_LEN;
|
|
474
|
+
wasm.wasmtransport_encrypt(retptr, this.__wbg_ptr, ptr0, len0);
|
|
475
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
476
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
477
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
478
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
479
|
+
if (r3) {
|
|
480
|
+
throw takeObject(r2);
|
|
481
|
+
}
|
|
482
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
483
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
484
|
+
return v2;
|
|
485
|
+
} finally {
|
|
486
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* @returns {Uint8Array}
|
|
491
|
+
*/
|
|
492
|
+
remotePublic() {
|
|
493
|
+
try {
|
|
494
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
495
|
+
wasm.wasmtransport_remotePublic(retptr, this.__wbg_ptr);
|
|
496
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
497
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
498
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
499
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
500
|
+
return v1;
|
|
501
|
+
} finally {
|
|
502
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (Symbol.dispose) WasmTransport.prototype[Symbol.dispose] = WasmTransport.prototype.free;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* 节点口令 → CPace 的口令输入:`Argon2id(NFC(口令), salt)`,浏览器里约 0.5–1 s。`salt` 必须是 16 字节。
|
|
510
|
+
* @param {string} password
|
|
511
|
+
* @param {Uint8Array} salt
|
|
512
|
+
* @returns {Uint8Array}
|
|
513
|
+
*/
|
|
514
|
+
export function deriveEnrollPasswordPrs(password, salt) {
|
|
515
|
+
try {
|
|
516
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
517
|
+
const ptr0 = passStringToWasm0(password, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
518
|
+
const len0 = WASM_VECTOR_LEN;
|
|
519
|
+
const ptr1 = passArray8ToWasm0(salt, wasm.__wbindgen_export2);
|
|
520
|
+
const len1 = WASM_VECTOR_LEN;
|
|
521
|
+
wasm.deriveEnrollPasswordPrs(retptr, ptr0, len0, ptr1, len1);
|
|
522
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
523
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
524
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
525
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
526
|
+
if (r3) {
|
|
527
|
+
throw takeObject(r2);
|
|
528
|
+
}
|
|
529
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
530
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
531
|
+
return v3;
|
|
532
|
+
} finally {
|
|
533
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* 扫码接入的 PSK。`secret` 必须是 32 字节。
|
|
539
|
+
* @param {Uint8Array} secret
|
|
540
|
+
* @param {string} nodeId
|
|
541
|
+
* @returns {Uint8Array}
|
|
542
|
+
*/
|
|
543
|
+
export function deriveEnrollScanPsk(secret, nodeId) {
|
|
544
|
+
try {
|
|
545
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
546
|
+
const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_export2);
|
|
547
|
+
const len0 = WASM_VECTOR_LEN;
|
|
548
|
+
const ptr1 = passStringToWasm0(nodeId, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
549
|
+
const len1 = WASM_VECTOR_LEN;
|
|
550
|
+
wasm.deriveEnrollScanPsk(retptr, ptr0, len0, ptr1, len1);
|
|
551
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
552
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
553
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
554
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
555
|
+
if (r3) {
|
|
556
|
+
throw takeObject(r2);
|
|
557
|
+
}
|
|
558
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
559
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
560
|
+
return v3;
|
|
561
|
+
} finally {
|
|
562
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* 短码 → hub 撮合用的 match id(一次完整 KDF)。
|
|
568
|
+
* @param {string} code
|
|
569
|
+
* @returns {string}
|
|
570
|
+
*/
|
|
571
|
+
export function deriveMatchId(code) {
|
|
572
|
+
let deferred3_0;
|
|
573
|
+
let deferred3_1;
|
|
574
|
+
try {
|
|
575
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
576
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
577
|
+
const len0 = WASM_VECTOR_LEN;
|
|
578
|
+
wasm.deriveMatchId(retptr, ptr0, len0);
|
|
579
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
580
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
581
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
582
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
583
|
+
var ptr2 = r0;
|
|
584
|
+
var len2 = r1;
|
|
585
|
+
if (r3) {
|
|
586
|
+
ptr2 = 0; len2 = 0;
|
|
587
|
+
throw takeObject(r2);
|
|
588
|
+
}
|
|
589
|
+
deferred3_0 = ptr2;
|
|
590
|
+
deferred3_1 = len2;
|
|
591
|
+
return getStringFromWasm0(ptr2, len2);
|
|
592
|
+
} finally {
|
|
593
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
594
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* 短码 → `{ matchId, psk }`,一次 KDF(Argon2id,64 MiB × 3 轮,浏览器里约 0.5–1 s)。
|
|
600
|
+
* 配对时用它,不要分别调 `deriveMatchId` 和 `derivePsk`(会算两次)。短码无效时抛 `invalid pair code`。
|
|
601
|
+
* @param {string} code
|
|
602
|
+
* @returns {WasmPairSecrets}
|
|
603
|
+
*/
|
|
604
|
+
export function derivePairSecrets(code) {
|
|
605
|
+
try {
|
|
606
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
607
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
608
|
+
const len0 = WASM_VECTOR_LEN;
|
|
609
|
+
wasm.derivePairSecrets(retptr, ptr0, len0);
|
|
610
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
611
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
612
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
613
|
+
if (r2) {
|
|
614
|
+
throw takeObject(r1);
|
|
615
|
+
}
|
|
616
|
+
return WasmPairSecrets.__wrap(r0);
|
|
617
|
+
} finally {
|
|
618
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* 短码 → 32 字节 PSK(一次完整 KDF)。短码无效时抛 `invalid pair code`。
|
|
624
|
+
* @param {string} code
|
|
625
|
+
* @returns {Uint8Array}
|
|
626
|
+
*/
|
|
627
|
+
export function derivePsk(code) {
|
|
628
|
+
try {
|
|
629
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
630
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
631
|
+
const len0 = WASM_VECTOR_LEN;
|
|
632
|
+
wasm.derivePsk(retptr, ptr0, len0);
|
|
633
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
634
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
635
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
636
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
637
|
+
if (r3) {
|
|
638
|
+
throw takeObject(r2);
|
|
639
|
+
}
|
|
640
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
641
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
642
|
+
return v2;
|
|
643
|
+
} finally {
|
|
644
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* CPace 信道标识。`method` 是 `"code"` 或 `"password"`。
|
|
650
|
+
* @param {string} nodeId
|
|
651
|
+
* @param {string} method
|
|
652
|
+
* @returns {Uint8Array}
|
|
653
|
+
*/
|
|
654
|
+
export function enrollChannelId(nodeId, method) {
|
|
655
|
+
try {
|
|
656
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
657
|
+
const ptr0 = passStringToWasm0(nodeId, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
658
|
+
const len0 = WASM_VECTOR_LEN;
|
|
659
|
+
const ptr1 = passStringToWasm0(method, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
660
|
+
const len1 = WASM_VECTOR_LEN;
|
|
661
|
+
wasm.enrollChannelId(retptr, ptr0, len0, ptr1, len1);
|
|
662
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
663
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
664
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
665
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
666
|
+
return v3;
|
|
667
|
+
} finally {
|
|
668
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* CPace 会话标识:新设备的 nonce ‖ daemon 的 nonce。
|
|
674
|
+
* @param {Uint8Array} initiatorNonce
|
|
675
|
+
* @param {Uint8Array} responderNonce
|
|
676
|
+
* @returns {Uint8Array}
|
|
677
|
+
*/
|
|
678
|
+
export function enrollSid(initiatorNonce, responderNonce) {
|
|
679
|
+
try {
|
|
680
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
681
|
+
const ptr0 = passArray8ToWasm0(initiatorNonce, wasm.__wbindgen_export2);
|
|
682
|
+
const len0 = WASM_VECTOR_LEN;
|
|
683
|
+
const ptr1 = passArray8ToWasm0(responderNonce, wasm.__wbindgen_export2);
|
|
684
|
+
const len1 = WASM_VECTOR_LEN;
|
|
685
|
+
wasm.enrollSid(retptr, ptr0, len0, ptr1, len1);
|
|
686
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
687
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
688
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
689
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
690
|
+
return v3;
|
|
691
|
+
} finally {
|
|
692
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* 公钥指纹,如 `3f:a2:…`(8 字节)。公钥必须是 32 字节。
|
|
698
|
+
* @param {Uint8Array} _public
|
|
699
|
+
* @returns {string}
|
|
700
|
+
*/
|
|
701
|
+
export function fingerprint(_public) {
|
|
702
|
+
let deferred3_0;
|
|
703
|
+
let deferred3_1;
|
|
704
|
+
try {
|
|
705
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
706
|
+
const ptr0 = passArray8ToWasm0(_public, wasm.__wbindgen_export2);
|
|
707
|
+
const len0 = WASM_VECTOR_LEN;
|
|
708
|
+
wasm.fingerprint(retptr, ptr0, len0);
|
|
709
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
710
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
711
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
712
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
713
|
+
var ptr2 = r0;
|
|
714
|
+
var len2 = r1;
|
|
715
|
+
if (r3) {
|
|
716
|
+
ptr2 = 0; len2 = 0;
|
|
717
|
+
throw takeObject(r2);
|
|
718
|
+
}
|
|
719
|
+
deferred3_0 = ptr2;
|
|
720
|
+
deferred3_1 = len2;
|
|
721
|
+
return getStringFromWasm0(ptr2, len2);
|
|
722
|
+
} finally {
|
|
723
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
724
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* 16 字节随机数(`EnrollHello.nonce`)。
|
|
730
|
+
* @returns {Uint8Array}
|
|
731
|
+
*/
|
|
732
|
+
export function generateEnrollNonce() {
|
|
733
|
+
try {
|
|
734
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
735
|
+
wasm.generateEnrollNonce(retptr);
|
|
736
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
737
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
738
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
739
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
740
|
+
return v1;
|
|
741
|
+
} finally {
|
|
742
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* 32 字节扫码密钥(放进二维码)。
|
|
748
|
+
* @returns {Uint8Array}
|
|
749
|
+
*/
|
|
750
|
+
export function generateEnrollSecret() {
|
|
751
|
+
try {
|
|
752
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
753
|
+
wasm.generateEnrollSecret(retptr);
|
|
754
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
755
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
756
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
757
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
758
|
+
return v1;
|
|
759
|
+
} finally {
|
|
760
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* 生成 `XXXX-XXXX` 形式的 8 位短码。
|
|
766
|
+
* @returns {string}
|
|
767
|
+
*/
|
|
768
|
+
export function generatePairCode() {
|
|
769
|
+
let deferred1_0;
|
|
770
|
+
let deferred1_1;
|
|
771
|
+
try {
|
|
772
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
773
|
+
wasm.generatePairCode(retptr);
|
|
774
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
775
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
776
|
+
deferred1_0 = r0;
|
|
777
|
+
deferred1_1 = r1;
|
|
778
|
+
return getStringFromWasm0(r0, r1);
|
|
779
|
+
} finally {
|
|
780
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
781
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* @returns {string}
|
|
787
|
+
*/
|
|
788
|
+
export function generatePairCodeLong() {
|
|
789
|
+
let deferred1_0;
|
|
790
|
+
let deferred1_1;
|
|
791
|
+
try {
|
|
792
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
793
|
+
wasm.generatePairCodeLong(retptr);
|
|
794
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
795
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
796
|
+
deferred1_0 = r0;
|
|
797
|
+
deferred1_1 = r1;
|
|
798
|
+
return getStringFromWasm0(r0, r1);
|
|
799
|
+
} finally {
|
|
800
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
801
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* @param {string} code
|
|
807
|
+
* @returns {string}
|
|
808
|
+
*/
|
|
809
|
+
export function normalizeCode(code) {
|
|
810
|
+
let deferred2_0;
|
|
811
|
+
let deferred2_1;
|
|
812
|
+
try {
|
|
813
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
814
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
815
|
+
const len0 = WASM_VECTOR_LEN;
|
|
816
|
+
wasm.normalizeCode(retptr, ptr0, len0);
|
|
817
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
818
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
819
|
+
deferred2_0 = r0;
|
|
820
|
+
deferred2_1 = r1;
|
|
821
|
+
return getStringFromWasm0(r0, r1);
|
|
822
|
+
} finally {
|
|
823
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
824
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* 接入码规范化:去掉空白和 `-`,必须是 6 个数字,否则抛 `invalid pair code`。
|
|
830
|
+
* @param {string} code
|
|
831
|
+
* @returns {string}
|
|
832
|
+
*/
|
|
833
|
+
export function normalizeEnrollCode(code) {
|
|
834
|
+
let deferred3_0;
|
|
835
|
+
let deferred3_1;
|
|
836
|
+
try {
|
|
837
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
838
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
839
|
+
const len0 = WASM_VECTOR_LEN;
|
|
840
|
+
wasm.normalizeEnrollCode(retptr, ptr0, len0);
|
|
841
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
842
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
843
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
844
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
845
|
+
var ptr2 = r0;
|
|
846
|
+
var len2 = r1;
|
|
847
|
+
if (r3) {
|
|
848
|
+
ptr2 = 0; len2 = 0;
|
|
849
|
+
throw takeObject(r2);
|
|
850
|
+
}
|
|
851
|
+
deferred3_0 = ptr2;
|
|
852
|
+
deferred3_1 = len2;
|
|
853
|
+
return getStringFromWasm0(ptr2, len2);
|
|
854
|
+
} finally {
|
|
855
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
856
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* 节点口令校验(设置时用):NFC 之后至少 8 个字符,否则抛 `enroll password too short`。
|
|
862
|
+
* @param {string} password
|
|
863
|
+
*/
|
|
864
|
+
export function validateEnrollPassword(password) {
|
|
865
|
+
try {
|
|
866
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
867
|
+
const ptr0 = passStringToWasm0(password, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
868
|
+
const len0 = WASM_VECTOR_LEN;
|
|
869
|
+
wasm.validateEnrollPassword(retptr, ptr0, len0);
|
|
870
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
871
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
872
|
+
if (r1) {
|
|
873
|
+
throw takeObject(r0);
|
|
874
|
+
}
|
|
875
|
+
} finally {
|
|
876
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
function __wbg_get_imports() {
|
|
880
|
+
const import0 = {
|
|
881
|
+
__proto__: null,
|
|
882
|
+
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
|
|
883
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
884
|
+
return addHeapObject(ret);
|
|
885
|
+
},
|
|
886
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
887
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
888
|
+
return ret;
|
|
889
|
+
},
|
|
890
|
+
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
|
|
891
|
+
const val = getObject(arg0);
|
|
892
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
893
|
+
return ret;
|
|
894
|
+
},
|
|
895
|
+
__wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
|
|
896
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
897
|
+
return ret;
|
|
898
|
+
},
|
|
899
|
+
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
900
|
+
const ret = getObject(arg0) === undefined;
|
|
901
|
+
return ret;
|
|
902
|
+
},
|
|
903
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
904
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
905
|
+
},
|
|
906
|
+
__wbg_call_187d372bd5fdd4aa: function() { return handleError(function (arg0, arg1, arg2) {
|
|
907
|
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
|
908
|
+
return addHeapObject(ret);
|
|
909
|
+
}, arguments); },
|
|
910
|
+
__wbg_crypto_38df2bab126b63dc: function(arg0) {
|
|
911
|
+
const ret = getObject(arg0).crypto;
|
|
912
|
+
return addHeapObject(ret);
|
|
913
|
+
},
|
|
914
|
+
__wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
|
|
915
|
+
getObject(arg0).getRandomValues(getObject(arg1));
|
|
916
|
+
}, arguments); },
|
|
917
|
+
__wbg_length_7f3c00c40364105e: function(arg0) {
|
|
918
|
+
const ret = getObject(arg0).length;
|
|
919
|
+
return ret;
|
|
920
|
+
},
|
|
921
|
+
__wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
|
|
922
|
+
const ret = getObject(arg0).msCrypto;
|
|
923
|
+
return addHeapObject(ret);
|
|
924
|
+
},
|
|
925
|
+
__wbg_new_with_length_3da0ad195f6f63ba: function(arg0) {
|
|
926
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
927
|
+
return addHeapObject(ret);
|
|
928
|
+
},
|
|
929
|
+
__wbg_node_84ea875411254db1: function(arg0) {
|
|
930
|
+
const ret = getObject(arg0).node;
|
|
931
|
+
return addHeapObject(ret);
|
|
932
|
+
},
|
|
933
|
+
__wbg_process_44c7a14e11e9f69e: function(arg0) {
|
|
934
|
+
const ret = getObject(arg0).process;
|
|
935
|
+
return addHeapObject(ret);
|
|
936
|
+
},
|
|
937
|
+
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
938
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
939
|
+
},
|
|
940
|
+
__wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
|
|
941
|
+
getObject(arg0).randomFillSync(takeObject(arg1));
|
|
942
|
+
}, arguments); },
|
|
943
|
+
__wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
|
|
944
|
+
const ret = module.require;
|
|
945
|
+
return addHeapObject(ret);
|
|
946
|
+
}, arguments); },
|
|
947
|
+
__wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
|
|
948
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
949
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
950
|
+
},
|
|
951
|
+
__wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
|
|
952
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
953
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
954
|
+
},
|
|
955
|
+
__wbg_static_accessor_SELF_0b583911f537483a: function() {
|
|
956
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
957
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
958
|
+
},
|
|
959
|
+
__wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
|
|
960
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
961
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
962
|
+
},
|
|
963
|
+
__wbg_subarray_002b94d5e13d1411: function(arg0, arg1, arg2) {
|
|
964
|
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
|
965
|
+
return addHeapObject(ret);
|
|
966
|
+
},
|
|
967
|
+
__wbg_versions_276b2795b1c6a219: function(arg0) {
|
|
968
|
+
const ret = getObject(arg0).versions;
|
|
969
|
+
return addHeapObject(ret);
|
|
970
|
+
},
|
|
971
|
+
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
972
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
973
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
974
|
+
return addHeapObject(ret);
|
|
975
|
+
},
|
|
976
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
977
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
978
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
979
|
+
return addHeapObject(ret);
|
|
980
|
+
},
|
|
981
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
982
|
+
const ret = getObject(arg0);
|
|
983
|
+
return addHeapObject(ret);
|
|
984
|
+
},
|
|
985
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
986
|
+
takeObject(arg0);
|
|
987
|
+
},
|
|
988
|
+
};
|
|
989
|
+
return {
|
|
990
|
+
__proto__: null,
|
|
991
|
+
"./anycon_crypto_bg.js": import0,
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
const WasmCpaceFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
996
|
+
? { register: () => {}, unregister: () => {} }
|
|
997
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmcpace_free(ptr, 1));
|
|
998
|
+
const WasmHandshakeFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
999
|
+
? { register: () => {}, unregister: () => {} }
|
|
1000
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmhandshake_free(ptr, 1));
|
|
1001
|
+
const WasmKeypairFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1002
|
+
? { register: () => {}, unregister: () => {} }
|
|
1003
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmkeypair_free(ptr, 1));
|
|
1004
|
+
const WasmPairSecretsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1005
|
+
? { register: () => {}, unregister: () => {} }
|
|
1006
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmpairsecrets_free(ptr, 1));
|
|
1007
|
+
const WasmTransportFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1008
|
+
? { register: () => {}, unregister: () => {} }
|
|
1009
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmtransport_free(ptr, 1));
|
|
1010
|
+
|
|
1011
|
+
function addHeapObject(obj) {
|
|
1012
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
1013
|
+
const idx = heap_next;
|
|
1014
|
+
heap_next = heap[idx];
|
|
1015
|
+
|
|
1016
|
+
heap[idx] = obj;
|
|
1017
|
+
return idx;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
function _assertClass(instance, klass) {
|
|
1021
|
+
if (!(instance instanceof klass)) {
|
|
1022
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
function dropObject(idx) {
|
|
1027
|
+
if (idx < 1028) return;
|
|
1028
|
+
heap[idx] = heap_next;
|
|
1029
|
+
heap_next = idx;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
1033
|
+
ptr = ptr >>> 0;
|
|
1034
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
let cachedDataViewMemory0 = null;
|
|
1038
|
+
function getDataViewMemory0() {
|
|
1039
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
1040
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
1041
|
+
}
|
|
1042
|
+
return cachedDataViewMemory0;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function getStringFromWasm0(ptr, len) {
|
|
1046
|
+
return decodeText(ptr >>> 0, len);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
let cachedUint8ArrayMemory0 = null;
|
|
1050
|
+
function getUint8ArrayMemory0() {
|
|
1051
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
1052
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
1053
|
+
}
|
|
1054
|
+
return cachedUint8ArrayMemory0;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function getObject(idx) { return heap[idx]; }
|
|
1058
|
+
|
|
1059
|
+
function handleError(f, args) {
|
|
1060
|
+
try {
|
|
1061
|
+
return f.apply(this, args);
|
|
1062
|
+
} catch (e) {
|
|
1063
|
+
wasm.__wbindgen_export(addHeapObject(e));
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
let heap = new Array(1024).fill(undefined);
|
|
1068
|
+
heap.push(undefined, null, true, false);
|
|
1069
|
+
|
|
1070
|
+
let heap_next = heap.length;
|
|
1071
|
+
|
|
1072
|
+
function isLikeNone(x) {
|
|
1073
|
+
return x === undefined || x === null;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
1077
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
1078
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
1079
|
+
WASM_VECTOR_LEN = arg.length;
|
|
1080
|
+
return ptr;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
1084
|
+
if (realloc === undefined) {
|
|
1085
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
1086
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
1087
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
1088
|
+
WASM_VECTOR_LEN = buf.length;
|
|
1089
|
+
return ptr;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
let len = arg.length;
|
|
1093
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
1094
|
+
|
|
1095
|
+
const mem = getUint8ArrayMemory0();
|
|
1096
|
+
|
|
1097
|
+
let offset = 0;
|
|
1098
|
+
|
|
1099
|
+
for (; offset < len; offset++) {
|
|
1100
|
+
const code = arg.charCodeAt(offset);
|
|
1101
|
+
if (code > 0x7F) break;
|
|
1102
|
+
mem[ptr + offset] = code;
|
|
1103
|
+
}
|
|
1104
|
+
if (offset !== len) {
|
|
1105
|
+
if (offset !== 0) {
|
|
1106
|
+
arg = arg.slice(offset);
|
|
1107
|
+
}
|
|
1108
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
1109
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
1110
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
1111
|
+
|
|
1112
|
+
offset += ret.written;
|
|
1113
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
WASM_VECTOR_LEN = offset;
|
|
1117
|
+
return ptr;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
function takeObject(idx) {
|
|
1121
|
+
const ret = getObject(idx);
|
|
1122
|
+
dropObject(idx);
|
|
1123
|
+
return ret;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1127
|
+
cachedTextDecoder.decode();
|
|
1128
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
1129
|
+
let numBytesDecoded = 0;
|
|
1130
|
+
function decodeText(ptr, len) {
|
|
1131
|
+
numBytesDecoded += len;
|
|
1132
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
1133
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1134
|
+
cachedTextDecoder.decode();
|
|
1135
|
+
numBytesDecoded = len;
|
|
1136
|
+
}
|
|
1137
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
const cachedTextEncoder = new TextEncoder();
|
|
1141
|
+
|
|
1142
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
1143
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
1144
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
1145
|
+
view.set(buf);
|
|
1146
|
+
return {
|
|
1147
|
+
read: arg.length,
|
|
1148
|
+
written: buf.length
|
|
1149
|
+
};
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
let WASM_VECTOR_LEN = 0;
|
|
1154
|
+
|
|
1155
|
+
let wasmModule, wasmInstance, wasm;
|
|
1156
|
+
function __wbg_finalize_init(instance, module) {
|
|
1157
|
+
wasmInstance = instance;
|
|
1158
|
+
wasm = instance.exports;
|
|
1159
|
+
wasmModule = module;
|
|
1160
|
+
cachedDataViewMemory0 = null;
|
|
1161
|
+
cachedUint8ArrayMemory0 = null;
|
|
1162
|
+
return wasm;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
async function __wbg_load(module, imports) {
|
|
1166
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
1167
|
+
if (!module.ok) {
|
|
1168
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
1172
|
+
try {
|
|
1173
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
1174
|
+
} catch (e) {
|
|
1175
|
+
const validResponse = expectedResponseType(module.type);
|
|
1176
|
+
|
|
1177
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
1178
|
+
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);
|
|
1179
|
+
|
|
1180
|
+
} else { throw e; }
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
const bytes = await module.arrayBuffer();
|
|
1185
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
1186
|
+
} else {
|
|
1187
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
1188
|
+
|
|
1189
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
1190
|
+
return { instance, module };
|
|
1191
|
+
} else {
|
|
1192
|
+
return instance;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
function expectedResponseType(type) {
|
|
1197
|
+
switch (type) {
|
|
1198
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
1199
|
+
}
|
|
1200
|
+
return false;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
function initSync(module) {
|
|
1205
|
+
if (wasm !== undefined) return wasm;
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
if (module !== undefined) {
|
|
1209
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
1210
|
+
({module} = module)
|
|
1211
|
+
} else {
|
|
1212
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
const imports = __wbg_get_imports();
|
|
1217
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
1218
|
+
module = new WebAssembly.Module(module);
|
|
1219
|
+
}
|
|
1220
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
1221
|
+
return __wbg_finalize_init(instance, module);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
async function __wbg_init(module_or_path) {
|
|
1225
|
+
if (wasm !== undefined) return wasm;
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
if (module_or_path !== undefined) {
|
|
1229
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
1230
|
+
({module_or_path} = module_or_path)
|
|
1231
|
+
} else {
|
|
1232
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
if (module_or_path === undefined) {
|
|
1237
|
+
module_or_path = new URL('anycon_crypto_bg.wasm', import.meta.url);
|
|
1238
|
+
}
|
|
1239
|
+
const imports = __wbg_get_imports();
|
|
1240
|
+
|
|
1241
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
1242
|
+
module_or_path = fetch(module_or_path);
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
1246
|
+
|
|
1247
|
+
return __wbg_finalize_init(instance, module);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
export { initSync, __wbg_init as default };
|