@dynamic-labs-wallet/aleo 0.0.0 → 0.0.331
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/index.cjs.d.ts +1 -0
- package/index.cjs.js +3339 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +3316 -0
- package/package.json +34 -1
- package/src/client/client.d.ts +359 -0
- package/src/client/client.d.ts.map +1 -0
- package/src/client/constants.d.ts +20 -0
- package/src/client/constants.d.ts.map +1 -0
- package/src/client/feemasterClient.d.ts +58 -0
- package/src/client/feemasterClient.d.ts.map +1 -0
- package/src/client/index.d.ts +2 -0
- package/src/client/index.d.ts.map +1 -0
- package/src/client/redcoastRecordScanner.d.ts +85 -0
- package/src/client/redcoastRecordScanner.d.ts.map +1 -0
- package/src/client/walletStateStorage.d.ts +85 -0
- package/src/client/walletStateStorage.d.ts.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.d.ts.map +1 -0
package/index.cjs.js
ADDED
|
@@ -0,0 +1,3339 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var browser = require('@dynamic-labs-wallet/browser');
|
|
4
|
+
var AleoSdkMainnet = require('@provablehq/sdk/mainnet.js');
|
|
5
|
+
var AleoSdkTestnet = require('@provablehq/sdk/testnet.js');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var AleoSdkMainnet__namespace = /*#__PURE__*/_interopNamespaceDefault(AleoSdkMainnet);
|
|
25
|
+
var AleoSdkTestnet__namespace = /*#__PURE__*/_interopNamespaceDefault(AleoSdkTestnet);
|
|
26
|
+
|
|
27
|
+
var ERROR_KEYGEN_FAILED = 'Error with Aleo keygen';
|
|
28
|
+
var ERROR_CREATE_WALLET_ACCOUNT = 'Error creating Aleo wallet account';
|
|
29
|
+
var ERROR_ACCOUNT_ADDRESS_REQUIRED = 'Account address is required';
|
|
30
|
+
var ERROR_EXPORT_PRIVATE_KEY = 'Error exporting Aleo private key';
|
|
31
|
+
var ERROR_IMPORT_PRIVATE_KEY_NOT_SUPPORTED = 'Aleo importPrivateKey is not supported yet';
|
|
32
|
+
var ERROR_SIGN_MESSAGE_NOT_SUPPORTED = 'Aleo signMessage is not supported yet — pending arbitrary-bytes EdBls12377 signing';
|
|
33
|
+
var ERROR_SIGN_TRANSACTION_NOT_SUPPORTED = 'Aleo signTransaction is not supported yet — coming in Phase 2';
|
|
34
|
+
var ALEO_NETWORKS = {
|
|
35
|
+
MAINNET: 'mainnet',
|
|
36
|
+
TESTNET: 'testnet'
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Default Provable Delegated Proving Service endpoint.
|
|
40
|
+
* Used by `submitProvingRequest` — Provable computes the ZK proof on their
|
|
41
|
+
* accelerator hardware and (optionally) broadcasts. No API key required for
|
|
42
|
+
* testnet during Phase 2.
|
|
43
|
+
*/ var DEFAULT_PROVABLE_PROVER_URI = 'https://accelerate.provable.com';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* IndexedDB-backed persistence for Aleo per-wallet record-scanner state.
|
|
47
|
+
*
|
|
48
|
+
* We cache the scanner's UUID, the owned-records list, and the spent-record
|
|
49
|
+
* nonces per accountAddress so subsequent queries resume from the last known
|
|
50
|
+
* state instead of re-registering with Provable's scanner on every page load.
|
|
51
|
+
*
|
|
52
|
+
* Storage shape (object store "state", keyed by `${accountAddress}:${network}`):
|
|
53
|
+
* { accountAddress, network, scannerUuid, records, spentNonces, lastScannedBlock,
|
|
54
|
+
* sealanceProofs, updatedAt }
|
|
55
|
+
*
|
|
56
|
+
* The keyPath value is the composite `${accountAddress}:${network}` so testnet
|
|
57
|
+
* and mainnet entries for the same wallet don't collide. Pre-network-aware
|
|
58
|
+
* entries (raw `accountAddress` keys) are functionally orphaned by the new
|
|
59
|
+
* composite lookups and will simply be re-registered on first call. Acceptable
|
|
60
|
+
* one-time cost; avoids a DB schema migration / version bump.
|
|
61
|
+
*
|
|
62
|
+
* `records` is a JSON-stringified array of `OwnedRecord` — keeping it as a
|
|
63
|
+
* string lets us cache decrypted plaintexts without imposing a Provable SDK
|
|
64
|
+
* type dependency on this persistence module.
|
|
65
|
+
*
|
|
66
|
+
* Security: blobs are stored plaintext, matching Dynamic's existing policy
|
|
67
|
+
* for locally-cached key material. Protection comes from the iframe's origin
|
|
68
|
+
* isolation, not at-rest encryption. Cloned from Midnight's
|
|
69
|
+
* walletStateStorage.ts; a future refactor may extract a generic kv store.
|
|
70
|
+
*/ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
71
|
+
try {
|
|
72
|
+
var info = gen[key](arg);
|
|
73
|
+
var value = info.value;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
reject(error);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (info.done) {
|
|
79
|
+
resolve(value);
|
|
80
|
+
} else {
|
|
81
|
+
Promise.resolve(value).then(_next, _throw);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function _async_to_generator$3(fn) {
|
|
85
|
+
return function() {
|
|
86
|
+
var self = this, args = arguments;
|
|
87
|
+
return new Promise(function(resolve, reject) {
|
|
88
|
+
var gen = fn.apply(self, args);
|
|
89
|
+
function _next(value) {
|
|
90
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
91
|
+
}
|
|
92
|
+
function _throw(err) {
|
|
93
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
94
|
+
}
|
|
95
|
+
_next(undefined);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function _instanceof$2(left, right) {
|
|
100
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
101
|
+
return !!right[Symbol.hasInstance](left);
|
|
102
|
+
} else {
|
|
103
|
+
return left instanceof right;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function _type_of$1(obj) {
|
|
107
|
+
"@swc/helpers - typeof";
|
|
108
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
109
|
+
}
|
|
110
|
+
function _ts_generator$3(thisArg, body) {
|
|
111
|
+
var f, y, t, g, _ = {
|
|
112
|
+
label: 0,
|
|
113
|
+
sent: function() {
|
|
114
|
+
if (t[0] & 1) throw t[1];
|
|
115
|
+
return t[1];
|
|
116
|
+
},
|
|
117
|
+
trys: [],
|
|
118
|
+
ops: []
|
|
119
|
+
};
|
|
120
|
+
return g = {
|
|
121
|
+
next: verb(0),
|
|
122
|
+
"throw": verb(1),
|
|
123
|
+
"return": verb(2)
|
|
124
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
125
|
+
return this;
|
|
126
|
+
}), g;
|
|
127
|
+
function verb(n) {
|
|
128
|
+
return function(v) {
|
|
129
|
+
return step([
|
|
130
|
+
n,
|
|
131
|
+
v
|
|
132
|
+
]);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function step(op) {
|
|
136
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
137
|
+
while(_)try {
|
|
138
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
139
|
+
if (y = 0, t) op = [
|
|
140
|
+
op[0] & 2,
|
|
141
|
+
t.value
|
|
142
|
+
];
|
|
143
|
+
switch(op[0]){
|
|
144
|
+
case 0:
|
|
145
|
+
case 1:
|
|
146
|
+
t = op;
|
|
147
|
+
break;
|
|
148
|
+
case 4:
|
|
149
|
+
_.label++;
|
|
150
|
+
return {
|
|
151
|
+
value: op[1],
|
|
152
|
+
done: false
|
|
153
|
+
};
|
|
154
|
+
case 5:
|
|
155
|
+
_.label++;
|
|
156
|
+
y = op[1];
|
|
157
|
+
op = [
|
|
158
|
+
0
|
|
159
|
+
];
|
|
160
|
+
continue;
|
|
161
|
+
case 7:
|
|
162
|
+
op = _.ops.pop();
|
|
163
|
+
_.trys.pop();
|
|
164
|
+
continue;
|
|
165
|
+
default:
|
|
166
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
167
|
+
_ = 0;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
171
|
+
_.label = op[1];
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
175
|
+
_.label = t[1];
|
|
176
|
+
t = op;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
if (t && _.label < t[2]) {
|
|
180
|
+
_.label = t[2];
|
|
181
|
+
_.ops.push(op);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
if (t[2]) _.ops.pop();
|
|
185
|
+
_.trys.pop();
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
op = body.call(thisArg, _);
|
|
189
|
+
} catch (e) {
|
|
190
|
+
op = [
|
|
191
|
+
6,
|
|
192
|
+
e
|
|
193
|
+
];
|
|
194
|
+
y = 0;
|
|
195
|
+
} finally{
|
|
196
|
+
f = t = 0;
|
|
197
|
+
}
|
|
198
|
+
if (op[0] & 5) throw op[1];
|
|
199
|
+
return {
|
|
200
|
+
value: op[0] ? op[1] : void 0,
|
|
201
|
+
done: true
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
var DB_NAME = 'dynamic-aleo-wallet-state';
|
|
206
|
+
var DB_VERSION = 1;
|
|
207
|
+
var STORE_NAME = 'state';
|
|
208
|
+
/** Composes the IndexedDB key from a wallet address + network. Exported so
|
|
209
|
+
* callers can build the same string when they need to look up a record
|
|
210
|
+
* outside the standard `getWalletState` path. */ var buildStorageKey = function(accountAddress, network) {
|
|
211
|
+
return "".concat(accountAddress, ":").concat(network);
|
|
212
|
+
};
|
|
213
|
+
// Normalizes a DOMException | unknown into an Error so promise rejections
|
|
214
|
+
// always carry an Error instance. Object-shaped errors (DOMException, plain
|
|
215
|
+
// objects) are looked up for a `.message` string first so we don't stringify
|
|
216
|
+
// them via Object.prototype.toString (which yields the useless '[object Object]').
|
|
217
|
+
// Exported for direct unit testing of the fallback chain.
|
|
218
|
+
function toError(err, fallbackMessage) {
|
|
219
|
+
if (_instanceof$2(err, Error)) return err;
|
|
220
|
+
if (err == null) return new Error(fallbackMessage);
|
|
221
|
+
if (typeof err === 'string') return new Error(err);
|
|
222
|
+
if (typeof err === 'number' || typeof err === 'boolean' || (typeof err === "undefined" ? "undefined" : _type_of$1(err)) === 'bigint') {
|
|
223
|
+
return new Error(String(err));
|
|
224
|
+
}
|
|
225
|
+
var message = err.message;
|
|
226
|
+
if (typeof message === 'string' && message.length > 0) return new Error(message);
|
|
227
|
+
try {
|
|
228
|
+
return new Error(JSON.stringify(err));
|
|
229
|
+
} catch (e) {
|
|
230
|
+
return new Error(fallbackMessage);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
var dbPromise = null;
|
|
234
|
+
function openDb() {
|
|
235
|
+
if (dbPromise) return dbPromise;
|
|
236
|
+
// On rejection, null the module-level cache so the next caller retries
|
|
237
|
+
// the open instead of receiving the same rejected promise for the rest of
|
|
238
|
+
// the session (private-browsing bootup, transient quota errors, etc).
|
|
239
|
+
dbPromise = new Promise(function(resolve, reject) {
|
|
240
|
+
var req = indexedDB.open(DB_NAME, DB_VERSION);
|
|
241
|
+
req.onupgradeneeded = function() {
|
|
242
|
+
var db = req.result;
|
|
243
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
244
|
+
db.createObjectStore(STORE_NAME, {
|
|
245
|
+
keyPath: 'accountAddress'
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
req.onsuccess = function() {
|
|
250
|
+
return resolve(req.result);
|
|
251
|
+
};
|
|
252
|
+
req.onerror = function() {
|
|
253
|
+
return reject(toError(req.error, 'IndexedDB open failed'));
|
|
254
|
+
};
|
|
255
|
+
}).catch(function(err) {
|
|
256
|
+
dbPromise = null;
|
|
257
|
+
throw err;
|
|
258
|
+
});
|
|
259
|
+
return dbPromise;
|
|
260
|
+
}
|
|
261
|
+
function runTransaction(mode, fn) {
|
|
262
|
+
return _runTransaction.apply(this, arguments);
|
|
263
|
+
}
|
|
264
|
+
function _runTransaction() {
|
|
265
|
+
_runTransaction = _async_to_generator$3(function(mode, fn) {
|
|
266
|
+
var db;
|
|
267
|
+
return _ts_generator$3(this, function(_state) {
|
|
268
|
+
switch(_state.label){
|
|
269
|
+
case 0:
|
|
270
|
+
return [
|
|
271
|
+
4,
|
|
272
|
+
openDb()
|
|
273
|
+
];
|
|
274
|
+
case 1:
|
|
275
|
+
db = _state.sent();
|
|
276
|
+
return [
|
|
277
|
+
2,
|
|
278
|
+
new Promise(function(resolve, reject) {
|
|
279
|
+
var tx = db.transaction(STORE_NAME, mode);
|
|
280
|
+
var store = tx.objectStore(STORE_NAME);
|
|
281
|
+
var req = fn(store);
|
|
282
|
+
req.onsuccess = function() {
|
|
283
|
+
return resolve(req.result);
|
|
284
|
+
};
|
|
285
|
+
req.onerror = function() {
|
|
286
|
+
return reject(toError(req.error, 'IndexedDB request failed'));
|
|
287
|
+
};
|
|
288
|
+
})
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
return _runTransaction.apply(this, arguments);
|
|
294
|
+
}
|
|
295
|
+
function getWalletState(accountAddress, network) {
|
|
296
|
+
return _getWalletState.apply(this, arguments);
|
|
297
|
+
}
|
|
298
|
+
function _getWalletState() {
|
|
299
|
+
_getWalletState = _async_to_generator$3(function(accountAddress, network) {
|
|
300
|
+
var key, result;
|
|
301
|
+
return _ts_generator$3(this, function(_state) {
|
|
302
|
+
switch(_state.label){
|
|
303
|
+
case 0:
|
|
304
|
+
_state.trys.push([
|
|
305
|
+
0,
|
|
306
|
+
2,
|
|
307
|
+
,
|
|
308
|
+
3
|
|
309
|
+
]);
|
|
310
|
+
key = buildStorageKey(accountAddress, network);
|
|
311
|
+
return [
|
|
312
|
+
4,
|
|
313
|
+
runTransaction('readonly', function(store) {
|
|
314
|
+
return store.get(key);
|
|
315
|
+
})
|
|
316
|
+
];
|
|
317
|
+
case 1:
|
|
318
|
+
result = _state.sent();
|
|
319
|
+
return [
|
|
320
|
+
2,
|
|
321
|
+
result !== null && result !== void 0 ? result : null
|
|
322
|
+
];
|
|
323
|
+
case 2:
|
|
324
|
+
_state.sent();
|
|
325
|
+
// IndexedDB unavailable (private mode, corrupt DB, etc.) — behave as if empty.
|
|
326
|
+
return [
|
|
327
|
+
2,
|
|
328
|
+
null
|
|
329
|
+
];
|
|
330
|
+
case 3:
|
|
331
|
+
return [
|
|
332
|
+
2
|
|
333
|
+
];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
return _getWalletState.apply(this, arguments);
|
|
338
|
+
}
|
|
339
|
+
function putWalletState(accountAddress, network, state) {
|
|
340
|
+
return _putWalletState.apply(this, arguments);
|
|
341
|
+
}
|
|
342
|
+
function _putWalletState() {
|
|
343
|
+
_putWalletState = _async_to_generator$3(function(accountAddress, network, state) {
|
|
344
|
+
var record;
|
|
345
|
+
return _ts_generator$3(this, function(_state) {
|
|
346
|
+
switch(_state.label){
|
|
347
|
+
case 0:
|
|
348
|
+
record = {
|
|
349
|
+
accountAddress: buildStorageKey(accountAddress, network),
|
|
350
|
+
walletAddress: accountAddress,
|
|
351
|
+
network: network,
|
|
352
|
+
scannerUuid: state.scannerUuid,
|
|
353
|
+
records: state.records,
|
|
354
|
+
spentNonces: state.spentNonces,
|
|
355
|
+
lastScannedBlock: state.lastScannedBlock,
|
|
356
|
+
sealanceProofs: state.sealanceProofs,
|
|
357
|
+
updatedAt: Date.now()
|
|
358
|
+
};
|
|
359
|
+
_state.label = 1;
|
|
360
|
+
case 1:
|
|
361
|
+
_state.trys.push([
|
|
362
|
+
1,
|
|
363
|
+
3,
|
|
364
|
+
,
|
|
365
|
+
4
|
|
366
|
+
]);
|
|
367
|
+
return [
|
|
368
|
+
4,
|
|
369
|
+
runTransaction('readwrite', function(store) {
|
|
370
|
+
return store.put(record);
|
|
371
|
+
})
|
|
372
|
+
];
|
|
373
|
+
case 2:
|
|
374
|
+
_state.sent();
|
|
375
|
+
return [
|
|
376
|
+
3,
|
|
377
|
+
4
|
|
378
|
+
];
|
|
379
|
+
case 3:
|
|
380
|
+
_state.sent();
|
|
381
|
+
return [
|
|
382
|
+
3,
|
|
383
|
+
4
|
|
384
|
+
];
|
|
385
|
+
case 4:
|
|
386
|
+
return [
|
|
387
|
+
2
|
|
388
|
+
];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
return _putWalletState.apply(this, arguments);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Iframe-side Feemaster surface used by `proveTransaction`.
|
|
397
|
+
*
|
|
398
|
+
* Earlier versions made `fetch()` calls to ANF directly with a hardcoded
|
|
399
|
+
* Bearer key shipped in the iframe bundle. As of Phase A1 the iframe goes
|
|
400
|
+
* through redcoast (which holds the ANF key server-side) — and by reusing
|
|
401
|
+
* the existing `DynamicApiClient` in `@dynamic-labs-wallet/core`, all the
|
|
402
|
+
* baseApiUrl / Authorization-header / retry plumbing is shared with the
|
|
403
|
+
* other waas redcoast endpoints (`exportAleoViewKey`, `signAleoRequest`,
|
|
404
|
+
* etc.).
|
|
405
|
+
*
|
|
406
|
+
* This file is now a thin wrapper that:
|
|
407
|
+
* - holds the network the iframe is bound to
|
|
408
|
+
* - keeps a 5-min in-memory policy cache (matches the previous behaviour)
|
|
409
|
+
* - delegates HTTP work to `DynamicApiClient`
|
|
410
|
+
*
|
|
411
|
+
* Surface kept identical (`fetchPolicy`, `isCovered`, `requestFeeAuthorization`)
|
|
412
|
+
* so call sites in `proveTransaction` don't change.
|
|
413
|
+
*/ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
414
|
+
try {
|
|
415
|
+
var info = gen[key](arg);
|
|
416
|
+
var value = info.value;
|
|
417
|
+
} catch (error) {
|
|
418
|
+
reject(error);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (info.done) {
|
|
422
|
+
resolve(value);
|
|
423
|
+
} else {
|
|
424
|
+
Promise.resolve(value).then(_next, _throw);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function _async_to_generator$2(fn) {
|
|
428
|
+
return function() {
|
|
429
|
+
var self = this, args = arguments;
|
|
430
|
+
return new Promise(function(resolve, reject) {
|
|
431
|
+
var gen = fn.apply(self, args);
|
|
432
|
+
function _next(value) {
|
|
433
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
434
|
+
}
|
|
435
|
+
function _throw(err) {
|
|
436
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
437
|
+
}
|
|
438
|
+
_next(undefined);
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function _class_call_check$2(instance, Constructor) {
|
|
443
|
+
if (!(instance instanceof Constructor)) {
|
|
444
|
+
throw new TypeError("Cannot call a class as a function");
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function _defineProperties$2(target, props) {
|
|
448
|
+
for(var i = 0; i < props.length; i++){
|
|
449
|
+
var descriptor = props[i];
|
|
450
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
451
|
+
descriptor.configurable = true;
|
|
452
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
453
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
457
|
+
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
|
458
|
+
return Constructor;
|
|
459
|
+
}
|
|
460
|
+
function _define_property$2(obj, key, value) {
|
|
461
|
+
if (key in obj) {
|
|
462
|
+
Object.defineProperty(obj, key, {
|
|
463
|
+
value: value,
|
|
464
|
+
enumerable: true,
|
|
465
|
+
configurable: true,
|
|
466
|
+
writable: true
|
|
467
|
+
});
|
|
468
|
+
} else {
|
|
469
|
+
obj[key] = value;
|
|
470
|
+
}
|
|
471
|
+
return obj;
|
|
472
|
+
}
|
|
473
|
+
function _ts_generator$2(thisArg, body) {
|
|
474
|
+
var f, y, t, g, _ = {
|
|
475
|
+
label: 0,
|
|
476
|
+
sent: function() {
|
|
477
|
+
if (t[0] & 1) throw t[1];
|
|
478
|
+
return t[1];
|
|
479
|
+
},
|
|
480
|
+
trys: [],
|
|
481
|
+
ops: []
|
|
482
|
+
};
|
|
483
|
+
return g = {
|
|
484
|
+
next: verb(0),
|
|
485
|
+
"throw": verb(1),
|
|
486
|
+
"return": verb(2)
|
|
487
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
488
|
+
return this;
|
|
489
|
+
}), g;
|
|
490
|
+
function verb(n) {
|
|
491
|
+
return function(v) {
|
|
492
|
+
return step([
|
|
493
|
+
n,
|
|
494
|
+
v
|
|
495
|
+
]);
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function step(op) {
|
|
499
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
500
|
+
while(_)try {
|
|
501
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
502
|
+
if (y = 0, t) op = [
|
|
503
|
+
op[0] & 2,
|
|
504
|
+
t.value
|
|
505
|
+
];
|
|
506
|
+
switch(op[0]){
|
|
507
|
+
case 0:
|
|
508
|
+
case 1:
|
|
509
|
+
t = op;
|
|
510
|
+
break;
|
|
511
|
+
case 4:
|
|
512
|
+
_.label++;
|
|
513
|
+
return {
|
|
514
|
+
value: op[1],
|
|
515
|
+
done: false
|
|
516
|
+
};
|
|
517
|
+
case 5:
|
|
518
|
+
_.label++;
|
|
519
|
+
y = op[1];
|
|
520
|
+
op = [
|
|
521
|
+
0
|
|
522
|
+
];
|
|
523
|
+
continue;
|
|
524
|
+
case 7:
|
|
525
|
+
op = _.ops.pop();
|
|
526
|
+
_.trys.pop();
|
|
527
|
+
continue;
|
|
528
|
+
default:
|
|
529
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
530
|
+
_ = 0;
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
534
|
+
_.label = op[1];
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
538
|
+
_.label = t[1];
|
|
539
|
+
t = op;
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
if (t && _.label < t[2]) {
|
|
543
|
+
_.label = t[2];
|
|
544
|
+
_.ops.push(op);
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
if (t[2]) _.ops.pop();
|
|
548
|
+
_.trys.pop();
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
op = body.call(thisArg, _);
|
|
552
|
+
} catch (e) {
|
|
553
|
+
op = [
|
|
554
|
+
6,
|
|
555
|
+
e
|
|
556
|
+
];
|
|
557
|
+
y = 0;
|
|
558
|
+
} finally{
|
|
559
|
+
f = t = 0;
|
|
560
|
+
}
|
|
561
|
+
if (op[0] & 5) throw op[1];
|
|
562
|
+
return {
|
|
563
|
+
value: op[0] ? op[1] : void 0,
|
|
564
|
+
done: true
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
var POLICY_TTL_MS = 5 * 60 * 1000;
|
|
569
|
+
var FeemasterClient = /*#__PURE__*/ function() {
|
|
570
|
+
function FeemasterClient(args) {
|
|
571
|
+
_class_call_check$2(this, FeemasterClient);
|
|
572
|
+
_define_property$2(this, "apiClient", void 0);
|
|
573
|
+
_define_property$2(this, "network", void 0);
|
|
574
|
+
_define_property$2(this, "policyCache", null);
|
|
575
|
+
this.apiClient = args.apiClient;
|
|
576
|
+
this.network = args.network;
|
|
577
|
+
}
|
|
578
|
+
_create_class$2(FeemasterClient, [
|
|
579
|
+
{
|
|
580
|
+
key: "fetchPolicy",
|
|
581
|
+
value: /** Fetches the Feemaster policy for the configured network. Cached for
|
|
582
|
+
* 5 minutes; pass `force: true` after a quota-exhausted response. */ function fetchPolicy() {
|
|
583
|
+
var force = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
|
|
584
|
+
var _this = this;
|
|
585
|
+
return _async_to_generator$2(function() {
|
|
586
|
+
var policy;
|
|
587
|
+
return _ts_generator$2(this, function(_state) {
|
|
588
|
+
switch(_state.label){
|
|
589
|
+
case 0:
|
|
590
|
+
if (!force && _this.policyCache && Date.now() - _this.policyCache.cachedAt < POLICY_TTL_MS) {
|
|
591
|
+
return [
|
|
592
|
+
2,
|
|
593
|
+
_this.policyCache.policy
|
|
594
|
+
];
|
|
595
|
+
}
|
|
596
|
+
return [
|
|
597
|
+
4,
|
|
598
|
+
_this.apiClient.getAleoFeemasterPolicy({
|
|
599
|
+
network: _this.network
|
|
600
|
+
})
|
|
601
|
+
];
|
|
602
|
+
case 1:
|
|
603
|
+
policy = _state.sent();
|
|
604
|
+
_this.policyCache = {
|
|
605
|
+
policy: policy,
|
|
606
|
+
cachedAt: Date.now()
|
|
607
|
+
};
|
|
608
|
+
return [
|
|
609
|
+
2,
|
|
610
|
+
policy
|
|
611
|
+
];
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
})();
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
key: "isCovered",
|
|
619
|
+
value: /** Returns true when the configured network's policy permits sponsoring
|
|
620
|
+
* `(programId, functionName)`. Never throws — returns false on any
|
|
621
|
+
* policy fetch failure so callers can fall back to user-paid. */ function isCovered(programId, functionName) {
|
|
622
|
+
var _this = this;
|
|
623
|
+
return _async_to_generator$2(function() {
|
|
624
|
+
var policy, entry;
|
|
625
|
+
return _ts_generator$2(this, function(_state) {
|
|
626
|
+
switch(_state.label){
|
|
627
|
+
case 0:
|
|
628
|
+
_state.trys.push([
|
|
629
|
+
0,
|
|
630
|
+
2,
|
|
631
|
+
,
|
|
632
|
+
3
|
|
633
|
+
]);
|
|
634
|
+
return [
|
|
635
|
+
4,
|
|
636
|
+
_this.apiClient.isAleoFeemasterCovered({
|
|
637
|
+
network: _this.network,
|
|
638
|
+
programId: programId,
|
|
639
|
+
functionName: functionName
|
|
640
|
+
})
|
|
641
|
+
];
|
|
642
|
+
case 1:
|
|
643
|
+
return [
|
|
644
|
+
2,
|
|
645
|
+
_state.sent()
|
|
646
|
+
];
|
|
647
|
+
case 2:
|
|
648
|
+
_state.sent();
|
|
649
|
+
return [
|
|
650
|
+
3,
|
|
651
|
+
3
|
|
652
|
+
];
|
|
653
|
+
case 3:
|
|
654
|
+
_state.trys.push([
|
|
655
|
+
3,
|
|
656
|
+
5,
|
|
657
|
+
,
|
|
658
|
+
6
|
|
659
|
+
]);
|
|
660
|
+
return [
|
|
661
|
+
4,
|
|
662
|
+
_this.fetchPolicy()
|
|
663
|
+
];
|
|
664
|
+
case 4:
|
|
665
|
+
policy = _state.sent();
|
|
666
|
+
if (!policy.allowed_programs) return [
|
|
667
|
+
2,
|
|
668
|
+
true
|
|
669
|
+
];
|
|
670
|
+
entry = policy.allowed_programs.find(function(p) {
|
|
671
|
+
return p.program_id === programId;
|
|
672
|
+
});
|
|
673
|
+
if (!entry) return [
|
|
674
|
+
2,
|
|
675
|
+
false
|
|
676
|
+
];
|
|
677
|
+
if (!entry.allowed_functions) return [
|
|
678
|
+
2,
|
|
679
|
+
true
|
|
680
|
+
];
|
|
681
|
+
return [
|
|
682
|
+
2,
|
|
683
|
+
entry.allowed_functions.includes(functionName)
|
|
684
|
+
];
|
|
685
|
+
case 5:
|
|
686
|
+
_state.sent();
|
|
687
|
+
return [
|
|
688
|
+
2,
|
|
689
|
+
false
|
|
690
|
+
];
|
|
691
|
+
case 6:
|
|
692
|
+
return [
|
|
693
|
+
2
|
|
694
|
+
];
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
})();
|
|
698
|
+
}
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
key: "requestFeeAuthorization",
|
|
702
|
+
value: /** Forwards a user-signed Aleo Authorization to ANF (via redcoast) and
|
|
703
|
+
* returns the corresponding `feeAuthorization` for bundling into a
|
|
704
|
+
* ProvingRequest. Throws on quota / service errors so the caller falls
|
|
705
|
+
* back to user-paid fees. */ function requestFeeAuthorization(params) {
|
|
706
|
+
var _this = this;
|
|
707
|
+
return _async_to_generator$2(function() {
|
|
708
|
+
var feeAuthorization;
|
|
709
|
+
return _ts_generator$2(this, function(_state) {
|
|
710
|
+
switch(_state.label){
|
|
711
|
+
case 0:
|
|
712
|
+
return [
|
|
713
|
+
4,
|
|
714
|
+
_this.apiClient.requestAleoFeeAuthorization({
|
|
715
|
+
network: _this.network,
|
|
716
|
+
authorization: params.authorizationString,
|
|
717
|
+
priorityFee: params.priorityFee
|
|
718
|
+
})
|
|
719
|
+
];
|
|
720
|
+
case 1:
|
|
721
|
+
feeAuthorization = _state.sent().feeAuthorization;
|
|
722
|
+
return [
|
|
723
|
+
2,
|
|
724
|
+
{
|
|
725
|
+
feeAuthorizationString: feeAuthorization
|
|
726
|
+
}
|
|
727
|
+
];
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
})();
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
]);
|
|
734
|
+
return FeemasterClient;
|
|
735
|
+
}();
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Iframe-side RecordScanner that mirrors the Provable SDK's surface but
|
|
739
|
+
* routes every HTTP call through redcoast. This is the Phase A2 swap —
|
|
740
|
+
* before this, the iframe held a hardcoded scanner apiKey + consumerId;
|
|
741
|
+
* now those credentials live in redcoast env vars and the iframe
|
|
742
|
+
* authenticates via the user's Dynamic JWT (handled by `DynamicApiClient`).
|
|
743
|
+
*
|
|
744
|
+
* What stays in the iframe:
|
|
745
|
+
* - The `crypto_box_seal` wrap of the view key (`encryptRegistrationRequest`
|
|
746
|
+
* from the Provable SDK). The view key plaintext never leaves the
|
|
747
|
+
* iframe; only its encrypted form crosses the wire.
|
|
748
|
+
*
|
|
749
|
+
* What now lives in redcoast:
|
|
750
|
+
* - The Provable Bearer apiKey + consumerId.
|
|
751
|
+
* - JWT lifecycle (the SDK used to manage this in the browser; redcoast
|
|
752
|
+
* manages it server-side now and the iframe is unaware).
|
|
753
|
+
*
|
|
754
|
+
* The class signature intentionally matches the parts of `sdk.RecordScanner`
|
|
755
|
+
* the iframe consumes (`registerEncrypted`, `findRecords`) so the rest of
|
|
756
|
+
* `DynamicAleoWalletClient.findOwnedRecordsInner` doesn't change.
|
|
757
|
+
*/ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
758
|
+
try {
|
|
759
|
+
var info = gen[key](arg);
|
|
760
|
+
var value = info.value;
|
|
761
|
+
} catch (error) {
|
|
762
|
+
reject(error);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
if (info.done) {
|
|
766
|
+
resolve(value);
|
|
767
|
+
} else {
|
|
768
|
+
Promise.resolve(value).then(_next, _throw);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function _async_to_generator$1(fn) {
|
|
772
|
+
return function() {
|
|
773
|
+
var self = this, args = arguments;
|
|
774
|
+
return new Promise(function(resolve, reject) {
|
|
775
|
+
var gen = fn.apply(self, args);
|
|
776
|
+
function _next(value) {
|
|
777
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
778
|
+
}
|
|
779
|
+
function _throw(err) {
|
|
780
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
781
|
+
}
|
|
782
|
+
_next(undefined);
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
function _class_call_check$1(instance, Constructor) {
|
|
787
|
+
if (!(instance instanceof Constructor)) {
|
|
788
|
+
throw new TypeError("Cannot call a class as a function");
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function _defineProperties$1(target, props) {
|
|
792
|
+
for(var i = 0; i < props.length; i++){
|
|
793
|
+
var descriptor = props[i];
|
|
794
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
795
|
+
descriptor.configurable = true;
|
|
796
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
797
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
801
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
802
|
+
return Constructor;
|
|
803
|
+
}
|
|
804
|
+
function _define_property$1(obj, key, value) {
|
|
805
|
+
if (key in obj) {
|
|
806
|
+
Object.defineProperty(obj, key, {
|
|
807
|
+
value: value,
|
|
808
|
+
enumerable: true,
|
|
809
|
+
configurable: true,
|
|
810
|
+
writable: true
|
|
811
|
+
});
|
|
812
|
+
} else {
|
|
813
|
+
obj[key] = value;
|
|
814
|
+
}
|
|
815
|
+
return obj;
|
|
816
|
+
}
|
|
817
|
+
function _instanceof$1(left, right) {
|
|
818
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
819
|
+
return !!right[Symbol.hasInstance](left);
|
|
820
|
+
} else {
|
|
821
|
+
return left instanceof right;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function _ts_generator$1(thisArg, body) {
|
|
825
|
+
var f, y, t, g, _ = {
|
|
826
|
+
label: 0,
|
|
827
|
+
sent: function() {
|
|
828
|
+
if (t[0] & 1) throw t[1];
|
|
829
|
+
return t[1];
|
|
830
|
+
},
|
|
831
|
+
trys: [],
|
|
832
|
+
ops: []
|
|
833
|
+
};
|
|
834
|
+
return g = {
|
|
835
|
+
next: verb(0),
|
|
836
|
+
"throw": verb(1),
|
|
837
|
+
"return": verb(2)
|
|
838
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
839
|
+
return this;
|
|
840
|
+
}), g;
|
|
841
|
+
function verb(n) {
|
|
842
|
+
return function(v) {
|
|
843
|
+
return step([
|
|
844
|
+
n,
|
|
845
|
+
v
|
|
846
|
+
]);
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function step(op) {
|
|
850
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
851
|
+
while(_)try {
|
|
852
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
853
|
+
if (y = 0, t) op = [
|
|
854
|
+
op[0] & 2,
|
|
855
|
+
t.value
|
|
856
|
+
];
|
|
857
|
+
switch(op[0]){
|
|
858
|
+
case 0:
|
|
859
|
+
case 1:
|
|
860
|
+
t = op;
|
|
861
|
+
break;
|
|
862
|
+
case 4:
|
|
863
|
+
_.label++;
|
|
864
|
+
return {
|
|
865
|
+
value: op[1],
|
|
866
|
+
done: false
|
|
867
|
+
};
|
|
868
|
+
case 5:
|
|
869
|
+
_.label++;
|
|
870
|
+
y = op[1];
|
|
871
|
+
op = [
|
|
872
|
+
0
|
|
873
|
+
];
|
|
874
|
+
continue;
|
|
875
|
+
case 7:
|
|
876
|
+
op = _.ops.pop();
|
|
877
|
+
_.trys.pop();
|
|
878
|
+
continue;
|
|
879
|
+
default:
|
|
880
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
881
|
+
_ = 0;
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
885
|
+
_.label = op[1];
|
|
886
|
+
break;
|
|
887
|
+
}
|
|
888
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
889
|
+
_.label = t[1];
|
|
890
|
+
t = op;
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
if (t && _.label < t[2]) {
|
|
894
|
+
_.label = t[2];
|
|
895
|
+
_.ops.push(op);
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
if (t[2]) _.ops.pop();
|
|
899
|
+
_.trys.pop();
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
op = body.call(thisArg, _);
|
|
903
|
+
} catch (e) {
|
|
904
|
+
op = [
|
|
905
|
+
6,
|
|
906
|
+
e
|
|
907
|
+
];
|
|
908
|
+
y = 0;
|
|
909
|
+
} finally{
|
|
910
|
+
f = t = 0;
|
|
911
|
+
}
|
|
912
|
+
if (op[0] & 5) throw op[1];
|
|
913
|
+
return {
|
|
914
|
+
value: op[0] ? op[1] : void 0,
|
|
915
|
+
done: true
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
var RedcoastRecordScanner = /*#__PURE__*/ function() {
|
|
920
|
+
function RedcoastRecordScanner(args) {
|
|
921
|
+
_class_call_check$1(this, RedcoastRecordScanner);
|
|
922
|
+
_define_property$1(this, "apiClient", void 0);
|
|
923
|
+
_define_property$1(this, "network", void 0);
|
|
924
|
+
_define_property$1(this, "sdk", void 0);
|
|
925
|
+
this.apiClient = args.apiClient;
|
|
926
|
+
this.network = args.network;
|
|
927
|
+
this.sdk = args.sdk;
|
|
928
|
+
}
|
|
929
|
+
_create_class$1(RedcoastRecordScanner, [
|
|
930
|
+
{
|
|
931
|
+
key: "registerEncrypted",
|
|
932
|
+
value: /**
|
|
933
|
+
* Registers an encrypted view key with the scanner. Mirrors
|
|
934
|
+
* `sdk.RecordScanner.registerEncrypted(viewKey, startBlock)`:
|
|
935
|
+
*
|
|
936
|
+
* 1. GET `/scanner/pubkey` → ephemeral public key
|
|
937
|
+
* 2. Wrap `(viewKey, startBlock)` via libsodium `crypto_box_seal`
|
|
938
|
+
* 3. POST `/scanner/register` with `{ key_id, ciphertext }`
|
|
939
|
+
*
|
|
940
|
+
* Returns the SDK-shaped Result so callers don't have to change.
|
|
941
|
+
*/ function registerEncrypted(viewKey, startBlock) {
|
|
942
|
+
var _this = this;
|
|
943
|
+
return _async_to_generator$1(function() {
|
|
944
|
+
var pubkey, ciphertext, data, err, _err_response, status, message;
|
|
945
|
+
return _ts_generator$1(this, function(_state) {
|
|
946
|
+
switch(_state.label){
|
|
947
|
+
case 0:
|
|
948
|
+
_state.trys.push([
|
|
949
|
+
0,
|
|
950
|
+
3,
|
|
951
|
+
,
|
|
952
|
+
4
|
|
953
|
+
]);
|
|
954
|
+
return [
|
|
955
|
+
4,
|
|
956
|
+
_this.apiClient.getAleoScannerPubkey({
|
|
957
|
+
network: _this.network
|
|
958
|
+
})
|
|
959
|
+
];
|
|
960
|
+
case 1:
|
|
961
|
+
pubkey = _state.sent();
|
|
962
|
+
ciphertext = _this.sdk.encryptRegistrationRequest(pubkey.public_key, viewKey, startBlock);
|
|
963
|
+
return [
|
|
964
|
+
4,
|
|
965
|
+
_this.apiClient.registerAleoScanner({
|
|
966
|
+
network: _this.network,
|
|
967
|
+
keyId: pubkey.key_id,
|
|
968
|
+
ciphertext: ciphertext
|
|
969
|
+
})
|
|
970
|
+
];
|
|
971
|
+
case 2:
|
|
972
|
+
data = _state.sent();
|
|
973
|
+
return [
|
|
974
|
+
2,
|
|
975
|
+
{
|
|
976
|
+
ok: true,
|
|
977
|
+
data: data
|
|
978
|
+
}
|
|
979
|
+
];
|
|
980
|
+
case 3:
|
|
981
|
+
err = _state.sent();
|
|
982
|
+
status = (_err_response = err.response) === null || _err_response === void 0 ? void 0 : _err_response.status;
|
|
983
|
+
message = _instanceof$1(err, Error) ? err.message : String(err);
|
|
984
|
+
return [
|
|
985
|
+
2,
|
|
986
|
+
{
|
|
987
|
+
ok: false,
|
|
988
|
+
status: status,
|
|
989
|
+
error: {
|
|
990
|
+
message: message
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
];
|
|
994
|
+
case 4:
|
|
995
|
+
return [
|
|
996
|
+
2
|
|
997
|
+
];
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
})();
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
key: "findRecords",
|
|
1005
|
+
value: /**
|
|
1006
|
+
* Find owned records by uuid. Mirrors the subset of
|
|
1007
|
+
* `sdk.RecordScanner.findRecords(filter)` the iframe consumes.
|
|
1008
|
+
*
|
|
1009
|
+
* The SDK's filter shape is `{ uuid, decrypt, unspent, filter, ... }`.
|
|
1010
|
+
* We forward it verbatim. Records returned are still encrypted on
|
|
1011
|
+
* the wire; the caller (`DynamicAleoWalletClient.findOwnedRecordsInner`)
|
|
1012
|
+
* decrypts them locally with the view key — same as before A2, just
|
|
1013
|
+
* with a different transport underneath.
|
|
1014
|
+
*/ function findRecords(filter) {
|
|
1015
|
+
var _this = this;
|
|
1016
|
+
return _async_to_generator$1(function() {
|
|
1017
|
+
var records;
|
|
1018
|
+
return _ts_generator$1(this, function(_state) {
|
|
1019
|
+
switch(_state.label){
|
|
1020
|
+
case 0:
|
|
1021
|
+
return [
|
|
1022
|
+
4,
|
|
1023
|
+
_this.apiClient.findAleoScannerRecords({
|
|
1024
|
+
network: _this.network,
|
|
1025
|
+
filter: filter
|
|
1026
|
+
})
|
|
1027
|
+
];
|
|
1028
|
+
case 1:
|
|
1029
|
+
records = _state.sent().records;
|
|
1030
|
+
return [
|
|
1031
|
+
2,
|
|
1032
|
+
Array.isArray(records) ? records : []
|
|
1033
|
+
];
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
})();
|
|
1037
|
+
}
|
|
1038
|
+
},
|
|
1039
|
+
{
|
|
1040
|
+
key: "revoke",
|
|
1041
|
+
value: /** Optional but useful for parity with the SDK; not currently called. */ function revoke(uuid) {
|
|
1042
|
+
var _this = this;
|
|
1043
|
+
return _async_to_generator$1(function() {
|
|
1044
|
+
return _ts_generator$1(this, function(_state) {
|
|
1045
|
+
return [
|
|
1046
|
+
2,
|
|
1047
|
+
_this.apiClient.revokeAleoScanner({
|
|
1048
|
+
network: _this.network,
|
|
1049
|
+
uuid: uuid
|
|
1050
|
+
})
|
|
1051
|
+
];
|
|
1052
|
+
});
|
|
1053
|
+
})();
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
]);
|
|
1057
|
+
return RedcoastRecordScanner;
|
|
1058
|
+
}();
|
|
1059
|
+
|
|
1060
|
+
function _array_like_to_array(arr, len) {
|
|
1061
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1062
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1063
|
+
return arr2;
|
|
1064
|
+
}
|
|
1065
|
+
function _array_with_holes(arr) {
|
|
1066
|
+
if (Array.isArray(arr)) return arr;
|
|
1067
|
+
}
|
|
1068
|
+
function _array_without_holes(arr) {
|
|
1069
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
1070
|
+
}
|
|
1071
|
+
function _assert_this_initialized(self) {
|
|
1072
|
+
if (self === void 0) {
|
|
1073
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
1074
|
+
}
|
|
1075
|
+
return self;
|
|
1076
|
+
}
|
|
1077
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1078
|
+
try {
|
|
1079
|
+
var info = gen[key](arg);
|
|
1080
|
+
var value = info.value;
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
reject(error);
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
if (info.done) {
|
|
1086
|
+
resolve(value);
|
|
1087
|
+
} else {
|
|
1088
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
function _async_to_generator(fn) {
|
|
1092
|
+
return function() {
|
|
1093
|
+
var self = this, args = arguments;
|
|
1094
|
+
return new Promise(function(resolve, reject) {
|
|
1095
|
+
var gen = fn.apply(self, args);
|
|
1096
|
+
function _next(value) {
|
|
1097
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
1098
|
+
}
|
|
1099
|
+
function _throw(err) {
|
|
1100
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1101
|
+
}
|
|
1102
|
+
_next(undefined);
|
|
1103
|
+
});
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
function _call_super(_this, derived, args) {
|
|
1107
|
+
derived = _get_prototype_of(derived);
|
|
1108
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
1109
|
+
}
|
|
1110
|
+
function _class_call_check(instance, Constructor) {
|
|
1111
|
+
if (!(instance instanceof Constructor)) {
|
|
1112
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
function _defineProperties(target, props) {
|
|
1116
|
+
for(var i = 0; i < props.length; i++){
|
|
1117
|
+
var descriptor = props[i];
|
|
1118
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1119
|
+
descriptor.configurable = true;
|
|
1120
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1121
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
1125
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
1126
|
+
return Constructor;
|
|
1127
|
+
}
|
|
1128
|
+
function _define_property(obj, key, value) {
|
|
1129
|
+
if (key in obj) {
|
|
1130
|
+
Object.defineProperty(obj, key, {
|
|
1131
|
+
value: value,
|
|
1132
|
+
enumerable: true,
|
|
1133
|
+
configurable: true,
|
|
1134
|
+
writable: true
|
|
1135
|
+
});
|
|
1136
|
+
} else {
|
|
1137
|
+
obj[key] = value;
|
|
1138
|
+
}
|
|
1139
|
+
return obj;
|
|
1140
|
+
}
|
|
1141
|
+
function _get_prototype_of(o) {
|
|
1142
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
1143
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
1144
|
+
};
|
|
1145
|
+
return _get_prototype_of(o);
|
|
1146
|
+
}
|
|
1147
|
+
function _inherits(subClass, superClass) {
|
|
1148
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
1149
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
1150
|
+
}
|
|
1151
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
1152
|
+
constructor: {
|
|
1153
|
+
value: subClass,
|
|
1154
|
+
writable: true,
|
|
1155
|
+
configurable: true
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
1159
|
+
}
|
|
1160
|
+
function _instanceof(left, right) {
|
|
1161
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1162
|
+
return !!right[Symbol.hasInstance](left);
|
|
1163
|
+
} else {
|
|
1164
|
+
return left instanceof right;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
function _iterable_to_array(iter) {
|
|
1168
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1169
|
+
}
|
|
1170
|
+
function _iterable_to_array_limit(arr, i) {
|
|
1171
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
1172
|
+
if (_i == null) return;
|
|
1173
|
+
var _arr = [];
|
|
1174
|
+
var _n = true;
|
|
1175
|
+
var _d = false;
|
|
1176
|
+
var _s, _e;
|
|
1177
|
+
try {
|
|
1178
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
1179
|
+
_arr.push(_s.value);
|
|
1180
|
+
if (i && _arr.length === i) break;
|
|
1181
|
+
}
|
|
1182
|
+
} catch (err) {
|
|
1183
|
+
_d = true;
|
|
1184
|
+
_e = err;
|
|
1185
|
+
} finally{
|
|
1186
|
+
try {
|
|
1187
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
1188
|
+
} finally{
|
|
1189
|
+
if (_d) throw _e;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return _arr;
|
|
1193
|
+
}
|
|
1194
|
+
function _non_iterable_rest() {
|
|
1195
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1196
|
+
}
|
|
1197
|
+
function _non_iterable_spread() {
|
|
1198
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1199
|
+
}
|
|
1200
|
+
function _object_spread(target) {
|
|
1201
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1202
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
1203
|
+
var ownKeys = Object.keys(source);
|
|
1204
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1205
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1206
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1207
|
+
}));
|
|
1208
|
+
}
|
|
1209
|
+
ownKeys.forEach(function(key) {
|
|
1210
|
+
_define_property(target, key, source[key]);
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
return target;
|
|
1214
|
+
}
|
|
1215
|
+
function ownKeys(object, enumerableOnly) {
|
|
1216
|
+
var keys = Object.keys(object);
|
|
1217
|
+
if (Object.getOwnPropertySymbols) {
|
|
1218
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
1219
|
+
keys.push.apply(keys, symbols);
|
|
1220
|
+
}
|
|
1221
|
+
return keys;
|
|
1222
|
+
}
|
|
1223
|
+
function _object_spread_props(target, source) {
|
|
1224
|
+
source = source != null ? source : {};
|
|
1225
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
1226
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
1227
|
+
} else {
|
|
1228
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
1229
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
return target;
|
|
1233
|
+
}
|
|
1234
|
+
function _possible_constructor_return(self, call) {
|
|
1235
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
1236
|
+
return call;
|
|
1237
|
+
}
|
|
1238
|
+
return _assert_this_initialized(self);
|
|
1239
|
+
}
|
|
1240
|
+
function _set_prototype_of(o, p) {
|
|
1241
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
1242
|
+
o.__proto__ = p;
|
|
1243
|
+
return o;
|
|
1244
|
+
};
|
|
1245
|
+
return _set_prototype_of(o, p);
|
|
1246
|
+
}
|
|
1247
|
+
function _sliced_to_array(arr, i) {
|
|
1248
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
1249
|
+
}
|
|
1250
|
+
function _to_consumable_array(arr) {
|
|
1251
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
1252
|
+
}
|
|
1253
|
+
function _type_of(obj) {
|
|
1254
|
+
"@swc/helpers - typeof";
|
|
1255
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1256
|
+
}
|
|
1257
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
1258
|
+
if (!o) return;
|
|
1259
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1260
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1261
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1262
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1263
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1264
|
+
}
|
|
1265
|
+
function _is_native_reflect_construct() {
|
|
1266
|
+
try {
|
|
1267
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
1268
|
+
} catch (_) {}
|
|
1269
|
+
return (_is_native_reflect_construct = function() {
|
|
1270
|
+
return !!result;
|
|
1271
|
+
})();
|
|
1272
|
+
}
|
|
1273
|
+
function _ts_generator(thisArg, body) {
|
|
1274
|
+
var f, y, t, g, _ = {
|
|
1275
|
+
label: 0,
|
|
1276
|
+
sent: function() {
|
|
1277
|
+
if (t[0] & 1) throw t[1];
|
|
1278
|
+
return t[1];
|
|
1279
|
+
},
|
|
1280
|
+
trys: [],
|
|
1281
|
+
ops: []
|
|
1282
|
+
};
|
|
1283
|
+
return g = {
|
|
1284
|
+
next: verb(0),
|
|
1285
|
+
"throw": verb(1),
|
|
1286
|
+
"return": verb(2)
|
|
1287
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
1288
|
+
return this;
|
|
1289
|
+
}), g;
|
|
1290
|
+
function verb(n) {
|
|
1291
|
+
return function(v) {
|
|
1292
|
+
return step([
|
|
1293
|
+
n,
|
|
1294
|
+
v
|
|
1295
|
+
]);
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
function step(op) {
|
|
1299
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1300
|
+
while(_)try {
|
|
1301
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1302
|
+
if (y = 0, t) op = [
|
|
1303
|
+
op[0] & 2,
|
|
1304
|
+
t.value
|
|
1305
|
+
];
|
|
1306
|
+
switch(op[0]){
|
|
1307
|
+
case 0:
|
|
1308
|
+
case 1:
|
|
1309
|
+
t = op;
|
|
1310
|
+
break;
|
|
1311
|
+
case 4:
|
|
1312
|
+
_.label++;
|
|
1313
|
+
return {
|
|
1314
|
+
value: op[1],
|
|
1315
|
+
done: false
|
|
1316
|
+
};
|
|
1317
|
+
case 5:
|
|
1318
|
+
_.label++;
|
|
1319
|
+
y = op[1];
|
|
1320
|
+
op = [
|
|
1321
|
+
0
|
|
1322
|
+
];
|
|
1323
|
+
continue;
|
|
1324
|
+
case 7:
|
|
1325
|
+
op = _.ops.pop();
|
|
1326
|
+
_.trys.pop();
|
|
1327
|
+
continue;
|
|
1328
|
+
default:
|
|
1329
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1330
|
+
_ = 0;
|
|
1331
|
+
continue;
|
|
1332
|
+
}
|
|
1333
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1334
|
+
_.label = op[1];
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1338
|
+
_.label = t[1];
|
|
1339
|
+
t = op;
|
|
1340
|
+
break;
|
|
1341
|
+
}
|
|
1342
|
+
if (t && _.label < t[2]) {
|
|
1343
|
+
_.label = t[2];
|
|
1344
|
+
_.ops.push(op);
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
if (t[2]) _.ops.pop();
|
|
1348
|
+
_.trys.pop();
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
op = body.call(thisArg, _);
|
|
1352
|
+
} catch (e) {
|
|
1353
|
+
op = [
|
|
1354
|
+
6,
|
|
1355
|
+
e
|
|
1356
|
+
];
|
|
1357
|
+
y = 0;
|
|
1358
|
+
} finally{
|
|
1359
|
+
f = t = 0;
|
|
1360
|
+
}
|
|
1361
|
+
if (op[0] & 5) throw op[1];
|
|
1362
|
+
return {
|
|
1363
|
+
value: op[0] ? op[1] : void 0,
|
|
1364
|
+
done: true
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Feemaster sponsorship for the Aleo `proveTransaction` flow runs through
|
|
1370
|
+
* redcoast as of A1.b. Redcoast holds the ANF Bearer key server-side; the
|
|
1371
|
+
* iframe authenticates with the user's Dynamic JWT. See `feemasterClient.ts`
|
|
1372
|
+
* for the request shape. No API key lives in this bundle anymore.
|
|
1373
|
+
*/ /**
|
|
1374
|
+
* Tier-3 stablecoin programs whose `transfer_private` and
|
|
1375
|
+
* `transfer_private_to_public` functions require a Sealance Merkle exclusion
|
|
1376
|
+
* proof for the sender. Programs not in this map skip the proof flow.
|
|
1377
|
+
*
|
|
1378
|
+
* Each entry maps `<stablecoinProgramId> → <freezelistProgramId, network>`.
|
|
1379
|
+
* The freezelist program publishes the BigInt-string Merkle tree at
|
|
1380
|
+
* `/v2/{network}/programs/{freezelist}/compliance/freeze-list` and the
|
|
1381
|
+
* current root at `/program/{freezelist}/mapping/freeze_list_root/1u8`.
|
|
1382
|
+
*/ var SEALANCE_PROGRAM_REGISTRY = {
|
|
1383
|
+
test_usad_stablecoin: {
|
|
1384
|
+
freezelistProgram: 'test_usad_freezelist.aleo',
|
|
1385
|
+
network: 'testnet'
|
|
1386
|
+
},
|
|
1387
|
+
test_usdcx_stablecoin: {
|
|
1388
|
+
freezelistProgram: 'test_usdcx_freezelist.aleo',
|
|
1389
|
+
network: 'testnet'
|
|
1390
|
+
},
|
|
1391
|
+
usad_stablecoin: {
|
|
1392
|
+
freezelistProgram: 'usad_freezelist.aleo',
|
|
1393
|
+
network: 'mainnet'
|
|
1394
|
+
},
|
|
1395
|
+
usdcx_stablecoin: {
|
|
1396
|
+
freezelistProgram: 'usdcx_freezelist.aleo',
|
|
1397
|
+
network: 'mainnet'
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
var SEALANCE_FUNCTIONS_REQUIRING_PROOF = new Set([
|
|
1401
|
+
'transfer_private',
|
|
1402
|
+
'transfer_private_to_public'
|
|
1403
|
+
]);
|
|
1404
|
+
/** Aleo VM input type for the proof argument on Sealance stablecoin programs.
|
|
1405
|
+
* Verified against `test_usad_stablecoin.aleo` source: `[MerkleProof; 2u32].private`. */ var SEALANCE_PROOF_INPUT_TYPE = '[MerkleProof; 2u32].private';
|
|
1406
|
+
/** Tree depth used by the freezelist Merkle tree. Matches the on-chain
|
|
1407
|
+
* `MerkleProof` struct: `siblings as [field; 16u32]`. */ var SEALANCE_TREE_DEPTH = 16;
|
|
1408
|
+
/** Heuristic for deriving the Aleo network from a program ID alone:
|
|
1409
|
+
* on Aleo, by convention all testnet programs are deployed under a `test_`
|
|
1410
|
+
* prefix; mainnet programs use the bare name. Both `credits.aleo` and
|
|
1411
|
+
* `<token>_freezelist.aleo` follow this. */ var networkFromProgramId = function(programId) {
|
|
1412
|
+
return programId.startsWith('test_') ? 'testnet' : 'mainnet';
|
|
1413
|
+
};
|
|
1414
|
+
/** Aleo numeric network ids (matches the connector's `getSelectedNetwork().chainId`):
|
|
1415
|
+
* `0` = mainnet, `1` = testnet. The connector + widget pass these in as
|
|
1416
|
+
* strings or numbers; this helper accepts both shapes. Defaults to testnet
|
|
1417
|
+
* when undefined / unrecognised so a missing network arg never silently
|
|
1418
|
+
* switches a session to mainnet. */ var resolveAleoNetwork = function(chainId) {
|
|
1419
|
+
if (chainId === undefined || chainId === null) return 'testnet';
|
|
1420
|
+
var asNumber = typeof chainId === 'number' ? chainId : Number(String(chainId));
|
|
1421
|
+
if (asNumber === 0) return 'mainnet';
|
|
1422
|
+
if (asNumber === 1) return 'testnet';
|
|
1423
|
+
return 'testnet';
|
|
1424
|
+
};
|
|
1425
|
+
var loadAleoSdk = /*#__PURE__*/ function() {
|
|
1426
|
+
var _ref = _async_to_generator(function(network) {
|
|
1427
|
+
return _ts_generator(this, function(_state) {
|
|
1428
|
+
return [
|
|
1429
|
+
2,
|
|
1430
|
+
network === 'mainnet' ? AleoSdkMainnet__namespace : AleoSdkTestnet__namespace
|
|
1431
|
+
];
|
|
1432
|
+
});
|
|
1433
|
+
});
|
|
1434
|
+
return function loadAleoSdk(network) {
|
|
1435
|
+
return _ref.apply(this, arguments);
|
|
1436
|
+
};
|
|
1437
|
+
}();
|
|
1438
|
+
var lookupSealanceConfig = function(programId) {
|
|
1439
|
+
var stem = programId.endsWith('.aleo') ? programId.slice(0, -'.aleo'.length) : programId;
|
|
1440
|
+
return SEALANCE_PROGRAM_REGISTRY[stem];
|
|
1441
|
+
};
|
|
1442
|
+
var DynamicAleoWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
1443
|
+
_inherits(DynamicAleoWalletClient, DynamicWalletClient);
|
|
1444
|
+
function DynamicAleoWalletClient(param, internalOptions) {
|
|
1445
|
+
var environmentId = param.environmentId, authToken = param.authToken, baseApiUrl = param.baseApiUrl, baseMPCRelayApiUrl = param.baseMPCRelayApiUrl, storageKey = param.storageKey, debug = param.debug, featureFlags = param.featureFlags, _param_authMode = param.authMode, authMode = _param_authMode === void 0 ? browser.AuthMode.HEADER : _param_authMode, sdkVersion = param.sdkVersion, forwardMPCClient = param.forwardMPCClient, logger = param.logger;
|
|
1446
|
+
_class_call_check(this, DynamicAleoWalletClient);
|
|
1447
|
+
var _this;
|
|
1448
|
+
_this = _call_super(this, DynamicAleoWalletClient, [
|
|
1449
|
+
{
|
|
1450
|
+
environmentId: environmentId,
|
|
1451
|
+
authToken: authToken,
|
|
1452
|
+
baseApiUrl: baseApiUrl,
|
|
1453
|
+
baseMPCRelayApiUrl: baseMPCRelayApiUrl,
|
|
1454
|
+
storageKey: storageKey,
|
|
1455
|
+
debug: debug,
|
|
1456
|
+
featureFlags: featureFlags,
|
|
1457
|
+
authMode: authMode,
|
|
1458
|
+
sdkVersion: sdkVersion,
|
|
1459
|
+
forwardMPCClient: forwardMPCClient,
|
|
1460
|
+
logger: logger
|
|
1461
|
+
},
|
|
1462
|
+
internalOptions
|
|
1463
|
+
]), _define_property(_this, "chainName", 'ALEO'), /**
|
|
1464
|
+
* Cached ProgramManager per Aleo network. The SDK ships separate
|
|
1465
|
+
* mainnet/testnet builds (`@provablehq/sdk/{mainnet,testnet}.js`) that
|
|
1466
|
+
* export network-specific class identities — `ExecutionRequest`,
|
|
1467
|
+
* `ProvingRequest`, etc. each network's prebundle has its own constructor.
|
|
1468
|
+
* `provingRequest` validates `executionRequest instanceof ExecutionRequest`
|
|
1469
|
+
* against the manager's own SDK build, so a manager constructed from the
|
|
1470
|
+
* testnet build will reject a mainnet-built executionRequest (silently
|
|
1471
|
+
* falling into the no-executionRequest branch and throwing a misleading
|
|
1472
|
+
* "No private key provided" error). Caching per network keeps both
|
|
1473
|
+
* builds available and ensures the manager and the executionRequest
|
|
1474
|
+
* always come from the same SDK build.
|
|
1475
|
+
*/ _define_property(_this, "programManagersByNetwork", new Map()), /**
|
|
1476
|
+
* Cached RecordScanner instances per Aleo network. Each entry talks to a
|
|
1477
|
+
* single network's scanner endpoint with a single network-specific SDK
|
|
1478
|
+
* build (`@provablehq/sdk/{testnet,mainnet}.js`). Per-wallet identity is
|
|
1479
|
+
* via the scanner UUID cached in walletStateStorage (also keyed by
|
|
1480
|
+
* network). Scanner credentials (apiKey, consumerId) are shared across
|
|
1481
|
+
* networks. The SDK handles JWT refresh automatically.
|
|
1482
|
+
*/ _define_property(_this, "scannersByNetwork", new Map()), /**
|
|
1483
|
+
* Cached `FeemasterClient` per Aleo network. Each instance holds an in-
|
|
1484
|
+
* memory policy cache (5 min TTL) and delegates HTTP work to the
|
|
1485
|
+
* inherited `this.apiClient` — the same `DynamicApiClient` every other
|
|
1486
|
+
* iframe→redcoast call uses. So baseApiUrl, auth headers, traceContext
|
|
1487
|
+
* propagation, etc. all come from the existing plumbing for free.
|
|
1488
|
+
*/ _define_property(_this, "feemasterClients", new Map()), /**
|
|
1489
|
+
* In-memory cache of program checksums keyed by `${network}:${programId}`.
|
|
1490
|
+
* The Aleo VM's external-signing path requires a non-null `program_checksum`
|
|
1491
|
+
* for any program with a constructor (i.e. anything other than credits.aleo
|
|
1492
|
+
* in our universe). The checksum is immutable for a given deployed program
|
|
1493
|
+
* edition, so we fetch once per session and reuse. Persistence not needed —
|
|
1494
|
+
* a single network round-trip on first use is cheap.
|
|
1495
|
+
*/ _define_property(_this, "programChecksumCache", new Map()), /**
|
|
1496
|
+
* Single-flight guard for `findOwnedRecords`, keyed by accountAddress.
|
|
1497
|
+
* The widget's Shielded tab + the demo's "List my records" button can fire
|
|
1498
|
+
* concurrent record scans on the same wallet; without dedup, multiple
|
|
1499
|
+
* findRecords calls race against a stale cached UUID and serially trip
|
|
1500
|
+
* UUIDErrors. With dedup, all concurrent callers await the same in-flight
|
|
1501
|
+
* promise and the recovery path runs at most once.
|
|
1502
|
+
*/ _define_property(_this, "pendingFindOwnedRecords", new Map());
|
|
1503
|
+
return _this;
|
|
1504
|
+
}
|
|
1505
|
+
_create_class(DynamicAleoWalletClient, [
|
|
1506
|
+
{
|
|
1507
|
+
key: "createWalletAccount",
|
|
1508
|
+
value: function createWalletAccount(param) {
|
|
1509
|
+
var thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, onError = param.onError, signedSessionId = param.signedSessionId;
|
|
1510
|
+
var _this = this;
|
|
1511
|
+
return _async_to_generator(function() {
|
|
1512
|
+
var ceremonyCompleteResolver, ceremonyCompletePromise, serverAccountAddress, _ref, rawPublicKey, clientKeyShares, firstShare, accountAddress, publicKeyHex, pubKeyBytes, error, detail;
|
|
1513
|
+
return _ts_generator(this, function(_state) {
|
|
1514
|
+
switch(_state.label){
|
|
1515
|
+
case 0:
|
|
1516
|
+
_state.trys.push([
|
|
1517
|
+
0,
|
|
1518
|
+
5,
|
|
1519
|
+
,
|
|
1520
|
+
6
|
|
1521
|
+
]);
|
|
1522
|
+
ceremonyCompletePromise = new Promise(function(resolve) {
|
|
1523
|
+
ceremonyCompleteResolver = resolve;
|
|
1524
|
+
});
|
|
1525
|
+
return [
|
|
1526
|
+
4,
|
|
1527
|
+
_this.keyGen({
|
|
1528
|
+
chainName: _this.chainName,
|
|
1529
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
1530
|
+
onError: onError,
|
|
1531
|
+
onCeremonyComplete: function(accountAddress, walletId) {
|
|
1532
|
+
var chainConfig = browser.getMPCChainConfig(_this.chainName);
|
|
1533
|
+
serverAccountAddress = accountAddress;
|
|
1534
|
+
_this.initializeWalletMapEntry({
|
|
1535
|
+
accountAddress: accountAddress,
|
|
1536
|
+
walletId: walletId,
|
|
1537
|
+
chainName: _this.chainName,
|
|
1538
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
1539
|
+
derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map(function(value, index) {
|
|
1540
|
+
return [
|
|
1541
|
+
index,
|
|
1542
|
+
value
|
|
1543
|
+
];
|
|
1544
|
+
})))
|
|
1545
|
+
});
|
|
1546
|
+
ceremonyCompleteResolver(undefined);
|
|
1547
|
+
},
|
|
1548
|
+
password: password,
|
|
1549
|
+
signedSessionId: signedSessionId
|
|
1550
|
+
})
|
|
1551
|
+
];
|
|
1552
|
+
case 1:
|
|
1553
|
+
_ref = _state.sent(), rawPublicKey = _ref.rawPublicKey, clientKeyShares = _ref.clientKeyShares;
|
|
1554
|
+
return [
|
|
1555
|
+
4,
|
|
1556
|
+
ceremonyCompletePromise
|
|
1557
|
+
];
|
|
1558
|
+
case 2:
|
|
1559
|
+
_state.sent();
|
|
1560
|
+
if (!clientKeyShares || clientKeyShares.length === 0) {
|
|
1561
|
+
throw new Error(ERROR_KEYGEN_FAILED);
|
|
1562
|
+
}
|
|
1563
|
+
// Aleo addresses come from the Sodot EdBls12377 keygen result directly
|
|
1564
|
+
// (keygenResult.address is the bech32 `aleo1...` address).
|
|
1565
|
+
// Prefer the server-provided address if present; otherwise read from the local keygen result.
|
|
1566
|
+
firstShare = clientKeyShares[0];
|
|
1567
|
+
accountAddress = serverAccountAddress !== null && serverAccountAddress !== void 0 ? serverAccountAddress : firstShare.address;
|
|
1568
|
+
if (!accountAddress) {
|
|
1569
|
+
throw new Error(ERROR_KEYGEN_FAILED);
|
|
1570
|
+
}
|
|
1571
|
+
return [
|
|
1572
|
+
4,
|
|
1573
|
+
_this.setClientKeySharesToStorage({
|
|
1574
|
+
accountAddress: accountAddress,
|
|
1575
|
+
clientKeyShares: clientKeyShares,
|
|
1576
|
+
overwriteOrMerge: 'overwrite'
|
|
1577
|
+
})
|
|
1578
|
+
];
|
|
1579
|
+
case 3:
|
|
1580
|
+
_state.sent();
|
|
1581
|
+
return [
|
|
1582
|
+
4,
|
|
1583
|
+
_this.storeEncryptedBackupByWallet({
|
|
1584
|
+
accountAddress: accountAddress,
|
|
1585
|
+
clientKeyShares: clientKeyShares,
|
|
1586
|
+
password: password,
|
|
1587
|
+
signedSessionId: signedSessionId
|
|
1588
|
+
})
|
|
1589
|
+
];
|
|
1590
|
+
case 4:
|
|
1591
|
+
_state.sent();
|
|
1592
|
+
// For Aleo, `rawPublicKey` from the base keygen is the EdBls12377 computeKey hex.
|
|
1593
|
+
// There's no separate public-key-to-address derivation — the address is baked into
|
|
1594
|
+
// the keygen result. Keep the hex for backup/reconstruction purposes.
|
|
1595
|
+
publicKeyHex = typeof rawPublicKey === 'string' ? rawPublicKey : '';
|
|
1596
|
+
pubKeyBytes = publicKeyHex ? Buffer.from(publicKeyHex, 'hex') : new Uint8Array();
|
|
1597
|
+
return [
|
|
1598
|
+
2,
|
|
1599
|
+
{
|
|
1600
|
+
accountAddress: accountAddress,
|
|
1601
|
+
publicKeyHex: publicKeyHex,
|
|
1602
|
+
rawPublicKey: new Uint8Array(pubKeyBytes)
|
|
1603
|
+
}
|
|
1604
|
+
];
|
|
1605
|
+
case 5:
|
|
1606
|
+
error = _state.sent();
|
|
1607
|
+
if (_instanceof(error, Error) && error.message === browser.ERROR_PASSWORD_MISMATCH) {
|
|
1608
|
+
throw error;
|
|
1609
|
+
}
|
|
1610
|
+
_this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
1611
|
+
detail = _instanceof(error, Error) ? error.message : String(error);
|
|
1612
|
+
throw new Error("".concat(ERROR_CREATE_WALLET_ACCOUNT, ": ").concat(detail));
|
|
1613
|
+
case 6:
|
|
1614
|
+
return [
|
|
1615
|
+
2
|
|
1616
|
+
];
|
|
1617
|
+
}
|
|
1618
|
+
});
|
|
1619
|
+
})();
|
|
1620
|
+
}
|
|
1621
|
+
},
|
|
1622
|
+
{
|
|
1623
|
+
key: "signMessage",
|
|
1624
|
+
value: // Phase 1 does not implement arbitrary-message signing for Aleo.
|
|
1625
|
+
// Sodot's EdBls12377 signer only exposes `signRequest(payload)` for Aleo transaction
|
|
1626
|
+
// authorization today — no plain `sign(bytes)` for native Aleo Schnorr signatures.
|
|
1627
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1628
|
+
function signMessage(_args) {
|
|
1629
|
+
return _async_to_generator(function() {
|
|
1630
|
+
return _ts_generator(this, function(_state) {
|
|
1631
|
+
throw new Error(ERROR_SIGN_MESSAGE_NOT_SUPPORTED);
|
|
1632
|
+
});
|
|
1633
|
+
})();
|
|
1634
|
+
}
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
key: "signTransaction",
|
|
1638
|
+
value: // signTransaction for Aleo uses the Sodot EdBls12377 `signRequest` ceremony.
|
|
1639
|
+
// That ceremony isn't wired up yet — coming in Phase 2 alongside transfer_public
|
|
1640
|
+
// and the other credits.aleo functions.
|
|
1641
|
+
function signTransaction(args) {
|
|
1642
|
+
return _async_to_generator(function() {
|
|
1643
|
+
return _ts_generator(this, function(_state) {
|
|
1644
|
+
if (!(args === null || args === void 0 ? void 0 : args.accountAddress)) {
|
|
1645
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
1646
|
+
}
|
|
1647
|
+
throw new Error(ERROR_SIGN_TRANSACTION_NOT_SUPPORTED);
|
|
1648
|
+
});
|
|
1649
|
+
})();
|
|
1650
|
+
}
|
|
1651
|
+
},
|
|
1652
|
+
{
|
|
1653
|
+
key: "exportPrivateKey",
|
|
1654
|
+
value: function exportPrivateKey(param) {
|
|
1655
|
+
var accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
1656
|
+
var _this = this;
|
|
1657
|
+
return _async_to_generator(function() {
|
|
1658
|
+
var derivedPrivateKey, error;
|
|
1659
|
+
return _ts_generator(this, function(_state) {
|
|
1660
|
+
switch(_state.label){
|
|
1661
|
+
case 0:
|
|
1662
|
+
_state.trys.push([
|
|
1663
|
+
0,
|
|
1664
|
+
2,
|
|
1665
|
+
,
|
|
1666
|
+
3
|
|
1667
|
+
]);
|
|
1668
|
+
if (!accountAddress) {
|
|
1669
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
1670
|
+
}
|
|
1671
|
+
return [
|
|
1672
|
+
4,
|
|
1673
|
+
_this.exportKey({
|
|
1674
|
+
accountAddress: accountAddress,
|
|
1675
|
+
chainName: _this.chainName,
|
|
1676
|
+
password: password,
|
|
1677
|
+
signedSessionId: signedSessionId,
|
|
1678
|
+
mfaToken: mfaToken,
|
|
1679
|
+
elevatedAccessToken: elevatedAccessToken
|
|
1680
|
+
})
|
|
1681
|
+
];
|
|
1682
|
+
case 1:
|
|
1683
|
+
derivedPrivateKey = _state.sent().derivedPrivateKey;
|
|
1684
|
+
if (!derivedPrivateKey) {
|
|
1685
|
+
throw new Error('Derived private key is undefined');
|
|
1686
|
+
}
|
|
1687
|
+
// For Aleo, `derivedPrivateKey` is the raw hex scalar produced by Sodot's
|
|
1688
|
+
// EdBls12377 exportFullPrivateKey. Aleo's canonical format is `APrivateKey1...`
|
|
1689
|
+
// (bech32-encoded via @provablehq/sdk). Encoding to that format requires the
|
|
1690
|
+
// Provable SDK and is done by the consumer (connector) for now.
|
|
1691
|
+
return [
|
|
1692
|
+
2,
|
|
1693
|
+
derivedPrivateKey
|
|
1694
|
+
];
|
|
1695
|
+
case 2:
|
|
1696
|
+
error = _state.sent();
|
|
1697
|
+
if (_instanceof(error, Error) && error.message === browser.ERROR_PASSWORD_MISMATCH) {
|
|
1698
|
+
throw error;
|
|
1699
|
+
}
|
|
1700
|
+
_this.logger.error(ERROR_EXPORT_PRIVATE_KEY, error);
|
|
1701
|
+
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
|
1702
|
+
case 3:
|
|
1703
|
+
return [
|
|
1704
|
+
2
|
|
1705
|
+
];
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
})();
|
|
1709
|
+
}
|
|
1710
|
+
},
|
|
1711
|
+
{
|
|
1712
|
+
key: "importPrivateKey",
|
|
1713
|
+
value: // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1714
|
+
function importPrivateKey(_args) {
|
|
1715
|
+
return _async_to_generator(function() {
|
|
1716
|
+
return _ts_generator(this, function(_state) {
|
|
1717
|
+
throw new Error(ERROR_IMPORT_PRIVATE_KEY_NOT_SUPPORTED);
|
|
1718
|
+
});
|
|
1719
|
+
})();
|
|
1720
|
+
}
|
|
1721
|
+
},
|
|
1722
|
+
{
|
|
1723
|
+
key: "getAleoWallets",
|
|
1724
|
+
value: function getAleoWallets() {
|
|
1725
|
+
var _this = this;
|
|
1726
|
+
return _async_to_generator(function() {
|
|
1727
|
+
var wallets;
|
|
1728
|
+
return _ts_generator(this, function(_state) {
|
|
1729
|
+
switch(_state.label){
|
|
1730
|
+
case 0:
|
|
1731
|
+
return [
|
|
1732
|
+
4,
|
|
1733
|
+
_this.getWallets()
|
|
1734
|
+
];
|
|
1735
|
+
case 1:
|
|
1736
|
+
wallets = _state.sent();
|
|
1737
|
+
return [
|
|
1738
|
+
2,
|
|
1739
|
+
wallets.filter(function(wallet) {
|
|
1740
|
+
return wallet.chainName === _this.chainName;
|
|
1741
|
+
})
|
|
1742
|
+
];
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
})();
|
|
1746
|
+
}
|
|
1747
|
+
},
|
|
1748
|
+
{
|
|
1749
|
+
key: "signAleoRequest",
|
|
1750
|
+
value: /**
|
|
1751
|
+
* Runs the Aleo signRequest MPC ceremony for the given structured payload.
|
|
1752
|
+
* The payload is Sodot's `EdBls12377RequestSignPayload` shape:
|
|
1753
|
+
* { function_id, is_root, program_checksum, inputs: [...] }.
|
|
1754
|
+
* Returns the signed request with { signature, tvk, signer, gammas? } which
|
|
1755
|
+
* the caller passes to `buildExecutionRequestFromExternallySignedData` to
|
|
1756
|
+
* produce an ExecutionRequest for proving via Provable DPS.
|
|
1757
|
+
*/ function signAleoRequest(param) {
|
|
1758
|
+
var accountAddress = param.accountAddress, payload = param.payload, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
1759
|
+
var _this = this;
|
|
1760
|
+
return _async_to_generator(function() {
|
|
1761
|
+
var wallet, mpcSigner, reconstructedKeyShare, wirePayload, roomId, signedRequest;
|
|
1762
|
+
return _ts_generator(this, function(_state) {
|
|
1763
|
+
switch(_state.label){
|
|
1764
|
+
case 0:
|
|
1765
|
+
if (!accountAddress) {
|
|
1766
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
1767
|
+
}
|
|
1768
|
+
return [
|
|
1769
|
+
4,
|
|
1770
|
+
_this.verifyPassword({
|
|
1771
|
+
accountAddress: accountAddress,
|
|
1772
|
+
password: password,
|
|
1773
|
+
signedSessionId: signedSessionId
|
|
1774
|
+
})
|
|
1775
|
+
];
|
|
1776
|
+
case 1:
|
|
1777
|
+
_state.sent();
|
|
1778
|
+
return [
|
|
1779
|
+
4,
|
|
1780
|
+
_this.getWallet({
|
|
1781
|
+
accountAddress: accountAddress,
|
|
1782
|
+
password: password,
|
|
1783
|
+
signedSessionId: signedSessionId
|
|
1784
|
+
})
|
|
1785
|
+
];
|
|
1786
|
+
case 2:
|
|
1787
|
+
wallet = _state.sent();
|
|
1788
|
+
mpcSigner = browser.getMPCSigner({
|
|
1789
|
+
chainName: _this.chainName,
|
|
1790
|
+
baseRelayUrl: _this.baseMPCRelayApiUrl
|
|
1791
|
+
});
|
|
1792
|
+
return [
|
|
1793
|
+
4,
|
|
1794
|
+
_this.getReconstructedKeyShare(accountAddress, mpcSigner)
|
|
1795
|
+
];
|
|
1796
|
+
case 3:
|
|
1797
|
+
reconstructedKeyShare = _state.sent();
|
|
1798
|
+
// HTTP transport cannot carry Uint8Arrays — hex-encode for the wire.
|
|
1799
|
+
// The server decodes back to Uint8Array before calling Sodot, so both
|
|
1800
|
+
// parties end up signing the same byte arrays.
|
|
1801
|
+
wirePayload = (typeof payload === "undefined" ? "undefined" : _type_of(payload)) === 'object' && payload !== null && 'function_id' in payload ? _this.encodePayloadForTransport(payload) : payload;
|
|
1802
|
+
return [
|
|
1803
|
+
4,
|
|
1804
|
+
_this.apiClient.signAleoRequest({
|
|
1805
|
+
walletId: wallet.walletId,
|
|
1806
|
+
payload: wirePayload,
|
|
1807
|
+
mfaToken: mfaToken,
|
|
1808
|
+
elevatedAccessToken: elevatedAccessToken
|
|
1809
|
+
})
|
|
1810
|
+
];
|
|
1811
|
+
case 4:
|
|
1812
|
+
roomId = _state.sent().roomId;
|
|
1813
|
+
return [
|
|
1814
|
+
4,
|
|
1815
|
+
mpcSigner.signRequest(roomId, reconstructedKeyShare, payload)
|
|
1816
|
+
];
|
|
1817
|
+
case 5:
|
|
1818
|
+
signedRequest = _state.sent();
|
|
1819
|
+
if (!signedRequest) {
|
|
1820
|
+
throw new Error('Aleo signRequest returned empty — MPC ceremony failed');
|
|
1821
|
+
}
|
|
1822
|
+
return [
|
|
1823
|
+
2,
|
|
1824
|
+
signedRequest
|
|
1825
|
+
];
|
|
1826
|
+
}
|
|
1827
|
+
});
|
|
1828
|
+
})();
|
|
1829
|
+
}
|
|
1830
|
+
},
|
|
1831
|
+
{
|
|
1832
|
+
key: "getViewKeyCacheStorageKey",
|
|
1833
|
+
value: /**
|
|
1834
|
+
* LocalStorage key for caching the per-account Aleo view key in the iframe.
|
|
1835
|
+
* Scoped to iframe origin — the DApp cannot read this via same-origin policy.
|
|
1836
|
+
*/ function getViewKeyCacheStorageKey(accountAddress) {
|
|
1837
|
+
return "dynamic-aleo-view-key:".concat(accountAddress);
|
|
1838
|
+
}
|
|
1839
|
+
},
|
|
1840
|
+
{
|
|
1841
|
+
key: "exportViewKey",
|
|
1842
|
+
value: /**
|
|
1843
|
+
* Returns the Aleo view key for the given account. On first call runs the
|
|
1844
|
+
* asymmetric exportViewKey MPC ceremony (client receives, server gets
|
|
1845
|
+
* nothing) and caches the result in iframe localStorage. Subsequent calls
|
|
1846
|
+
* return the cached value. View key never leaves the iframe — it is NOT
|
|
1847
|
+
* postMessage'd to the DApp.
|
|
1848
|
+
*/ function exportViewKey(param) {
|
|
1849
|
+
var accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
1850
|
+
var _this = this;
|
|
1851
|
+
return _async_to_generator(function() {
|
|
1852
|
+
var cacheKey, _globalThis_localStorage, cached, wallet, mpcSigner, reconstructedKeyShare, exportId, roomId, viewKey, _globalThis_localStorage1;
|
|
1853
|
+
return _ts_generator(this, function(_state) {
|
|
1854
|
+
switch(_state.label){
|
|
1855
|
+
case 0:
|
|
1856
|
+
if (!accountAddress) {
|
|
1857
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
1858
|
+
}
|
|
1859
|
+
cacheKey = _this.getViewKeyCacheStorageKey(accountAddress);
|
|
1860
|
+
try {
|
|
1861
|
+
;
|
|
1862
|
+
cached = (_globalThis_localStorage = globalThis.localStorage) === null || _globalThis_localStorage === void 0 ? void 0 : _globalThis_localStorage.getItem(cacheKey);
|
|
1863
|
+
if (cached) return [
|
|
1864
|
+
2,
|
|
1865
|
+
cached
|
|
1866
|
+
];
|
|
1867
|
+
} catch (e) {
|
|
1868
|
+
// localStorage unavailable (SSR / sandboxed) — fall through to ceremony.
|
|
1869
|
+
}
|
|
1870
|
+
return [
|
|
1871
|
+
4,
|
|
1872
|
+
_this.verifyPassword({
|
|
1873
|
+
accountAddress: accountAddress,
|
|
1874
|
+
password: password,
|
|
1875
|
+
signedSessionId: signedSessionId
|
|
1876
|
+
})
|
|
1877
|
+
];
|
|
1878
|
+
case 1:
|
|
1879
|
+
_state.sent();
|
|
1880
|
+
return [
|
|
1881
|
+
4,
|
|
1882
|
+
_this.getWallet({
|
|
1883
|
+
accountAddress: accountAddress,
|
|
1884
|
+
password: password,
|
|
1885
|
+
signedSessionId: signedSessionId
|
|
1886
|
+
})
|
|
1887
|
+
];
|
|
1888
|
+
case 2:
|
|
1889
|
+
wallet = _state.sent();
|
|
1890
|
+
// Re-use the base-class MPC signer + key-share reconstruction so this path
|
|
1891
|
+
// doesn't duplicate storage logic. The mpcSigner here is an EdBls12377.
|
|
1892
|
+
mpcSigner = browser.getMPCSigner({
|
|
1893
|
+
chainName: _this.chainName,
|
|
1894
|
+
baseRelayUrl: _this.baseMPCRelayApiUrl
|
|
1895
|
+
});
|
|
1896
|
+
return [
|
|
1897
|
+
4,
|
|
1898
|
+
_this.getReconstructedKeyShare(accountAddress, mpcSigner)
|
|
1899
|
+
];
|
|
1900
|
+
case 3:
|
|
1901
|
+
reconstructedKeyShare = _state.sent();
|
|
1902
|
+
return [
|
|
1903
|
+
4,
|
|
1904
|
+
_this.getExportId({
|
|
1905
|
+
chainName: _this.chainName,
|
|
1906
|
+
clientKeyShare: reconstructedKeyShare
|
|
1907
|
+
})
|
|
1908
|
+
];
|
|
1909
|
+
case 4:
|
|
1910
|
+
exportId = _state.sent();
|
|
1911
|
+
return [
|
|
1912
|
+
4,
|
|
1913
|
+
_this.apiClient.exportAleoViewKey({
|
|
1914
|
+
walletId: wallet.walletId,
|
|
1915
|
+
exportId: exportId,
|
|
1916
|
+
mfaToken: mfaToken,
|
|
1917
|
+
elevatedAccessToken: elevatedAccessToken
|
|
1918
|
+
})
|
|
1919
|
+
];
|
|
1920
|
+
case 5:
|
|
1921
|
+
roomId = _state.sent().roomId;
|
|
1922
|
+
return [
|
|
1923
|
+
4,
|
|
1924
|
+
mpcSigner.exportViewKey(roomId, reconstructedKeyShare, exportId)
|
|
1925
|
+
];
|
|
1926
|
+
case 6:
|
|
1927
|
+
viewKey = _state.sent();
|
|
1928
|
+
if (!viewKey) {
|
|
1929
|
+
throw new Error('Aleo view key export returned empty — MPC ceremony failed');
|
|
1930
|
+
}
|
|
1931
|
+
try {
|
|
1932
|
+
;
|
|
1933
|
+
(_globalThis_localStorage1 = globalThis.localStorage) === null || _globalThis_localStorage1 === void 0 ? void 0 : _globalThis_localStorage1.setItem(cacheKey, viewKey);
|
|
1934
|
+
} catch (e) {
|
|
1935
|
+
// best-effort cache — fine to proceed without persistence.
|
|
1936
|
+
}
|
|
1937
|
+
return [
|
|
1938
|
+
2,
|
|
1939
|
+
viewKey
|
|
1940
|
+
];
|
|
1941
|
+
}
|
|
1942
|
+
});
|
|
1943
|
+
})();
|
|
1944
|
+
}
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
key: "toRequestSignPayload",
|
|
1948
|
+
value: /**
|
|
1949
|
+
* Convert a Provable `ExternalSigningInput<'bytes'>` into the Sodot
|
|
1950
|
+
* EdBls12377 signing payload shape. Mirrors the playground helper.
|
|
1951
|
+
* All Uint8Array fields are preserved — this shape is passed directly to
|
|
1952
|
+
* `mpcSigner.signRequest` locally. For HTTP transport, use
|
|
1953
|
+
* `encodePayloadForTransport` to hex-encode the byte fields.
|
|
1954
|
+
*/ function toRequestSignPayload(signingInputs) {
|
|
1955
|
+
var _signingInputs_checksum;
|
|
1956
|
+
return {
|
|
1957
|
+
function_id: signingInputs.functionId,
|
|
1958
|
+
is_root: signingInputs.isRoot,
|
|
1959
|
+
program_checksum: (_signingInputs_checksum = signingInputs.checksum) !== null && _signingInputs_checksum !== void 0 ? _signingInputs_checksum : null,
|
|
1960
|
+
inputs: signingInputs.requestInputs.map(function(requestInput) {
|
|
1961
|
+
if (requestInput.signingInputType === 'record') {
|
|
1962
|
+
return {
|
|
1963
|
+
type: 'record',
|
|
1964
|
+
h: requestInput.h,
|
|
1965
|
+
tag: requestInput.tag
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
return {
|
|
1969
|
+
type: requestInput.signingInputType,
|
|
1970
|
+
index: requestInput.index,
|
|
1971
|
+
fields: requestInput.data
|
|
1972
|
+
};
|
|
1973
|
+
})
|
|
1974
|
+
};
|
|
1975
|
+
}
|
|
1976
|
+
},
|
|
1977
|
+
{
|
|
1978
|
+
key: "encodePayloadForTransport",
|
|
1979
|
+
value: /**
|
|
1980
|
+
* Hex-encode the Uint8Array fields of an EdBls12377 signing payload so it
|
|
1981
|
+
* can travel through JSON HTTP without loss. Mirror of
|
|
1982
|
+
* `decodeAleoSigningPayload` in wallet-service — both sides must agree on
|
|
1983
|
+
* the wire format so the MPC ceremony sees identical byte arrays.
|
|
1984
|
+
*/ function encodePayloadForTransport(payload) {
|
|
1985
|
+
var u8ToHex = function(u8) {
|
|
1986
|
+
return Array.from(u8, function(b) {
|
|
1987
|
+
return b.toString(16).padStart(2, '0');
|
|
1988
|
+
}).join('');
|
|
1989
|
+
};
|
|
1990
|
+
return {
|
|
1991
|
+
function_id: u8ToHex(payload.function_id),
|
|
1992
|
+
is_root: payload.is_root,
|
|
1993
|
+
program_checksum: payload.program_checksum == null ? null : u8ToHex(payload.program_checksum),
|
|
1994
|
+
inputs: payload.inputs.map(function(input) {
|
|
1995
|
+
if (input.type === 'record') {
|
|
1996
|
+
return {
|
|
1997
|
+
type: 'record',
|
|
1998
|
+
h: u8ToHex(input.h),
|
|
1999
|
+
tag: u8ToHex(input.tag)
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
return {
|
|
2003
|
+
type: input.type,
|
|
2004
|
+
index: u8ToHex(input.index),
|
|
2005
|
+
fields: input.fields.map(function(f) {
|
|
2006
|
+
return u8ToHex(f);
|
|
2007
|
+
})
|
|
2008
|
+
};
|
|
2009
|
+
})
|
|
2010
|
+
};
|
|
2011
|
+
}
|
|
2012
|
+
},
|
|
2013
|
+
{
|
|
2014
|
+
key: "getProgramChecksum",
|
|
2015
|
+
value: /**
|
|
2016
|
+
* Fetches the on-chain `program_checksum` for a deployed program and
|
|
2017
|
+
* returns it as a 32-byte `Uint8Array` ready to feed into
|
|
2018
|
+
* `computeExternalSigningInputs({ checksum })` and Sodot's
|
|
2019
|
+
* `signRequest` payload (`program_checksum` field).
|
|
2020
|
+
*
|
|
2021
|
+
* Why we need this: the Aleo VM's external-signing path checks the
|
|
2022
|
+
* program checksum for any program that has a constructor. Constructor-
|
|
2023
|
+
* less programs (`credits.aleo`, `token_registry.aleo`) deploy without a
|
|
2024
|
+
* `program_checksum` field and work with `checksum: null`. Programs with
|
|
2025
|
+
* a constructor (USAD/USDCx Tier-3 stablecoins, any custom program)
|
|
2026
|
+
* trip a hardcoded `"Program ID must be credits.aleo"` error in the WASM
|
|
2027
|
+
* unless a real checksum is supplied.
|
|
2028
|
+
*
|
|
2029
|
+
* Returns `null` when the deployment has no checksum (constructor-less);
|
|
2030
|
+
* caller is expected to pass that `null` through to `signRequest`.
|
|
2031
|
+
*
|
|
2032
|
+
* Source: the deployment transaction's `deployment.program_checksum`
|
|
2033
|
+
* field, returned as a 32-element array of `<n>u8` literals (e.g.
|
|
2034
|
+
* `["207u8", "221u8", ...]`).
|
|
2035
|
+
*/ function getProgramChecksum(programId, network) {
|
|
2036
|
+
var _this = this;
|
|
2037
|
+
return _async_to_generator(function() {
|
|
2038
|
+
var _txJson_deployment, cacheKey, cached, apiBase, txIdRes, txId, txRes, txJson, checksumU8s, _JSON_stringify, bytes, i, match;
|
|
2039
|
+
return _ts_generator(this, function(_state) {
|
|
2040
|
+
switch(_state.label){
|
|
2041
|
+
case 0:
|
|
2042
|
+
cacheKey = "".concat(network, ":").concat(programId);
|
|
2043
|
+
cached = _this.programChecksumCache.get(cacheKey);
|
|
2044
|
+
if (cached !== undefined) return [
|
|
2045
|
+
2,
|
|
2046
|
+
cached
|
|
2047
|
+
];
|
|
2048
|
+
apiBase = "https://api.explorer.provable.com/v2/".concat(network);
|
|
2049
|
+
return [
|
|
2050
|
+
4,
|
|
2051
|
+
fetch("".concat(apiBase, "/find/transactionID/deployment/").concat(programId))
|
|
2052
|
+
];
|
|
2053
|
+
case 1:
|
|
2054
|
+
txIdRes = _state.sent();
|
|
2055
|
+
if (!txIdRes.ok) {
|
|
2056
|
+
throw new Error("Failed to look up deployment transaction for ".concat(programId, " on ").concat(network, ": HTTP ").concat(txIdRes.status));
|
|
2057
|
+
}
|
|
2058
|
+
return [
|
|
2059
|
+
4,
|
|
2060
|
+
txIdRes.text()
|
|
2061
|
+
];
|
|
2062
|
+
case 2:
|
|
2063
|
+
txId = _state.sent().replaceAll(/^"|"$/g, '').trim();
|
|
2064
|
+
// Aleo deployment transaction IDs are bech32-encoded strings prefixed with
|
|
2065
|
+
// `at1`. Validate before interpolating into the next URL so a corrupted or
|
|
2066
|
+
// malicious upstream response can't redirect the request elsewhere.
|
|
2067
|
+
if (!/^at1[a-z0-9]{40,200}$/.test(txId)) {
|
|
2068
|
+
throw new Error("Invalid deployment transaction ID format for ".concat(programId, ": ").concat(txId.slice(0, 60)));
|
|
2069
|
+
}
|
|
2070
|
+
return [
|
|
2071
|
+
4,
|
|
2072
|
+
fetch("".concat(apiBase, "/transaction/").concat(txId))
|
|
2073
|
+
];
|
|
2074
|
+
case 3:
|
|
2075
|
+
txRes = _state.sent();
|
|
2076
|
+
if (!txRes.ok) {
|
|
2077
|
+
throw new Error("Failed to fetch deployment transaction ".concat(txId, ": HTTP ").concat(txRes.status));
|
|
2078
|
+
}
|
|
2079
|
+
return [
|
|
2080
|
+
4,
|
|
2081
|
+
txRes.json()
|
|
2082
|
+
];
|
|
2083
|
+
case 4:
|
|
2084
|
+
txJson = _state.sent();
|
|
2085
|
+
checksumU8s = txJson === null || txJson === void 0 ? void 0 : (_txJson_deployment = txJson.deployment) === null || _txJson_deployment === void 0 ? void 0 : _txJson_deployment.program_checksum;
|
|
2086
|
+
if (checksumU8s == null) {
|
|
2087
|
+
// Constructor-less program — checksum is genuinely absent on-chain.
|
|
2088
|
+
_this.programChecksumCache.set(cacheKey, null);
|
|
2089
|
+
return [
|
|
2090
|
+
2,
|
|
2091
|
+
null
|
|
2092
|
+
];
|
|
2093
|
+
}
|
|
2094
|
+
if (!Array.isArray(checksumU8s) || checksumU8s.length !== 32) {
|
|
2095
|
+
throw new Error("Unexpected program_checksum shape for ".concat(programId, ": expected 32-byte array, got ").concat((_JSON_stringify = JSON.stringify(checksumU8s)) === null || _JSON_stringify === void 0 ? void 0 : _JSON_stringify.slice(0, 100)));
|
|
2096
|
+
}
|
|
2097
|
+
bytes = new Uint8Array(32);
|
|
2098
|
+
for(i = 0; i < 32; i += 1){
|
|
2099
|
+
match = /^(\d+)u8$/.exec(String(checksumU8s[i]));
|
|
2100
|
+
if (!match) {
|
|
2101
|
+
throw new Error("Invalid u8 literal at index ".concat(i, " of program_checksum for ").concat(programId, ": ").concat(checksumU8s[i]));
|
|
2102
|
+
}
|
|
2103
|
+
bytes[i] = Number.parseInt(match[1], 10);
|
|
2104
|
+
}
|
|
2105
|
+
_this.programChecksumCache.set(cacheKey, bytes);
|
|
2106
|
+
return [
|
|
2107
|
+
2,
|
|
2108
|
+
bytes
|
|
2109
|
+
];
|
|
2110
|
+
}
|
|
2111
|
+
});
|
|
2112
|
+
})();
|
|
2113
|
+
}
|
|
2114
|
+
},
|
|
2115
|
+
{
|
|
2116
|
+
key: "getSealanceProof",
|
|
2117
|
+
value: /**
|
|
2118
|
+
* Computes (or returns from cache) the Sealance Merkle exclusion proof
|
|
2119
|
+
* for `accountAddress` against the given freezelist program's tree.
|
|
2120
|
+
*
|
|
2121
|
+
* The Sealance flow proves the sender is *not* on the freeze list. Recipe:
|
|
2122
|
+
* 1. Fetch the BigInt-string tree at
|
|
2123
|
+
* `/v2/{network}/programs/{freezelist}/compliance/freeze-list`.
|
|
2124
|
+
* 2. `tree[tree.length - 1]` is the Merkle root.
|
|
2125
|
+
* 3. `convertTreeToBigInt` → `getLeafIndices(addr)` → 2× `getSiblingPath`
|
|
2126
|
+
* → `formatMerkleProof` produces the formatted `[MerkleProof; 2u32]` literal.
|
|
2127
|
+
*
|
|
2128
|
+
* Cached per (accountAddress, freezelistProgram, root). On the next spend
|
|
2129
|
+
* we only refetch the tree and rebuild when the root has changed.
|
|
2130
|
+
*/ function getSealanceProof(param) {
|
|
2131
|
+
var accountAddress = param.accountAddress, freezelistProgram = param.freezelistProgram, network = param.network;
|
|
2132
|
+
return _async_to_generator(function() {
|
|
2133
|
+
var url, response, treeStrings, currentRoot, cached, _cached_sealanceProofs, cachedProofs, cachedEntry, sdk, sealance, tree, _sealance_getLeafIndices, leftIdx, rightIdx, proofLeft, proofRight, formattedProof, _cached_records, _cached_spentNonces, _cached_lastScannedBlock;
|
|
2134
|
+
return _ts_generator(this, function(_state) {
|
|
2135
|
+
switch(_state.label){
|
|
2136
|
+
case 0:
|
|
2137
|
+
// Defense-in-depth: TS types don't enforce at runtime, so validate the
|
|
2138
|
+
// path segments before interpolating into the explorer URL.
|
|
2139
|
+
if (network !== 'testnet' && network !== 'mainnet') {
|
|
2140
|
+
throw new Error("Invalid network for Sealance proof: ".concat(network));
|
|
2141
|
+
}
|
|
2142
|
+
if (!/^\w+\.aleo$/.test(freezelistProgram)) {
|
|
2143
|
+
throw new Error("Invalid freezelist program ID: ".concat(freezelistProgram));
|
|
2144
|
+
}
|
|
2145
|
+
url = "https://api.explorer.provable.com/v2/".concat(network, "/programs/").concat(freezelistProgram, "/compliance/freeze-list");
|
|
2146
|
+
return [
|
|
2147
|
+
4,
|
|
2148
|
+
fetch(url)
|
|
2149
|
+
];
|
|
2150
|
+
case 1:
|
|
2151
|
+
response = _state.sent();
|
|
2152
|
+
if (!response.ok) {
|
|
2153
|
+
throw new Error("Failed to fetch Sealance freeze list (".concat(freezelistProgram, ", ").concat(network, "): HTTP ").concat(response.status));
|
|
2154
|
+
}
|
|
2155
|
+
return [
|
|
2156
|
+
4,
|
|
2157
|
+
response.json()
|
|
2158
|
+
];
|
|
2159
|
+
case 2:
|
|
2160
|
+
treeStrings = _state.sent();
|
|
2161
|
+
if (!Array.isArray(treeStrings) || treeStrings.length === 0) {
|
|
2162
|
+
throw new Error("Sealance freeze list response for ".concat(freezelistProgram, " on ").concat(network, " is empty or malformed."));
|
|
2163
|
+
}
|
|
2164
|
+
currentRoot = treeStrings.at(-1);
|
|
2165
|
+
return [
|
|
2166
|
+
4,
|
|
2167
|
+
getWalletState(accountAddress, network)
|
|
2168
|
+
];
|
|
2169
|
+
case 3:
|
|
2170
|
+
cached = _state.sent();
|
|
2171
|
+
cachedProofs = (_cached_sealanceProofs = cached === null || cached === void 0 ? void 0 : cached.sealanceProofs) !== null && _cached_sealanceProofs !== void 0 ? _cached_sealanceProofs : {};
|
|
2172
|
+
cachedEntry = cachedProofs[freezelistProgram];
|
|
2173
|
+
if ((cachedEntry === null || cachedEntry === void 0 ? void 0 : cachedEntry.root) === currentRoot) {
|
|
2174
|
+
return [
|
|
2175
|
+
2,
|
|
2176
|
+
cachedEntry.formattedProof
|
|
2177
|
+
];
|
|
2178
|
+
}
|
|
2179
|
+
return [
|
|
2180
|
+
4,
|
|
2181
|
+
loadAleoSdk(network)
|
|
2182
|
+
];
|
|
2183
|
+
case 4:
|
|
2184
|
+
sdk = _state.sent();
|
|
2185
|
+
sealance = new sdk.SealanceMerkleTree();
|
|
2186
|
+
tree = sealance.convertTreeToBigInt(treeStrings);
|
|
2187
|
+
_sealance_getLeafIndices = _sliced_to_array(sealance.getLeafIndices(tree, accountAddress), 2), leftIdx = _sealance_getLeafIndices[0], rightIdx = _sealance_getLeafIndices[1];
|
|
2188
|
+
proofLeft = sealance.getSiblingPath(tree, leftIdx, SEALANCE_TREE_DEPTH);
|
|
2189
|
+
proofRight = sealance.getSiblingPath(tree, rightIdx, SEALANCE_TREE_DEPTH);
|
|
2190
|
+
formattedProof = sealance.formatMerkleProof([
|
|
2191
|
+
proofLeft,
|
|
2192
|
+
proofRight
|
|
2193
|
+
]);
|
|
2194
|
+
return [
|
|
2195
|
+
4,
|
|
2196
|
+
putWalletState(accountAddress, network, {
|
|
2197
|
+
scannerUuid: cached === null || cached === void 0 ? void 0 : cached.scannerUuid,
|
|
2198
|
+
records: (_cached_records = cached === null || cached === void 0 ? void 0 : cached.records) !== null && _cached_records !== void 0 ? _cached_records : '[]',
|
|
2199
|
+
spentNonces: (_cached_spentNonces = cached === null || cached === void 0 ? void 0 : cached.spentNonces) !== null && _cached_spentNonces !== void 0 ? _cached_spentNonces : [],
|
|
2200
|
+
lastScannedBlock: (_cached_lastScannedBlock = cached === null || cached === void 0 ? void 0 : cached.lastScannedBlock) !== null && _cached_lastScannedBlock !== void 0 ? _cached_lastScannedBlock : 0,
|
|
2201
|
+
sealanceProofs: _object_spread_props(_object_spread({}, cachedProofs), _define_property({}, freezelistProgram, {
|
|
2202
|
+
root: currentRoot,
|
|
2203
|
+
formattedProof: formattedProof,
|
|
2204
|
+
computedAt: Date.now()
|
|
2205
|
+
}))
|
|
2206
|
+
})
|
|
2207
|
+
];
|
|
2208
|
+
case 5:
|
|
2209
|
+
_state.sent();
|
|
2210
|
+
return [
|
|
2211
|
+
2,
|
|
2212
|
+
formattedProof
|
|
2213
|
+
];
|
|
2214
|
+
}
|
|
2215
|
+
});
|
|
2216
|
+
})();
|
|
2217
|
+
}
|
|
2218
|
+
},
|
|
2219
|
+
{
|
|
2220
|
+
key: "proveTransaction",
|
|
2221
|
+
value: /**
|
|
2222
|
+
* Full Aleo transaction flow:
|
|
2223
|
+
* viewKey (MPC exported, cached) → computeExternalSigningInputs
|
|
2224
|
+
* → Sodot signAleoRequest MPC ceremony
|
|
2225
|
+
* → buildExecutionRequestFromExternallySignedData
|
|
2226
|
+
* → Provable DPS submitProvingRequest (computes ZK proof + broadcasts)
|
|
2227
|
+
*
|
|
2228
|
+
* Handles both non-record functions (transfer_public) and record-consuming
|
|
2229
|
+
* functions (transfer_private, join, transfer_public_to_private).
|
|
2230
|
+
*
|
|
2231
|
+
* For Sealance-compliant tier-3 stablecoins (USAD, USDCx), the iframe also
|
|
2232
|
+
* auto-fetches/computes the Merkle exclusion proof and appends it to
|
|
2233
|
+
* `inputs`/`inputTypes` when the program/function pair calls for it. The
|
|
2234
|
+
* caller passes the same shape as a credits.aleo transfer.
|
|
2235
|
+
*
|
|
2236
|
+
* @param broadcast - if true, DPS broadcasts the transaction and returns a
|
|
2237
|
+
* txId. If false, DPS returns the proving response and the caller
|
|
2238
|
+
* decides what to do with it.
|
|
2239
|
+
*/ function proveTransaction(param) {
|
|
2240
|
+
var accountAddress = param.accountAddress, programId = param.programId, functionName = param.functionName, inputs = param.inputs, inputTypes = param.inputTypes, _param_broadcast = param.broadcast, broadcast = _param_broadcast === void 0 ? true : _param_broadcast, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, chainId = param.chainId;
|
|
2241
|
+
var _this = this;
|
|
2242
|
+
return _async_to_generator(function() {
|
|
2243
|
+
var viewKey, txNetwork, sdk, programManager, _ref, effectiveInputs, effectiveInputTypes, checksum, signingInputs, payload, signedRequest, executionRequestBase, executionRequest, provingRequest, provingResult, _provingResult_transaction;
|
|
2244
|
+
return _ts_generator(this, function(_state) {
|
|
2245
|
+
switch(_state.label){
|
|
2246
|
+
case 0:
|
|
2247
|
+
if (!accountAddress) {
|
|
2248
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
2249
|
+
}
|
|
2250
|
+
return [
|
|
2251
|
+
4,
|
|
2252
|
+
_this.exportViewKey({
|
|
2253
|
+
accountAddress: accountAddress,
|
|
2254
|
+
password: password,
|
|
2255
|
+
signedSessionId: signedSessionId,
|
|
2256
|
+
mfaToken: mfaToken,
|
|
2257
|
+
elevatedAccessToken: elevatedAccessToken
|
|
2258
|
+
})
|
|
2259
|
+
];
|
|
2260
|
+
case 1:
|
|
2261
|
+
viewKey = _state.sent();
|
|
2262
|
+
// Network resolution: prefer the caller-supplied chainId. The
|
|
2263
|
+
// `networkFromProgramId` heuristic only works for programs whose
|
|
2264
|
+
// name varies by network (`test_` prefix on stablecoins / ARC-21);
|
|
2265
|
+
// it can't disambiguate `credits.aleo`. We trust the caller first
|
|
2266
|
+
// and only fall back to the heuristic when chainId is omitted.
|
|
2267
|
+
txNetwork = chainId !== undefined && chainId !== null ? resolveAleoNetwork(chainId) : networkFromProgramId(programId);
|
|
2268
|
+
return [
|
|
2269
|
+
4,
|
|
2270
|
+
loadAleoSdk(txNetwork)
|
|
2271
|
+
];
|
|
2272
|
+
case 2:
|
|
2273
|
+
sdk = _state.sent();
|
|
2274
|
+
return [
|
|
2275
|
+
4,
|
|
2276
|
+
_this.getProgramManager(txNetwork)
|
|
2277
|
+
];
|
|
2278
|
+
case 3:
|
|
2279
|
+
programManager = _state.sent();
|
|
2280
|
+
return [
|
|
2281
|
+
4,
|
|
2282
|
+
_this.injectSealanceProofIfNeeded({
|
|
2283
|
+
accountAddress: accountAddress,
|
|
2284
|
+
functionName: functionName,
|
|
2285
|
+
inputTypes: inputTypes,
|
|
2286
|
+
inputs: inputs,
|
|
2287
|
+
programId: programId
|
|
2288
|
+
})
|
|
2289
|
+
];
|
|
2290
|
+
case 4:
|
|
2291
|
+
_ref = _state.sent(), effectiveInputs = _ref.inputs, effectiveInputTypes = _ref.inputTypes;
|
|
2292
|
+
return [
|
|
2293
|
+
4,
|
|
2294
|
+
_this.deriveProgramChecksumField({
|
|
2295
|
+
programId: programId,
|
|
2296
|
+
sdk: sdk,
|
|
2297
|
+
txNetwork: txNetwork
|
|
2298
|
+
})
|
|
2299
|
+
];
|
|
2300
|
+
case 5:
|
|
2301
|
+
checksum = _state.sent();
|
|
2302
|
+
return [
|
|
2303
|
+
4,
|
|
2304
|
+
sdk.computeExternalSigningInputs({
|
|
2305
|
+
programName: programId,
|
|
2306
|
+
functionName: functionName,
|
|
2307
|
+
inputs: effectiveInputs,
|
|
2308
|
+
inputTypes: effectiveInputTypes,
|
|
2309
|
+
isRoot: true,
|
|
2310
|
+
checksum: checksum,
|
|
2311
|
+
viewKey: viewKey,
|
|
2312
|
+
outputFormat: 'bytes'
|
|
2313
|
+
})
|
|
2314
|
+
];
|
|
2315
|
+
case 6:
|
|
2316
|
+
signingInputs = _state.sent();
|
|
2317
|
+
payload = _this.toRequestSignPayload(signingInputs);
|
|
2318
|
+
return [
|
|
2319
|
+
4,
|
|
2320
|
+
_this.signAleoRequest({
|
|
2321
|
+
accountAddress: accountAddress,
|
|
2322
|
+
payload: payload,
|
|
2323
|
+
password: password,
|
|
2324
|
+
signedSessionId: signedSessionId,
|
|
2325
|
+
mfaToken: mfaToken,
|
|
2326
|
+
elevatedAccessToken: elevatedAccessToken
|
|
2327
|
+
})
|
|
2328
|
+
];
|
|
2329
|
+
case 7:
|
|
2330
|
+
signedRequest = _state.sent();
|
|
2331
|
+
executionRequestBase = {
|
|
2332
|
+
programId: programId,
|
|
2333
|
+
functionName: functionName,
|
|
2334
|
+
inputs: effectiveInputs,
|
|
2335
|
+
inputTypes: effectiveInputTypes,
|
|
2336
|
+
signature: signedRequest.signature,
|
|
2337
|
+
tvk: signedRequest.tvk,
|
|
2338
|
+
signer: signedRequest.signer,
|
|
2339
|
+
skTag: signingInputs.skTag
|
|
2340
|
+
};
|
|
2341
|
+
// Use the viewKey strategy — works for all function shapes:
|
|
2342
|
+
// - record-consuming: SDK derives recordViewKeys from the viewKey
|
|
2343
|
+
// - record-producing: gammas feed the output record's commitment derivation
|
|
2344
|
+
// - pure-public: both are no-ops, safe to pass
|
|
2345
|
+
// `signedRequest.gammas` comes from the MPC signature and is required
|
|
2346
|
+
// whenever the circuit references any record (input or output).
|
|
2347
|
+
executionRequest = sdk.buildExecutionRequestFromExternallySignedData(executionRequestBase, {
|
|
2348
|
+
viewKey: viewKey,
|
|
2349
|
+
gammas: signedRequest.gammas
|
|
2350
|
+
});
|
|
2351
|
+
return [
|
|
2352
|
+
4,
|
|
2353
|
+
_this.buildProvingRequest({
|
|
2354
|
+
broadcast: broadcast,
|
|
2355
|
+
effectiveInputs: effectiveInputs,
|
|
2356
|
+
executionRequest: executionRequest,
|
|
2357
|
+
functionName: functionName,
|
|
2358
|
+
programId: programId,
|
|
2359
|
+
programManager: programManager,
|
|
2360
|
+
sdk: sdk,
|
|
2361
|
+
txNetwork: txNetwork
|
|
2362
|
+
})
|
|
2363
|
+
];
|
|
2364
|
+
case 8:
|
|
2365
|
+
provingRequest = _state.sent();
|
|
2366
|
+
return [
|
|
2367
|
+
4,
|
|
2368
|
+
programManager.networkClient.submitProvingRequest({
|
|
2369
|
+
provingRequest: provingRequest,
|
|
2370
|
+
dpsPrivacy: true
|
|
2371
|
+
})
|
|
2372
|
+
];
|
|
2373
|
+
case 9:
|
|
2374
|
+
provingResult = _state.sent();
|
|
2375
|
+
if (broadcast) {
|
|
2376
|
+
return [
|
|
2377
|
+
2,
|
|
2378
|
+
{
|
|
2379
|
+
txId: provingResult === null || provingResult === void 0 ? void 0 : (_provingResult_transaction = provingResult.transaction) === null || _provingResult_transaction === void 0 ? void 0 : _provingResult_transaction.id
|
|
2380
|
+
}
|
|
2381
|
+
];
|
|
2382
|
+
}
|
|
2383
|
+
return [
|
|
2384
|
+
2,
|
|
2385
|
+
{
|
|
2386
|
+
provingResponse: provingResult
|
|
2387
|
+
}
|
|
2388
|
+
];
|
|
2389
|
+
}
|
|
2390
|
+
});
|
|
2391
|
+
})();
|
|
2392
|
+
}
|
|
2393
|
+
},
|
|
2394
|
+
{
|
|
2395
|
+
key: "injectSealanceProofIfNeeded",
|
|
2396
|
+
value: /**
|
|
2397
|
+
* Sealance auto-injection. For tier-3 stablecoin transfer functions that
|
|
2398
|
+
* require a freeze-list exclusion proof, append the formatted
|
|
2399
|
+
* `[MerkleProof; 2u32].private` literal to inputs/inputTypes. Programs
|
|
2400
|
+
* not in the registry / function not requiring proof → pass-through.
|
|
2401
|
+
*/ function injectSealanceProofIfNeeded(param) {
|
|
2402
|
+
var accountAddress = param.accountAddress, functionName = param.functionName, inputTypes = param.inputTypes, inputs = param.inputs, programId = param.programId;
|
|
2403
|
+
var _this = this;
|
|
2404
|
+
return _async_to_generator(function() {
|
|
2405
|
+
var sealanceConfig, proof;
|
|
2406
|
+
return _ts_generator(this, function(_state) {
|
|
2407
|
+
switch(_state.label){
|
|
2408
|
+
case 0:
|
|
2409
|
+
sealanceConfig = lookupSealanceConfig(programId);
|
|
2410
|
+
if (!sealanceConfig || !SEALANCE_FUNCTIONS_REQUIRING_PROOF.has(functionName)) {
|
|
2411
|
+
return [
|
|
2412
|
+
2,
|
|
2413
|
+
{
|
|
2414
|
+
inputTypes: inputTypes,
|
|
2415
|
+
inputs: inputs
|
|
2416
|
+
}
|
|
2417
|
+
];
|
|
2418
|
+
}
|
|
2419
|
+
return [
|
|
2420
|
+
4,
|
|
2421
|
+
_this.getSealanceProof({
|
|
2422
|
+
accountAddress: accountAddress,
|
|
2423
|
+
freezelistProgram: sealanceConfig.freezelistProgram,
|
|
2424
|
+
network: sealanceConfig.network
|
|
2425
|
+
})
|
|
2426
|
+
];
|
|
2427
|
+
case 1:
|
|
2428
|
+
proof = _state.sent();
|
|
2429
|
+
return [
|
|
2430
|
+
2,
|
|
2431
|
+
{
|
|
2432
|
+
inputTypes: _to_consumable_array(inputTypes).concat([
|
|
2433
|
+
SEALANCE_PROOF_INPUT_TYPE
|
|
2434
|
+
]),
|
|
2435
|
+
inputs: _to_consumable_array(inputs).concat([
|
|
2436
|
+
proof
|
|
2437
|
+
])
|
|
2438
|
+
}
|
|
2439
|
+
];
|
|
2440
|
+
}
|
|
2441
|
+
});
|
|
2442
|
+
})();
|
|
2443
|
+
}
|
|
2444
|
+
},
|
|
2445
|
+
{
|
|
2446
|
+
key: "deriveProgramChecksumField",
|
|
2447
|
+
value: /**
|
|
2448
|
+
* Derive the program-checksum `Field` snarkVM's external-signing path
|
|
2449
|
+
* needs for non-credits programs. `credits.aleo` is special-cased in the
|
|
2450
|
+
* WASM and works with `null`. Other programs: fetch the on-chain 32-byte
|
|
2451
|
+
* checksum, expand bytes → bits LE, truncate to `Field::SIZE_IN_DATA_BITS`
|
|
2452
|
+
* (252 for Fr), and call `Field.fromBitsLe` — mirrors snarkVM's own
|
|
2453
|
+
* `Stack::program_checksum_as_field`.
|
|
2454
|
+
*/ function deriveProgramChecksumField(param) {
|
|
2455
|
+
var programId = param.programId, sdk = param.sdk, txNetwork = param.txNetwork;
|
|
2456
|
+
var _this = this;
|
|
2457
|
+
return _async_to_generator(function() {
|
|
2458
|
+
var checksumBytes, bits, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, byte, i, SIZE_IN_DATA_BITS;
|
|
2459
|
+
return _ts_generator(this, function(_state) {
|
|
2460
|
+
switch(_state.label){
|
|
2461
|
+
case 0:
|
|
2462
|
+
if (programId === 'credits.aleo') return [
|
|
2463
|
+
2,
|
|
2464
|
+
null
|
|
2465
|
+
];
|
|
2466
|
+
return [
|
|
2467
|
+
4,
|
|
2468
|
+
_this.getProgramChecksum(programId, txNetwork)
|
|
2469
|
+
];
|
|
2470
|
+
case 1:
|
|
2471
|
+
checksumBytes = _state.sent();
|
|
2472
|
+
if (checksumBytes === null) return [
|
|
2473
|
+
2,
|
|
2474
|
+
null
|
|
2475
|
+
];
|
|
2476
|
+
bits = [];
|
|
2477
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2478
|
+
try {
|
|
2479
|
+
for(_iterator = checksumBytes[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2480
|
+
byte = _step.value;
|
|
2481
|
+
for(i = 0; i < 8; i += 1){
|
|
2482
|
+
bits.push((byte >> i & 1) === 1);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
} catch (err) {
|
|
2486
|
+
_didIteratorError = true;
|
|
2487
|
+
_iteratorError = err;
|
|
2488
|
+
} finally{
|
|
2489
|
+
try {
|
|
2490
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2491
|
+
_iterator.return();
|
|
2492
|
+
}
|
|
2493
|
+
} finally{
|
|
2494
|
+
if (_didIteratorError) {
|
|
2495
|
+
throw _iteratorError;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
// Aleo's `Field` is the BLS12-377 scalar field Fr (252 data bits).
|
|
2500
|
+
SIZE_IN_DATA_BITS = 252;
|
|
2501
|
+
return [
|
|
2502
|
+
2,
|
|
2503
|
+
sdk.Field.fromBitsLe(bits.slice(0, SIZE_IN_DATA_BITS))
|
|
2504
|
+
];
|
|
2505
|
+
}
|
|
2506
|
+
});
|
|
2507
|
+
})();
|
|
2508
|
+
}
|
|
2509
|
+
},
|
|
2510
|
+
{
|
|
2511
|
+
key: "buildProvingRequest",
|
|
2512
|
+
value: /**
|
|
2513
|
+
* Build the proving request — feemaster path when ANF covers the
|
|
2514
|
+
* (programId, functionName), user-paid fallback otherwise. Feemaster
|
|
2515
|
+
* failures fall through silently so a transient policy/quota issue
|
|
2516
|
+
* doesn't block the user; they just pay the fee themselves.
|
|
2517
|
+
*/ function buildProvingRequest(param) {
|
|
2518
|
+
var broadcast = param.broadcast, effectiveInputs = param.effectiveInputs, executionRequest = param.executionRequest, functionName = param.functionName, programId = param.programId, programManager = param.programManager, sdk = param.sdk, txNetwork = param.txNetwork;
|
|
2519
|
+
var _this = this;
|
|
2520
|
+
return _async_to_generator(function() {
|
|
2521
|
+
var feemaster, _tmp, err;
|
|
2522
|
+
return _ts_generator(this, function(_state) {
|
|
2523
|
+
switch(_state.label){
|
|
2524
|
+
case 0:
|
|
2525
|
+
feemaster = _this.getFeemasterClient(txNetwork);
|
|
2526
|
+
_tmp = feemaster;
|
|
2527
|
+
if (!_tmp) return [
|
|
2528
|
+
3,
|
|
2529
|
+
2
|
|
2530
|
+
];
|
|
2531
|
+
return [
|
|
2532
|
+
4,
|
|
2533
|
+
feemaster.isCovered(programId, functionName)
|
|
2534
|
+
];
|
|
2535
|
+
case 1:
|
|
2536
|
+
_tmp = _state.sent();
|
|
2537
|
+
_state.label = 2;
|
|
2538
|
+
case 2:
|
|
2539
|
+
if (!_tmp) return [
|
|
2540
|
+
3,
|
|
2541
|
+
6
|
|
2542
|
+
];
|
|
2543
|
+
_state.label = 3;
|
|
2544
|
+
case 3:
|
|
2545
|
+
_state.trys.push([
|
|
2546
|
+
3,
|
|
2547
|
+
5,
|
|
2548
|
+
,
|
|
2549
|
+
6
|
|
2550
|
+
]);
|
|
2551
|
+
return [
|
|
2552
|
+
4,
|
|
2553
|
+
_this.buildFeemasterProvingRequest({
|
|
2554
|
+
broadcast: broadcast,
|
|
2555
|
+
executionRequest: executionRequest,
|
|
2556
|
+
feemaster: feemaster,
|
|
2557
|
+
programId: programId,
|
|
2558
|
+
programManager: programManager,
|
|
2559
|
+
sdk: sdk
|
|
2560
|
+
})
|
|
2561
|
+
];
|
|
2562
|
+
case 4:
|
|
2563
|
+
return [
|
|
2564
|
+
2,
|
|
2565
|
+
_state.sent()
|
|
2566
|
+
];
|
|
2567
|
+
case 5:
|
|
2568
|
+
err = _state.sent();
|
|
2569
|
+
// eslint-disable-next-line no-console
|
|
2570
|
+
console.warn('[aleo:proveTransaction] Feemaster path failed; falling back to user-paid fee', err);
|
|
2571
|
+
return [
|
|
2572
|
+
3,
|
|
2573
|
+
6
|
|
2574
|
+
];
|
|
2575
|
+
case 6:
|
|
2576
|
+
// User-paid fee path. The SDK's `provingRequest` short-circuits its
|
|
2577
|
+
// private-key check when `executionRequest` is provided — it forwards
|
|
2578
|
+
// the already-MPC-signed request straight to
|
|
2579
|
+
// `WasmProgramManager.buildProvingRequestFromExecutionRequest`.
|
|
2580
|
+
return [
|
|
2581
|
+
2,
|
|
2582
|
+
programManager.provingRequest({
|
|
2583
|
+
programName: programId,
|
|
2584
|
+
functionName: functionName,
|
|
2585
|
+
inputs: effectiveInputs,
|
|
2586
|
+
priorityFee: 0,
|
|
2587
|
+
privateFee: false,
|
|
2588
|
+
broadcast: broadcast,
|
|
2589
|
+
executionRequest: executionRequest
|
|
2590
|
+
})
|
|
2591
|
+
];
|
|
2592
|
+
}
|
|
2593
|
+
});
|
|
2594
|
+
})();
|
|
2595
|
+
}
|
|
2596
|
+
},
|
|
2597
|
+
{
|
|
2598
|
+
key: "buildFeemasterProvingRequest",
|
|
2599
|
+
value: /**
|
|
2600
|
+
* Feemaster-sponsored proving request. Builds the user authorization via
|
|
2601
|
+
* the WASM-direct ProgramManager static (no private key needed — the
|
|
2602
|
+
* request is already MPC-signed), exchanges it with the Feemaster for a
|
|
2603
|
+
* `feeAuthorization`, and returns the bundled `ProvingRequest`.
|
|
2604
|
+
*/ function buildFeemasterProvingRequest(param) {
|
|
2605
|
+
var broadcast = param.broadcast, executionRequest = param.executionRequest, feemaster = param.feemaster, programId = param.programId, programManager = param.programManager, sdk = param.sdk;
|
|
2606
|
+
return _async_to_generator(function() {
|
|
2607
|
+
var networkClient, programSrc, edition, importedPrograms, authorization, feeAuthorizationString, feeAuthorization;
|
|
2608
|
+
return _ts_generator(this, function(_state) {
|
|
2609
|
+
switch(_state.label){
|
|
2610
|
+
case 0:
|
|
2611
|
+
networkClient = programManager.networkClient;
|
|
2612
|
+
return [
|
|
2613
|
+
4,
|
|
2614
|
+
networkClient.getProgram(programId)
|
|
2615
|
+
];
|
|
2616
|
+
case 1:
|
|
2617
|
+
programSrc = _state.sent();
|
|
2618
|
+
return [
|
|
2619
|
+
4,
|
|
2620
|
+
networkClient.getLatestProgramEdition(programId)
|
|
2621
|
+
];
|
|
2622
|
+
case 2:
|
|
2623
|
+
edition = _state.sent();
|
|
2624
|
+
return [
|
|
2625
|
+
4,
|
|
2626
|
+
networkClient.getProgramImports(programId).catch(function() {
|
|
2627
|
+
return undefined;
|
|
2628
|
+
})
|
|
2629
|
+
];
|
|
2630
|
+
case 3:
|
|
2631
|
+
importedPrograms = _state.sent();
|
|
2632
|
+
return [
|
|
2633
|
+
4,
|
|
2634
|
+
sdk.ProgramManagerBase.buildAuthorizationFromExecutionRequest(executionRequest, programSrc, /* unchecked */ true, edition, importedPrograms, /* private_key */ null)
|
|
2635
|
+
];
|
|
2636
|
+
case 4:
|
|
2637
|
+
authorization = _state.sent();
|
|
2638
|
+
return [
|
|
2639
|
+
4,
|
|
2640
|
+
feemaster.requestFeeAuthorization({
|
|
2641
|
+
authorizationString: authorization.toString()
|
|
2642
|
+
})
|
|
2643
|
+
];
|
|
2644
|
+
case 5:
|
|
2645
|
+
feeAuthorizationString = _state.sent().feeAuthorizationString;
|
|
2646
|
+
feeAuthorization = sdk.Authorization.fromString(feeAuthorizationString);
|
|
2647
|
+
return [
|
|
2648
|
+
2,
|
|
2649
|
+
sdk.ProvingRequest.new(authorization, feeAuthorization, broadcast)
|
|
2650
|
+
];
|
|
2651
|
+
}
|
|
2652
|
+
});
|
|
2653
|
+
})();
|
|
2654
|
+
}
|
|
2655
|
+
},
|
|
2656
|
+
{
|
|
2657
|
+
key: "isFeemasterCovered",
|
|
2658
|
+
value: /**
|
|
2659
|
+
* Standalone Feemaster coverage check for any (programId, functionName)
|
|
2660
|
+
* pair on the connector-selected network. Used by the widget to decide
|
|
2661
|
+
* whether a user-paid confirmation modal is needed before triggering a
|
|
2662
|
+
* shield/send/join. Resolves the network from the caller-supplied
|
|
2663
|
+
* `chainId`; defaults to testnet when omitted (mirrors `resolveAleoNetwork`).
|
|
2664
|
+
*
|
|
2665
|
+
* Never throws — returns `false` on any policy fetch failure so callers
|
|
2666
|
+
* can default to "show modal" rather than silently shielding.
|
|
2667
|
+
*/ function isFeemasterCovered(param) {
|
|
2668
|
+
var programId = param.programId, functionName = param.functionName, chainId = param.chainId;
|
|
2669
|
+
var _this = this;
|
|
2670
|
+
return _async_to_generator(function() {
|
|
2671
|
+
var network, feemaster;
|
|
2672
|
+
return _ts_generator(this, function(_state) {
|
|
2673
|
+
switch(_state.label){
|
|
2674
|
+
case 0:
|
|
2675
|
+
network = chainId !== undefined && chainId !== null ? resolveAleoNetwork(chainId) : 'testnet';
|
|
2676
|
+
feemaster = _this.getFeemasterClient(network);
|
|
2677
|
+
if (!feemaster) return [
|
|
2678
|
+
2,
|
|
2679
|
+
false
|
|
2680
|
+
];
|
|
2681
|
+
_state.label = 1;
|
|
2682
|
+
case 1:
|
|
2683
|
+
_state.trys.push([
|
|
2684
|
+
1,
|
|
2685
|
+
3,
|
|
2686
|
+
,
|
|
2687
|
+
4
|
|
2688
|
+
]);
|
|
2689
|
+
return [
|
|
2690
|
+
4,
|
|
2691
|
+
feemaster.isCovered(programId, functionName)
|
|
2692
|
+
];
|
|
2693
|
+
case 2:
|
|
2694
|
+
return [
|
|
2695
|
+
2,
|
|
2696
|
+
_state.sent()
|
|
2697
|
+
];
|
|
2698
|
+
case 3:
|
|
2699
|
+
_state.sent();
|
|
2700
|
+
return [
|
|
2701
|
+
2,
|
|
2702
|
+
false
|
|
2703
|
+
];
|
|
2704
|
+
case 4:
|
|
2705
|
+
return [
|
|
2706
|
+
2
|
|
2707
|
+
];
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
})();
|
|
2711
|
+
}
|
|
2712
|
+
},
|
|
2713
|
+
{
|
|
2714
|
+
key: "getProgramManager",
|
|
2715
|
+
value: /**
|
|
2716
|
+
* Lazy-load the network-matching `@provablehq/sdk` build, instantiate a
|
|
2717
|
+
* ProgramManager, and cache it. The Provable WASM bundle is ~20MB, so
|
|
2718
|
+
* we avoid loading it eagerly at iframe init; both networks' bundles
|
|
2719
|
+
* load on first use of each.
|
|
2720
|
+
*/ function getProgramManager(network) {
|
|
2721
|
+
var _this = this;
|
|
2722
|
+
return _async_to_generator(function() {
|
|
2723
|
+
var cached, sdk, programManager, sameOriginProxy;
|
|
2724
|
+
return _ts_generator(this, function(_state) {
|
|
2725
|
+
switch(_state.label){
|
|
2726
|
+
case 0:
|
|
2727
|
+
cached = _this.programManagersByNetwork.get(network);
|
|
2728
|
+
if (cached) return [
|
|
2729
|
+
2,
|
|
2730
|
+
cached
|
|
2731
|
+
];
|
|
2732
|
+
return [
|
|
2733
|
+
4,
|
|
2734
|
+
loadAleoSdk(network)
|
|
2735
|
+
];
|
|
2736
|
+
case 1:
|
|
2737
|
+
sdk = _state.sent();
|
|
2738
|
+
programManager = new sdk.ProgramManager();
|
|
2739
|
+
// accelerate.provable.com rejects the SDK's X-Aleo-* headers via CORS and
|
|
2740
|
+
// ships `Access-Control-Allow-Origin: *` alongside `credentials: include`
|
|
2741
|
+
// (incompatible). In dev, route through the iframe host's Vite proxy
|
|
2742
|
+
// (`/aleo-dps`) so the browser sees same-origin calls. In prod, the iframe
|
|
2743
|
+
// host must proxy `/aleo-dps/*` to accelerate.provable.com.
|
|
2744
|
+
sameOriginProxy = typeof globalThis !== 'undefined' && globalThis.location ? "".concat(globalThis.location.origin, "/aleo-dps") : DEFAULT_PROVABLE_PROVER_URI;
|
|
2745
|
+
programManager.networkClient.setProverUri(sameOriginProxy);
|
|
2746
|
+
_this.programManagersByNetwork.set(network, programManager);
|
|
2747
|
+
return [
|
|
2748
|
+
2,
|
|
2749
|
+
programManager
|
|
2750
|
+
];
|
|
2751
|
+
}
|
|
2752
|
+
});
|
|
2753
|
+
})();
|
|
2754
|
+
}
|
|
2755
|
+
},
|
|
2756
|
+
{
|
|
2757
|
+
key: "getFeemasterClient",
|
|
2758
|
+
value: function getFeemasterClient(network) {
|
|
2759
|
+
var cached = this.feemasterClients.get(network);
|
|
2760
|
+
if (cached) return cached;
|
|
2761
|
+
var client = new FeemasterClient({
|
|
2762
|
+
apiClient: this.apiClient,
|
|
2763
|
+
network: network
|
|
2764
|
+
});
|
|
2765
|
+
this.feemasterClients.set(network, client);
|
|
2766
|
+
return client;
|
|
2767
|
+
}
|
|
2768
|
+
},
|
|
2769
|
+
{
|
|
2770
|
+
key: "getRecordScanner",
|
|
2771
|
+
value: /**
|
|
2772
|
+
* Lazy-init RecordScanner for the given Aleo network using the shared
|
|
2773
|
+
* Provable consumer credentials (VITE_ALEO_SCANNER_API_KEY +
|
|
2774
|
+
* VITE_ALEO_SCANNER_CONSUMER_ID in iframe env). Scanner calls and JWT
|
|
2775
|
+
* refresh both route through the Vite dev proxy `/aleo-api/*` to work
|
|
2776
|
+
* around Provable's CORS 401 on preflight.
|
|
2777
|
+
*
|
|
2778
|
+
* The Provable SDK ships separate `testnet.js` / `mainnet.js` builds
|
|
2779
|
+
* (verified in `node_modules/@provablehq/sdk/package.json#exports`). Each
|
|
2780
|
+
* build pins the chain endpoints to that network, so the right scanner
|
|
2781
|
+
* comes from importing the matching build. We cache an instance per
|
|
2782
|
+
* network on `this.scannersByNetwork`; toggling networks at runtime is
|
|
2783
|
+
* a Map lookup, no teardown.
|
|
2784
|
+
*/ function getRecordScanner(network) {
|
|
2785
|
+
var _this = this;
|
|
2786
|
+
return _async_to_generator(function() {
|
|
2787
|
+
var cached, sdk, scanner;
|
|
2788
|
+
return _ts_generator(this, function(_state) {
|
|
2789
|
+
switch(_state.label){
|
|
2790
|
+
case 0:
|
|
2791
|
+
cached = _this.scannersByNetwork.get(network);
|
|
2792
|
+
if (cached) return [
|
|
2793
|
+
2,
|
|
2794
|
+
cached
|
|
2795
|
+
];
|
|
2796
|
+
return [
|
|
2797
|
+
4,
|
|
2798
|
+
loadAleoSdk(network)
|
|
2799
|
+
];
|
|
2800
|
+
case 1:
|
|
2801
|
+
sdk = _state.sent();
|
|
2802
|
+
scanner = new RedcoastRecordScanner({
|
|
2803
|
+
apiClient: _this.apiClient,
|
|
2804
|
+
network: network,
|
|
2805
|
+
sdk: sdk
|
|
2806
|
+
});
|
|
2807
|
+
_this.scannersByNetwork.set(network, scanner);
|
|
2808
|
+
return [
|
|
2809
|
+
2,
|
|
2810
|
+
scanner
|
|
2811
|
+
];
|
|
2812
|
+
}
|
|
2813
|
+
});
|
|
2814
|
+
})();
|
|
2815
|
+
}
|
|
2816
|
+
},
|
|
2817
|
+
{
|
|
2818
|
+
key: "findOwnedRecords",
|
|
2819
|
+
value: /**
|
|
2820
|
+
* List all Aleo records owned by this wallet across every program (credits,
|
|
2821
|
+
* custom tokens, etc.). Uses Provable's hosted RecordScanner with our shared
|
|
2822
|
+
* consumer; per-wallet scanner UUID is cached in iframe IndexedDB
|
|
2823
|
+
* (walletStateStorage) so subsequent calls skip the register step.
|
|
2824
|
+
*
|
|
2825
|
+
* Each returned record carries `program_name` + `record_name` so callers
|
|
2826
|
+
* can classify by token. Credits records additionally get a `microcredits`
|
|
2827
|
+
* field parsed in-iframe for convenience (public WASM primitive). Other
|
|
2828
|
+
* tokens are returned as-is — the caller is responsible for amount parsing
|
|
2829
|
+
* per program schema.
|
|
2830
|
+
*
|
|
2831
|
+
* Records are decrypted locally in the iframe via view-key only.
|
|
2832
|
+
* Spent-tracking filters out locally-known spent nonces (records we
|
|
2833
|
+
* consumed in our own proveTransaction calls, before the scanner has
|
|
2834
|
+
* re-indexed).
|
|
2835
|
+
*/ function findOwnedRecords(params) {
|
|
2836
|
+
var _this = this;
|
|
2837
|
+
return _async_to_generator(function() {
|
|
2838
|
+
var accountAddress, chainId, network, dedupeKey, inflight, promise;
|
|
2839
|
+
return _ts_generator(this, function(_state) {
|
|
2840
|
+
accountAddress = params.accountAddress, chainId = params.chainId;
|
|
2841
|
+
if (!accountAddress) {
|
|
2842
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
2843
|
+
}
|
|
2844
|
+
// Dedupe concurrent scans on the same (wallet, network) so the recovery
|
|
2845
|
+
// path runs at most once. Including the network in the key lets a user
|
|
2846
|
+
// who toggles networks in flight kick off one scan per network without
|
|
2847
|
+
// the second being absorbed into the first.
|
|
2848
|
+
network = resolveAleoNetwork(chainId);
|
|
2849
|
+
dedupeKey = "".concat(accountAddress, ":").concat(network);
|
|
2850
|
+
inflight = _this.pendingFindOwnedRecords.get(dedupeKey);
|
|
2851
|
+
if (inflight) return [
|
|
2852
|
+
2,
|
|
2853
|
+
inflight
|
|
2854
|
+
];
|
|
2855
|
+
promise = _this.findOwnedRecordsInner(params).finally(function() {
|
|
2856
|
+
_this.pendingFindOwnedRecords.delete(dedupeKey);
|
|
2857
|
+
});
|
|
2858
|
+
_this.pendingFindOwnedRecords.set(dedupeKey, promise);
|
|
2859
|
+
return [
|
|
2860
|
+
2,
|
|
2861
|
+
promise
|
|
2862
|
+
];
|
|
2863
|
+
});
|
|
2864
|
+
})();
|
|
2865
|
+
}
|
|
2866
|
+
},
|
|
2867
|
+
{
|
|
2868
|
+
key: "findOwnedRecordsInner",
|
|
2869
|
+
value: function findOwnedRecordsInner(param) {
|
|
2870
|
+
var accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, chainId = param.chainId;
|
|
2871
|
+
var _this = this;
|
|
2872
|
+
return _async_to_generator(function() {
|
|
2873
|
+
var viewKey, network, sdk, cached, _cached_spentNonces, spentNonces, _ref, ownedRecords, scannerUuid, viewKeyObj, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, record, filtered, _cached_lastScannedBlock;
|
|
2874
|
+
return _ts_generator(this, function(_state) {
|
|
2875
|
+
switch(_state.label){
|
|
2876
|
+
case 0:
|
|
2877
|
+
return [
|
|
2878
|
+
4,
|
|
2879
|
+
_this.exportViewKey({
|
|
2880
|
+
accountAddress: accountAddress,
|
|
2881
|
+
password: password,
|
|
2882
|
+
signedSessionId: signedSessionId,
|
|
2883
|
+
mfaToken: mfaToken,
|
|
2884
|
+
elevatedAccessToken: elevatedAccessToken
|
|
2885
|
+
})
|
|
2886
|
+
];
|
|
2887
|
+
case 1:
|
|
2888
|
+
viewKey = _state.sent();
|
|
2889
|
+
network = resolveAleoNetwork(chainId);
|
|
2890
|
+
return [
|
|
2891
|
+
4,
|
|
2892
|
+
_this.loadAleoSdkOrThrow(network)
|
|
2893
|
+
];
|
|
2894
|
+
case 2:
|
|
2895
|
+
sdk = _state.sent();
|
|
2896
|
+
return [
|
|
2897
|
+
4,
|
|
2898
|
+
_this.loadWalletStateOrThrow(accountAddress, network)
|
|
2899
|
+
];
|
|
2900
|
+
case 3:
|
|
2901
|
+
cached = _state.sent();
|
|
2902
|
+
spentNonces = (_cached_spentNonces = cached === null || cached === void 0 ? void 0 : cached.spentNonces) !== null && _cached_spentNonces !== void 0 ? _cached_spentNonces : [];
|
|
2903
|
+
return [
|
|
2904
|
+
4,
|
|
2905
|
+
_this.findRecordsWithUuidRetry({
|
|
2906
|
+
accountAddress: accountAddress,
|
|
2907
|
+
cached: cached,
|
|
2908
|
+
network: network,
|
|
2909
|
+
sdk: sdk,
|
|
2910
|
+
spentNonces: spentNonces,
|
|
2911
|
+
viewKey: viewKey
|
|
2912
|
+
})
|
|
2913
|
+
];
|
|
2914
|
+
case 4:
|
|
2915
|
+
_ref = _state.sent(), ownedRecords = _ref.records, scannerUuid = _ref.scannerUuid;
|
|
2916
|
+
// Decrypt + annotate (microcredits / amount) per record so the DApp
|
|
2917
|
+
// doesn't need the Provable WASM in its own bundle.
|
|
2918
|
+
viewKeyObj = sdk.ViewKey.from_string(viewKey);
|
|
2919
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2920
|
+
try {
|
|
2921
|
+
for(_iterator = ownedRecords[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2922
|
+
record = _step.value;
|
|
2923
|
+
_this.enrichOwnedRecord(record, sdk, viewKeyObj);
|
|
2924
|
+
}
|
|
2925
|
+
} catch (err) {
|
|
2926
|
+
_didIteratorError = true;
|
|
2927
|
+
_iteratorError = err;
|
|
2928
|
+
} finally{
|
|
2929
|
+
try {
|
|
2930
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2931
|
+
_iterator.return();
|
|
2932
|
+
}
|
|
2933
|
+
} finally{
|
|
2934
|
+
if (_didIteratorError) {
|
|
2935
|
+
throw _iteratorError;
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
filtered = _this.filterUnspentRecords(ownedRecords, sdk, spentNonces);
|
|
2940
|
+
// Persist the fresh set so subsequent calls can return immediately if
|
|
2941
|
+
// the scanner is unreachable.
|
|
2942
|
+
return [
|
|
2943
|
+
4,
|
|
2944
|
+
putWalletState(accountAddress, network, {
|
|
2945
|
+
scannerUuid: scannerUuid,
|
|
2946
|
+
records: JSON.stringify(filtered),
|
|
2947
|
+
spentNonces: spentNonces,
|
|
2948
|
+
lastScannedBlock: (_cached_lastScannedBlock = cached === null || cached === void 0 ? void 0 : cached.lastScannedBlock) !== null && _cached_lastScannedBlock !== void 0 ? _cached_lastScannedBlock : 0
|
|
2949
|
+
})
|
|
2950
|
+
];
|
|
2951
|
+
case 5:
|
|
2952
|
+
_state.sent();
|
|
2953
|
+
return [
|
|
2954
|
+
2,
|
|
2955
|
+
{
|
|
2956
|
+
records: filtered
|
|
2957
|
+
}
|
|
2958
|
+
];
|
|
2959
|
+
}
|
|
2960
|
+
});
|
|
2961
|
+
})();
|
|
2962
|
+
}
|
|
2963
|
+
},
|
|
2964
|
+
{
|
|
2965
|
+
key: "loadAleoSdkOrThrow",
|
|
2966
|
+
value: /**
|
|
2967
|
+
* Loads the network-specific Provable SDK build and surfaces a clear
|
|
2968
|
+
* error log to the iframe console when WASM init fails (so the failure
|
|
2969
|
+
* is debuggable; the throw still propagates).
|
|
2970
|
+
*/ function loadAleoSdkOrThrow(network) {
|
|
2971
|
+
return _async_to_generator(function() {
|
|
2972
|
+
var err;
|
|
2973
|
+
return _ts_generator(this, function(_state) {
|
|
2974
|
+
switch(_state.label){
|
|
2975
|
+
case 0:
|
|
2976
|
+
_state.trys.push([
|
|
2977
|
+
0,
|
|
2978
|
+
2,
|
|
2979
|
+
,
|
|
2980
|
+
3
|
|
2981
|
+
]);
|
|
2982
|
+
return [
|
|
2983
|
+
4,
|
|
2984
|
+
loadAleoSdk(network)
|
|
2985
|
+
];
|
|
2986
|
+
case 1:
|
|
2987
|
+
return [
|
|
2988
|
+
2,
|
|
2989
|
+
_state.sent()
|
|
2990
|
+
];
|
|
2991
|
+
case 2:
|
|
2992
|
+
err = _state.sent();
|
|
2993
|
+
// eslint-disable-next-line no-console
|
|
2994
|
+
console.error('[aleo-client:findOwnedRecordsInner] loadAleoSdk FAILED', {
|
|
2995
|
+
network: network,
|
|
2996
|
+
error: _instanceof(err, Error) ? err.message : String(err)
|
|
2997
|
+
});
|
|
2998
|
+
throw err;
|
|
2999
|
+
case 3:
|
|
3000
|
+
return [
|
|
3001
|
+
2
|
|
3002
|
+
];
|
|
3003
|
+
}
|
|
3004
|
+
});
|
|
3005
|
+
})();
|
|
3006
|
+
}
|
|
3007
|
+
},
|
|
3008
|
+
{
|
|
3009
|
+
key: "loadWalletStateOrThrow",
|
|
3010
|
+
value: /**
|
|
3011
|
+
* Reads the per-(account, network) wallet state from IndexedDB. Errors
|
|
3012
|
+
* are logged and rethrown — a wedged IDB blocks the find-records flow
|
|
3013
|
+
* entirely, so silent fallback isn't safe here.
|
|
3014
|
+
*/ function loadWalletStateOrThrow(accountAddress, network) {
|
|
3015
|
+
return _async_to_generator(function() {
|
|
3016
|
+
var err;
|
|
3017
|
+
return _ts_generator(this, function(_state) {
|
|
3018
|
+
switch(_state.label){
|
|
3019
|
+
case 0:
|
|
3020
|
+
_state.trys.push([
|
|
3021
|
+
0,
|
|
3022
|
+
2,
|
|
3023
|
+
,
|
|
3024
|
+
3
|
|
3025
|
+
]);
|
|
3026
|
+
return [
|
|
3027
|
+
4,
|
|
3028
|
+
getWalletState(accountAddress, network)
|
|
3029
|
+
];
|
|
3030
|
+
case 1:
|
|
3031
|
+
return [
|
|
3032
|
+
2,
|
|
3033
|
+
_state.sent()
|
|
3034
|
+
];
|
|
3035
|
+
case 2:
|
|
3036
|
+
err = _state.sent();
|
|
3037
|
+
// eslint-disable-next-line no-console
|
|
3038
|
+
console.error('[aleo-client:findOwnedRecordsInner] getWalletState FAILED', {
|
|
3039
|
+
error: _instanceof(err, Error) ? err.message : String(err)
|
|
3040
|
+
});
|
|
3041
|
+
throw err;
|
|
3042
|
+
case 3:
|
|
3043
|
+
return [
|
|
3044
|
+
2
|
|
3045
|
+
];
|
|
3046
|
+
}
|
|
3047
|
+
});
|
|
3048
|
+
})();
|
|
3049
|
+
}
|
|
3050
|
+
},
|
|
3051
|
+
{
|
|
3052
|
+
key: "findRecordsWithUuidRetry",
|
|
3053
|
+
value: /**
|
|
3054
|
+
* Provable's RecordScanner can throw a `UUIDError` for several reasons —
|
|
3055
|
+
* cached UUID expired server-side, consumer key rotated, scanner instance
|
|
3056
|
+
* stale after a JWT refresh blip. Recovery: drop the cached scanner
|
|
3057
|
+
* instance + cached UUID, re-register, retry up to twice. After that the
|
|
3058
|
+
* problem isn't UUID-related and we surface the underlying error.
|
|
3059
|
+
*/ function findRecordsWithUuidRetry(param) {
|
|
3060
|
+
var accountAddress = param.accountAddress, cached = param.cached, network = param.network, sdk = param.sdk, spentNonces = param.spentNonces, viewKey = param.viewKey;
|
|
3061
|
+
var _this = this;
|
|
3062
|
+
return _async_to_generator(function() {
|
|
3063
|
+
var registerWallet, tryFind, _cached_scannerUuid, scannerUuid, _tmp, lastErr, attempt, _tmp1, err, _cached_records, _cached_lastScannedBlock;
|
|
3064
|
+
return _ts_generator(this, function(_state) {
|
|
3065
|
+
switch(_state.label){
|
|
3066
|
+
case 0:
|
|
3067
|
+
registerWallet = /*#__PURE__*/ function() {
|
|
3068
|
+
var _ref = _async_to_generator(function() {
|
|
3069
|
+
return _ts_generator(this, function(_state) {
|
|
3070
|
+
return [
|
|
3071
|
+
2,
|
|
3072
|
+
_this.registerScannerWallet({
|
|
3073
|
+
accountAddress: accountAddress,
|
|
3074
|
+
cached: cached,
|
|
3075
|
+
network: network,
|
|
3076
|
+
sdk: sdk,
|
|
3077
|
+
spentNonces: spentNonces,
|
|
3078
|
+
viewKey: viewKey
|
|
3079
|
+
})
|
|
3080
|
+
];
|
|
3081
|
+
});
|
|
3082
|
+
});
|
|
3083
|
+
return function registerWallet() {
|
|
3084
|
+
return _ref.apply(this, arguments);
|
|
3085
|
+
};
|
|
3086
|
+
}();
|
|
3087
|
+
tryFind = /*#__PURE__*/ function() {
|
|
3088
|
+
var _ref = _async_to_generator(function(uuid) {
|
|
3089
|
+
var scanner;
|
|
3090
|
+
return _ts_generator(this, function(_state) {
|
|
3091
|
+
switch(_state.label){
|
|
3092
|
+
case 0:
|
|
3093
|
+
return [
|
|
3094
|
+
4,
|
|
3095
|
+
_this.getRecordScanner(network)
|
|
3096
|
+
];
|
|
3097
|
+
case 1:
|
|
3098
|
+
scanner = _state.sent();
|
|
3099
|
+
return [
|
|
3100
|
+
2,
|
|
3101
|
+
scanner.findRecords({
|
|
3102
|
+
uuid: uuid,
|
|
3103
|
+
decrypt: true,
|
|
3104
|
+
unspent: true,
|
|
3105
|
+
filter: {}
|
|
3106
|
+
})
|
|
3107
|
+
];
|
|
3108
|
+
}
|
|
3109
|
+
});
|
|
3110
|
+
});
|
|
3111
|
+
return function tryFind(uuid) {
|
|
3112
|
+
return _ref.apply(this, arguments);
|
|
3113
|
+
};
|
|
3114
|
+
}();
|
|
3115
|
+
if (!((_cached_scannerUuid = cached === null || cached === void 0 ? void 0 : cached.scannerUuid) !== null && _cached_scannerUuid !== void 0)) return [
|
|
3116
|
+
3,
|
|
3117
|
+
1
|
|
3118
|
+
];
|
|
3119
|
+
_tmp = _cached_scannerUuid;
|
|
3120
|
+
return [
|
|
3121
|
+
3,
|
|
3122
|
+
3
|
|
3123
|
+
];
|
|
3124
|
+
case 1:
|
|
3125
|
+
return [
|
|
3126
|
+
4,
|
|
3127
|
+
registerWallet()
|
|
3128
|
+
];
|
|
3129
|
+
case 2:
|
|
3130
|
+
_tmp = _state.sent();
|
|
3131
|
+
_state.label = 3;
|
|
3132
|
+
case 3:
|
|
3133
|
+
scannerUuid = _tmp;
|
|
3134
|
+
attempt = 0;
|
|
3135
|
+
_state.label = 4;
|
|
3136
|
+
case 4:
|
|
3137
|
+
if (!(attempt < 3)) return [
|
|
3138
|
+
3,
|
|
3139
|
+
12
|
|
3140
|
+
];
|
|
3141
|
+
_state.label = 5;
|
|
3142
|
+
case 5:
|
|
3143
|
+
_state.trys.push([
|
|
3144
|
+
5,
|
|
3145
|
+
7,
|
|
3146
|
+
,
|
|
3147
|
+
11
|
|
3148
|
+
]);
|
|
3149
|
+
_tmp1 = {};
|
|
3150
|
+
return [
|
|
3151
|
+
4,
|
|
3152
|
+
tryFind(scannerUuid)
|
|
3153
|
+
];
|
|
3154
|
+
case 6:
|
|
3155
|
+
return [
|
|
3156
|
+
2,
|
|
3157
|
+
(_tmp1.records = _state.sent(), _tmp1.scannerUuid = scannerUuid, _tmp1)
|
|
3158
|
+
];
|
|
3159
|
+
case 7:
|
|
3160
|
+
err = _state.sent();
|
|
3161
|
+
lastErr = err;
|
|
3162
|
+
if (!isUuidScannerError(err)) throw err;
|
|
3163
|
+
// Reset this network's scanner instance + cached UUID, re-register.
|
|
3164
|
+
_this.scannersByNetwork.delete(network);
|
|
3165
|
+
return [
|
|
3166
|
+
4,
|
|
3167
|
+
putWalletState(accountAddress, network, {
|
|
3168
|
+
scannerUuid: undefined,
|
|
3169
|
+
records: (_cached_records = cached === null || cached === void 0 ? void 0 : cached.records) !== null && _cached_records !== void 0 ? _cached_records : '[]',
|
|
3170
|
+
spentNonces: spentNonces,
|
|
3171
|
+
lastScannedBlock: (_cached_lastScannedBlock = cached === null || cached === void 0 ? void 0 : cached.lastScannedBlock) !== null && _cached_lastScannedBlock !== void 0 ? _cached_lastScannedBlock : 0
|
|
3172
|
+
})
|
|
3173
|
+
];
|
|
3174
|
+
case 8:
|
|
3175
|
+
_state.sent();
|
|
3176
|
+
return [
|
|
3177
|
+
4,
|
|
3178
|
+
new Promise(function(resolve) {
|
|
3179
|
+
return setTimeout(resolve, 100);
|
|
3180
|
+
})
|
|
3181
|
+
];
|
|
3182
|
+
case 9:
|
|
3183
|
+
_state.sent();
|
|
3184
|
+
return [
|
|
3185
|
+
4,
|
|
3186
|
+
registerWallet()
|
|
3187
|
+
];
|
|
3188
|
+
case 10:
|
|
3189
|
+
scannerUuid = _state.sent();
|
|
3190
|
+
return [
|
|
3191
|
+
3,
|
|
3192
|
+
11
|
|
3193
|
+
];
|
|
3194
|
+
case 11:
|
|
3195
|
+
attempt += 1;
|
|
3196
|
+
return [
|
|
3197
|
+
3,
|
|
3198
|
+
4
|
|
3199
|
+
];
|
|
3200
|
+
case 12:
|
|
3201
|
+
throw new Error("Aleo RecordScanner kept rejecting the wallet UUID after re-registering. Try refreshing the page; underlying error: ".concat(_instanceof(lastErr, Error) ? lastErr.message : String(lastErr)));
|
|
3202
|
+
}
|
|
3203
|
+
});
|
|
3204
|
+
})();
|
|
3205
|
+
}
|
|
3206
|
+
},
|
|
3207
|
+
{
|
|
3208
|
+
key: "registerScannerWallet",
|
|
3209
|
+
value: /**
|
|
3210
|
+
* Wraps the encrypted view key and registers it with the scanner.
|
|
3211
|
+
* `registerEncrypted` (not `register`) ensures the view key crosses the
|
|
3212
|
+
* wire encrypted; same pattern Provable's `example-autojoin` uses.
|
|
3213
|
+
*/ function registerScannerWallet(param) {
|
|
3214
|
+
var accountAddress = param.accountAddress, cached = param.cached, network = param.network, sdk = param.sdk, spentNonces = param.spentNonces, viewKey = param.viewKey;
|
|
3215
|
+
var _this = this;
|
|
3216
|
+
return _async_to_generator(function() {
|
|
3217
|
+
var scanner, regResult, _regResult_error, _regResult_status, status, _regResult_error_message, newUuid, _cached_records, _cached_lastScannedBlock;
|
|
3218
|
+
return _ts_generator(this, function(_state) {
|
|
3219
|
+
switch(_state.label){
|
|
3220
|
+
case 0:
|
|
3221
|
+
return [
|
|
3222
|
+
4,
|
|
3223
|
+
_this.getRecordScanner(network)
|
|
3224
|
+
];
|
|
3225
|
+
case 1:
|
|
3226
|
+
scanner = _state.sent();
|
|
3227
|
+
return [
|
|
3228
|
+
4,
|
|
3229
|
+
scanner.registerEncrypted(sdk.ViewKey.from_string(viewKey), 0)
|
|
3230
|
+
];
|
|
3231
|
+
case 2:
|
|
3232
|
+
regResult = _state.sent();
|
|
3233
|
+
if (!(regResult === null || regResult === void 0 ? void 0 : regResult.ok)) {
|
|
3234
|
+
status = (_regResult_status = regResult === null || regResult === void 0 ? void 0 : regResult.status) !== null && _regResult_status !== void 0 ? _regResult_status : 'unknown';
|
|
3235
|
+
throw new Error((_regResult_error_message = regResult === null || regResult === void 0 ? void 0 : (_regResult_error = regResult.error) === null || _regResult_error === void 0 ? void 0 : _regResult_error.message) !== null && _regResult_error_message !== void 0 ? _regResult_error_message : "register failed (".concat(status, ")"));
|
|
3236
|
+
}
|
|
3237
|
+
newUuid = regResult.data.uuid;
|
|
3238
|
+
return [
|
|
3239
|
+
4,
|
|
3240
|
+
putWalletState(accountAddress, network, {
|
|
3241
|
+
scannerUuid: newUuid,
|
|
3242
|
+
records: (_cached_records = cached === null || cached === void 0 ? void 0 : cached.records) !== null && _cached_records !== void 0 ? _cached_records : '[]',
|
|
3243
|
+
spentNonces: spentNonces,
|
|
3244
|
+
lastScannedBlock: (_cached_lastScannedBlock = cached === null || cached === void 0 ? void 0 : cached.lastScannedBlock) !== null && _cached_lastScannedBlock !== void 0 ? _cached_lastScannedBlock : 0
|
|
3245
|
+
})
|
|
3246
|
+
];
|
|
3247
|
+
case 3:
|
|
3248
|
+
_state.sent();
|
|
3249
|
+
return [
|
|
3250
|
+
2,
|
|
3251
|
+
newUuid
|
|
3252
|
+
];
|
|
3253
|
+
}
|
|
3254
|
+
});
|
|
3255
|
+
})();
|
|
3256
|
+
}
|
|
3257
|
+
},
|
|
3258
|
+
{
|
|
3259
|
+
key: "enrichOwnedRecord",
|
|
3260
|
+
value: /**
|
|
3261
|
+
* Decrypt the record's ciphertext locally (when missing) and surface
|
|
3262
|
+
* `microcredits` / `amount` as decimal strings so the DApp side can
|
|
3263
|
+
* display balances without needing the Provable WASM in its own bundle.
|
|
3264
|
+
* Mutates the record in place — same contract the original loop had.
|
|
3265
|
+
*/ function enrichOwnedRecord(record, sdk, viewKeyObj) {
|
|
3266
|
+
if (!record.record_plaintext && record.record_ciphertext) {
|
|
3267
|
+
try {
|
|
3268
|
+
var ciphertext = sdk.RecordCiphertext.fromString(record.record_ciphertext);
|
|
3269
|
+
record.record_plaintext = ciphertext.decrypt(viewKeyObj).toString();
|
|
3270
|
+
} catch (e) {
|
|
3271
|
+
// Wrong view key or malformed ciphertext — record stays without
|
|
3272
|
+
// plaintext (renders as "#N" in the UI).
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
var isCreditsRecord = record.program_name === 'credits.aleo' && record.record_name === 'credits';
|
|
3276
|
+
if (isCreditsRecord && record.record_plaintext && !record.microcredits) {
|
|
3277
|
+
try {
|
|
3278
|
+
var plaintext = sdk.RecordPlaintext.fromString(record.record_plaintext);
|
|
3279
|
+
record.microcredits = plaintext.microcredits().toString();
|
|
3280
|
+
} catch (e) {
|
|
3281
|
+
/* ignore — malformed plaintext */ }
|
|
3282
|
+
return;
|
|
3283
|
+
}
|
|
3284
|
+
// Non-credits Token records (stablecoins / ARC-21) carry their balance
|
|
3285
|
+
// in an `amount` field of type `u128.private`. `getMember('amount')`
|
|
3286
|
+
// returns e.g. "100u128.private" — strip the type suffix.
|
|
3287
|
+
if (!isCreditsRecord && record.record_plaintext && !record.amount) {
|
|
3288
|
+
try {
|
|
3289
|
+
var plaintext1 = sdk.RecordPlaintext.fromString(record.record_plaintext);
|
|
3290
|
+
var amountLiteral = plaintext1.getMember('amount').toString();
|
|
3291
|
+
var numericMatch = /^(\d+)/.exec(amountLiteral);
|
|
3292
|
+
if (numericMatch) {
|
|
3293
|
+
record.amount = numericMatch[1];
|
|
3294
|
+
}
|
|
3295
|
+
} catch (e) {
|
|
3296
|
+
/* not a Token record with an amount field — skip */ }
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
},
|
|
3300
|
+
{
|
|
3301
|
+
key: "filterUnspentRecords",
|
|
3302
|
+
value: /**
|
|
3303
|
+
* Local spent-nonce filter — protects against the race where we've
|
|
3304
|
+
* broadcast a record-spending transaction but the scanner hasn't indexed
|
|
3305
|
+
* the spend yet.
|
|
3306
|
+
*/ function filterUnspentRecords(records, sdk, spentNonces) {
|
|
3307
|
+
var nonceOf = function(r) {
|
|
3308
|
+
try {
|
|
3309
|
+
if (r.record_plaintext) {
|
|
3310
|
+
return sdk.RecordPlaintext.fromString(r.record_plaintext).nonce();
|
|
3311
|
+
}
|
|
3312
|
+
} catch (e) {
|
|
3313
|
+
/* ignore */ }
|
|
3314
|
+
return undefined;
|
|
3315
|
+
};
|
|
3316
|
+
return records.filter(function(r) {
|
|
3317
|
+
var n = nonceOf(r);
|
|
3318
|
+
return !n || !spentNonces.includes(n);
|
|
3319
|
+
});
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
]);
|
|
3323
|
+
return DynamicAleoWalletClient;
|
|
3324
|
+
}(browser.DynamicWalletClient);
|
|
3325
|
+
/**
|
|
3326
|
+
* `findOwnedRecordsInner` retries on a UUID-stale signal — match the SDK's
|
|
3327
|
+
* own `UUIDError` message and the redcoast 422 forwarding (controller wraps
|
|
3328
|
+
* Provable's 422 with a "UUID invalid" body); plus any HTTP 422 on this
|
|
3329
|
+
* endpoint always indicates a stale/unknown UUID per Provable's contract.
|
|
3330
|
+
*/ var isUuidScannerError = function(err) {
|
|
3331
|
+
var _err_response;
|
|
3332
|
+
var msg = _instanceof(err, Error) ? err.message : String(err);
|
|
3333
|
+
var _err_response_status;
|
|
3334
|
+
var status = (_err_response_status = err === null || err === void 0 ? void 0 : (_err_response = err.response) === null || _err_response === void 0 ? void 0 : _err_response.status) !== null && _err_response_status !== void 0 ? _err_response_status : err === null || err === void 0 ? void 0 : err.status;
|
|
3335
|
+
return /UUID/i.test(msg) || status === 422;
|
|
3336
|
+
};
|
|
3337
|
+
|
|
3338
|
+
exports.ALEO_NETWORKS = ALEO_NETWORKS;
|
|
3339
|
+
exports.DynamicAleoWalletClient = DynamicAleoWalletClient;
|