@dynamic-labs-wallet/node-ton 0.0.353 → 0.1.0-request-signing
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 +172 -149
- package/index.esm.js +172 -149
- package/package.json +2 -2
- package/src/client/client.d.ts +41 -27
- package/src/client/client.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -108,6 +108,40 @@ function _instanceof(left, right) {
|
|
|
108
108
|
return left instanceof right;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
function _object_spread(target) {
|
|
112
|
+
for(var i = 1; i < arguments.length; i++){
|
|
113
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
114
|
+
var ownKeys = Object.keys(source);
|
|
115
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
116
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
117
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
ownKeys.forEach(function(key) {
|
|
121
|
+
_define_property(target, key, source[key]);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return target;
|
|
125
|
+
}
|
|
126
|
+
function ownKeys(object, enumerableOnly) {
|
|
127
|
+
var keys = Object.keys(object);
|
|
128
|
+
if (Object.getOwnPropertySymbols) {
|
|
129
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
130
|
+
keys.push.apply(keys, symbols);
|
|
131
|
+
}
|
|
132
|
+
return keys;
|
|
133
|
+
}
|
|
134
|
+
function _object_spread_props(target, source) {
|
|
135
|
+
source = source != null ? source : {};
|
|
136
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
137
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
138
|
+
} else {
|
|
139
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
140
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return target;
|
|
144
|
+
}
|
|
111
145
|
function _possible_constructor_return(self, call) {
|
|
112
146
|
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
113
147
|
return call;
|
|
@@ -232,7 +266,7 @@ var logError = node.createLogError('node-ton');
|
|
|
232
266
|
var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
233
267
|
_inherits(DynamicTonWalletClient, DynamicWalletClient);
|
|
234
268
|
function DynamicTonWalletClient(param) {
|
|
235
|
-
var environmentId = param.environmentId, baseApiUrl = param.baseApiUrl, baseMPCRelayApiUrl = param.baseMPCRelayApiUrl, debug = param.debug, enableMPCAccelerator = param.enableMPCAccelerator, logger = param.logger;
|
|
269
|
+
var environmentId = param.environmentId, baseApiUrl = param.baseApiUrl, baseMPCRelayApiUrl = param.baseMPCRelayApiUrl, debug = param.debug, enableMPCAccelerator = param.enableMPCAccelerator, logger = param.logger, requestSigning = param.requestSigning;
|
|
236
270
|
_class_call_check(this, DynamicTonWalletClient);
|
|
237
271
|
var _this;
|
|
238
272
|
_this = _call_super(this, DynamicTonWalletClient, [
|
|
@@ -242,7 +276,8 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
242
276
|
baseMPCRelayApiUrl: baseMPCRelayApiUrl,
|
|
243
277
|
debug: debug,
|
|
244
278
|
enableMPCAccelerator: enableMPCAccelerator,
|
|
245
|
-
logger: logger
|
|
279
|
+
logger: logger,
|
|
280
|
+
requestSigning: requestSigning
|
|
246
281
|
}
|
|
247
282
|
]), _define_property(_this, "chainName", 'TON'), /**
|
|
248
283
|
* Derives a TON address from a public key
|
|
@@ -273,13 +308,13 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
273
308
|
* @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet.
|
|
274
309
|
* @param password - The password to use for the wallet.
|
|
275
310
|
* @param onError - The function to call if an error occurs.
|
|
276
|
-
* @param
|
|
277
|
-
* @returns The
|
|
311
|
+
* @param backUpToDynamic - Whether to back up the external server key shares to the client share service. By default, it is false.
|
|
312
|
+
* @returns The walletMetadata, public key hex, raw public key, and external server key shares.
|
|
278
313
|
*/ function createWalletAccount(param) {
|
|
279
|
-
var thresholdSignatureScheme = param.thresholdSignatureScheme,
|
|
314
|
+
var thresholdSignatureScheme = param.thresholdSignatureScheme, password = param.password, onError = param.onError, _param_backUpToDynamic = param.backUpToDynamic, backUpToDynamic = _param_backUpToDynamic === void 0 ? false : _param_backUpToDynamic;
|
|
280
315
|
var _this = this;
|
|
281
316
|
return _async_to_generator(function() {
|
|
282
|
-
var
|
|
317
|
+
var ceremony, _ref, rawPublicKey, externalServerKeyShares, _ceremony_completion, resolvedWalletId, resolvedShareSetId, publicKeyHex, accountAddress, chainConfig, walletMetadata, _ref1, keySharesWithBackupStatus, backupInfo, _ceremony_completion_encryptedWalletApiKey, error;
|
|
283
318
|
return _ts_generator(this, function(_state) {
|
|
284
319
|
switch(_state.label){
|
|
285
320
|
case 0:
|
|
@@ -289,31 +324,16 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
289
324
|
,
|
|
290
325
|
5
|
|
291
326
|
]);
|
|
292
|
-
|
|
293
|
-
ceremonyCeremonyCompleteResolver = resolve;
|
|
294
|
-
});
|
|
327
|
+
ceremony = _this.createCeremonyCompletionTracker();
|
|
295
328
|
return [
|
|
296
329
|
4,
|
|
297
330
|
_this.keyGen({
|
|
298
331
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
299
332
|
chainName: _this.chainName,
|
|
333
|
+
password: password,
|
|
334
|
+
backUpToDynamic: backUpToDynamic,
|
|
300
335
|
onError: onError,
|
|
301
|
-
onCeremonyComplete:
|
|
302
|
-
var chainConfig = node.getMPCChainConfig(_this.chainName);
|
|
303
|
-
_this.initializeWalletMapEntry({
|
|
304
|
-
accountAddress: accountAddress,
|
|
305
|
-
walletId: walletId,
|
|
306
|
-
chainName: _this.chainName,
|
|
307
|
-
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
308
|
-
derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map(function(value, index) {
|
|
309
|
-
return [
|
|
310
|
-
index,
|
|
311
|
-
value
|
|
312
|
-
];
|
|
313
|
-
})))
|
|
314
|
-
});
|
|
315
|
-
ceremonyCeremonyCompleteResolver(undefined);
|
|
316
|
-
}
|
|
336
|
+
onCeremonyComplete: ceremony.onCeremonyComplete
|
|
317
337
|
})
|
|
318
338
|
];
|
|
319
339
|
case 1:
|
|
@@ -321,11 +341,12 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
321
341
|
// Wait for the ceremony to complete before proceeding
|
|
322
342
|
return [
|
|
323
343
|
4,
|
|
324
|
-
|
|
344
|
+
ceremony.promise
|
|
325
345
|
];
|
|
326
346
|
case 2:
|
|
327
347
|
_state.sent();
|
|
328
|
-
|
|
348
|
+
_ceremony_completion = ceremony.completion, resolvedWalletId = _ceremony_completion.walletId, resolvedShareSetId = _ceremony_completion.shareSetId;
|
|
349
|
+
if (!rawPublicKey || !externalServerKeyShares || !resolvedWalletId || !(typeof rawPublicKey === 'string' || _instanceof(rawPublicKey, Uint8Array))) {
|
|
329
350
|
throw new Error(ERROR_KEYGEN_FAILED);
|
|
330
351
|
}
|
|
331
352
|
publicKeyHex = typeof rawPublicKey === 'string' ? rawPublicKey : Buffer.from(rawPublicKey).toString('hex');
|
|
@@ -333,26 +354,42 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
333
354
|
publicKeyHex: publicKeyHex,
|
|
334
355
|
workchain: 0
|
|
335
356
|
});
|
|
357
|
+
chainConfig = node.getMPCChainConfig(_this.chainName);
|
|
358
|
+
walletMetadata = {
|
|
359
|
+
walletId: resolvedWalletId,
|
|
360
|
+
accountAddress: accountAddress,
|
|
361
|
+
chainName: _this.chainName,
|
|
362
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
363
|
+
derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map(function(value, index) {
|
|
364
|
+
return [
|
|
365
|
+
index,
|
|
366
|
+
value
|
|
367
|
+
];
|
|
368
|
+
}))),
|
|
369
|
+
shareSetId: resolvedShareSetId
|
|
370
|
+
};
|
|
336
371
|
return [
|
|
337
372
|
4,
|
|
338
373
|
_this.storeEncryptedBackupByWalletWithRetry({
|
|
339
374
|
accountAddress: accountAddress,
|
|
340
375
|
externalServerKeyShares: externalServerKeyShares,
|
|
341
376
|
password: password,
|
|
342
|
-
|
|
377
|
+
backUpToDynamic: backUpToDynamic,
|
|
378
|
+
walletMetadata: walletMetadata
|
|
343
379
|
})
|
|
344
380
|
];
|
|
345
381
|
case 3:
|
|
346
|
-
|
|
382
|
+
_ref1 = _state.sent(), keySharesWithBackupStatus = _ref1.keySharesWithBackupStatus, backupInfo = _ref1.backupInfo;
|
|
383
|
+
walletMetadata.externalServerKeySharesBackupInfo = backupInfo;
|
|
347
384
|
return [
|
|
348
385
|
2,
|
|
349
386
|
{
|
|
350
|
-
|
|
351
|
-
accountAddress: accountAddress,
|
|
387
|
+
walletMetadata: walletMetadata,
|
|
352
388
|
publicKeyHex: publicKeyHex,
|
|
353
389
|
rawPublicKey: rawPublicKey,
|
|
354
390
|
externalServerKeyShares: externalServerKeyShares,
|
|
355
|
-
externalKeySharesWithBackupStatus:
|
|
391
|
+
externalKeySharesWithBackupStatus: keySharesWithBackupStatus,
|
|
392
|
+
encryptedWalletApiKey: (_ceremony_completion_encryptedWalletApiKey = ceremony.completion.encryptedWalletApiKey) !== null && _ceremony_completion_encryptedWalletApiKey !== void 0 ? _ceremony_completion_encryptedWalletApiKey : undefined
|
|
356
393
|
}
|
|
357
394
|
];
|
|
358
395
|
case 4:
|
|
@@ -362,7 +399,9 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
362
399
|
error: error,
|
|
363
400
|
context: {}
|
|
364
401
|
});
|
|
365
|
-
throw new Error(ERROR_CREATE_WALLET_ACCOUNT
|
|
402
|
+
throw new Error(ERROR_CREATE_WALLET_ACCOUNT, {
|
|
403
|
+
cause: error
|
|
404
|
+
});
|
|
366
405
|
case 5:
|
|
367
406
|
return [
|
|
368
407
|
2
|
|
@@ -377,43 +416,35 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
377
416
|
value: /**
|
|
378
417
|
* Signs a message using MPC
|
|
379
418
|
* @param message - The message to sign
|
|
380
|
-
* @param
|
|
419
|
+
* @param walletMetadata - Wallet metadata (the full object returned by createWalletAccount/importPrivateKey, with backupInfo merged from any subsequent updatePassword/refresh/reshare)
|
|
381
420
|
* @param password - The password for encrypted backup shares
|
|
382
421
|
* @param externalServerKeyShares - The external server key shares
|
|
422
|
+
* @param context - Policy signing context. Defaults to the signed message.
|
|
383
423
|
* @param onError - The function to call if an error occurs
|
|
384
424
|
* @returns The signature as a base64 string
|
|
385
425
|
*/ function signMessage(param) {
|
|
386
|
-
var message = param.message,
|
|
426
|
+
var message = param.message, walletMetadata = param.walletMetadata, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, externalServerKeyShares = param.externalServerKeyShares, context = param.context, onError = param.onError;
|
|
387
427
|
var _this = this;
|
|
388
428
|
return _async_to_generator(function() {
|
|
389
|
-
var signatureEd25519, formattedSignature, error;
|
|
429
|
+
var accountAddress, resolvedContext, signatureEd25519, formattedSignature, error;
|
|
390
430
|
return _ts_generator(this, function(_state) {
|
|
391
431
|
switch(_state.label){
|
|
392
432
|
case 0:
|
|
433
|
+
accountAddress = walletMetadata.accountAddress;
|
|
393
434
|
if (!accountAddress) {
|
|
394
435
|
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
395
436
|
}
|
|
437
|
+
resolvedContext = _object_spread_props(_object_spread({}, context), {
|
|
438
|
+
tonMessage: message
|
|
439
|
+
});
|
|
396
440
|
_state.label = 1;
|
|
397
441
|
case 1:
|
|
398
442
|
_state.trys.push([
|
|
399
443
|
1,
|
|
400
|
-
|
|
444
|
+
3,
|
|
401
445
|
,
|
|
402
|
-
|
|
446
|
+
4
|
|
403
447
|
]);
|
|
404
|
-
// Attempt to recover key shares from backup if not provided
|
|
405
|
-
return [
|
|
406
|
-
4,
|
|
407
|
-
_this.ensureKeySharesRecovered({
|
|
408
|
-
accountAddress: accountAddress,
|
|
409
|
-
password: password,
|
|
410
|
-
walletOperation: node.WalletOperation.SIGN_MESSAGE,
|
|
411
|
-
externalServerKeyShares: externalServerKeyShares,
|
|
412
|
-
errorMessage: 'External server key shares are required to sign a message. No backup shares available for recovery.'
|
|
413
|
-
})
|
|
414
|
-
];
|
|
415
|
-
case 2:
|
|
416
|
-
_state.sent();
|
|
417
448
|
return [
|
|
418
449
|
4,
|
|
419
450
|
_this.sign({
|
|
@@ -422,17 +453,19 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
422
453
|
chainName: _this.chainName,
|
|
423
454
|
password: password,
|
|
424
455
|
externalServerKeyShares: externalServerKeyShares,
|
|
425
|
-
|
|
456
|
+
context: resolvedContext,
|
|
457
|
+
onError: onError,
|
|
458
|
+
walletMetadata: walletMetadata
|
|
426
459
|
})
|
|
427
460
|
];
|
|
428
|
-
case
|
|
461
|
+
case 2:
|
|
429
462
|
signatureEd25519 = _state.sent();
|
|
430
463
|
formattedSignature = Buffer.from(signatureEd25519).toString('base64');
|
|
431
464
|
return [
|
|
432
465
|
2,
|
|
433
466
|
formattedSignature
|
|
434
467
|
];
|
|
435
|
-
case
|
|
468
|
+
case 3:
|
|
436
469
|
error = _state.sent();
|
|
437
470
|
logError({
|
|
438
471
|
message: ERROR_SIGN_MESSAGE,
|
|
@@ -441,8 +474,10 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
441
474
|
accountAddress: accountAddress
|
|
442
475
|
}
|
|
443
476
|
});
|
|
444
|
-
throw new Error(ERROR_SIGN_MESSAGE
|
|
445
|
-
|
|
477
|
+
throw new Error(ERROR_SIGN_MESSAGE, {
|
|
478
|
+
cause: error
|
|
479
|
+
});
|
|
480
|
+
case 4:
|
|
446
481
|
return [
|
|
447
482
|
2
|
|
448
483
|
];
|
|
@@ -455,82 +490,75 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
455
490
|
key: "signTransaction",
|
|
456
491
|
value: /**
|
|
457
492
|
* Signs a transaction using MPC
|
|
458
|
-
* @param
|
|
493
|
+
* @param walletMetadata - Wallet metadata (the full object returned by createWalletAccount/importPrivateKey, with backupInfo merged from any subsequent updatePassword/refresh/reshare)
|
|
459
494
|
* @param transaction - The serialized transaction to sign
|
|
460
495
|
* @param password - The password for encrypted backup shares
|
|
461
496
|
* @param externalServerKeyShares - The external server key shares
|
|
497
|
+
* @param context - Policy signing context. Defaults to the serialized transaction.
|
|
462
498
|
* @param onError - The function to call if an error occurs
|
|
463
499
|
* @returns The signature as a base64 string
|
|
464
500
|
*/ function signTransaction(param) {
|
|
465
|
-
var
|
|
501
|
+
var walletMetadata = param.walletMetadata, transaction = param.transaction, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, externalServerKeyShares = param.externalServerKeyShares, context = param.context, onError = param.onError;
|
|
466
502
|
var _this = this;
|
|
467
503
|
return _async_to_generator(function() {
|
|
468
|
-
var signatureEd25519, formattedSignature, error;
|
|
504
|
+
var accountAddress, resolvedContext, signatureEd25519, formattedSignature, error;
|
|
469
505
|
return _ts_generator(this, function(_state) {
|
|
470
506
|
switch(_state.label){
|
|
471
507
|
case 0:
|
|
472
|
-
|
|
508
|
+
accountAddress = walletMetadata.accountAddress;
|
|
509
|
+
if (!accountAddress) {
|
|
473
510
|
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
474
511
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
];
|
|
512
|
+
resolvedContext = _object_spread_props(_object_spread({}, context), {
|
|
513
|
+
tonTransaction: {
|
|
514
|
+
serializedTransaction: transaction
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
_state.label = 1;
|
|
482
518
|
case 1:
|
|
483
|
-
_state.sent();
|
|
484
|
-
_state.label = 2;
|
|
485
|
-
case 2:
|
|
486
519
|
_state.trys.push([
|
|
487
|
-
|
|
488
|
-
|
|
520
|
+
1,
|
|
521
|
+
3,
|
|
489
522
|
,
|
|
490
|
-
|
|
523
|
+
4
|
|
491
524
|
]);
|
|
492
|
-
// Attempt to recover key shares from backup if not provided
|
|
493
|
-
return [
|
|
494
|
-
4,
|
|
495
|
-
_this.ensureKeySharesRecovered({
|
|
496
|
-
accountAddress: senderAddress,
|
|
497
|
-
password: password,
|
|
498
|
-
walletOperation: node.WalletOperation.SIGN_TRANSACTION,
|
|
499
|
-
externalServerKeyShares: externalServerKeyShares,
|
|
500
|
-
errorMessage: 'External server key shares are required to sign a transaction. No backup shares available for recovery.'
|
|
501
|
-
})
|
|
502
|
-
];
|
|
503
|
-
case 3:
|
|
504
|
-
_state.sent();
|
|
505
525
|
return [
|
|
506
526
|
4,
|
|
507
527
|
_this.sign({
|
|
508
528
|
message: transaction,
|
|
509
|
-
accountAddress:
|
|
529
|
+
accountAddress: accountAddress,
|
|
510
530
|
chainName: _this.chainName,
|
|
511
531
|
password: password,
|
|
512
532
|
externalServerKeyShares: externalServerKeyShares,
|
|
513
|
-
|
|
533
|
+
context: resolvedContext,
|
|
534
|
+
onError: onError,
|
|
535
|
+
walletMetadata: walletMetadata,
|
|
536
|
+
walletOperation: node.WalletOperation.SIGN_TRANSACTION
|
|
514
537
|
})
|
|
515
538
|
];
|
|
516
|
-
case
|
|
539
|
+
case 2:
|
|
517
540
|
signatureEd25519 = _state.sent();
|
|
541
|
+
if (!_instanceof(signatureEd25519, Uint8Array)) {
|
|
542
|
+
throw new TypeError('Invalid signature format returned from MPC signing');
|
|
543
|
+
}
|
|
518
544
|
formattedSignature = Buffer.from(signatureEd25519).toString('base64');
|
|
519
545
|
return [
|
|
520
546
|
2,
|
|
521
547
|
formattedSignature
|
|
522
548
|
];
|
|
523
|
-
case
|
|
549
|
+
case 3:
|
|
524
550
|
error = _state.sent();
|
|
525
551
|
logError({
|
|
526
552
|
message: ERROR_SIGN_TRANSACTION,
|
|
527
553
|
error: error,
|
|
528
554
|
context: {
|
|
529
|
-
|
|
555
|
+
accountAddress: accountAddress
|
|
530
556
|
}
|
|
531
557
|
});
|
|
532
|
-
throw new Error(ERROR_SIGN_TRANSACTION
|
|
533
|
-
|
|
558
|
+
throw new Error(ERROR_SIGN_TRANSACTION, {
|
|
559
|
+
cause: error
|
|
560
|
+
});
|
|
561
|
+
case 4:
|
|
534
562
|
return [
|
|
535
563
|
2
|
|
536
564
|
];
|
|
@@ -542,57 +570,39 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
542
570
|
{
|
|
543
571
|
key: "exportPrivateKey",
|
|
544
572
|
value: /**
|
|
545
|
-
* Exports the private key for a given
|
|
546
|
-
* @param
|
|
573
|
+
* Exports the private key for a given wallet
|
|
574
|
+
* @param walletMetadata - Wallet metadata (the full object returned by createWalletAccount/importPrivateKey, with backupInfo merged from any subsequent updatePassword/refresh/reshare)
|
|
547
575
|
* @param password - The password for encrypted backup shares
|
|
548
576
|
* @param externalServerKeyShares - The external server key shares
|
|
549
577
|
* @returns The private key as a hex string
|
|
550
578
|
*/ function exportPrivateKey(param) {
|
|
551
|
-
var
|
|
579
|
+
var walletMetadata = param.walletMetadata, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, externalServerKeyShares = param.externalServerKeyShares;
|
|
552
580
|
var _this = this;
|
|
553
581
|
return _async_to_generator(function() {
|
|
554
|
-
var derivedPrivateKey, privateScalarHex, error;
|
|
582
|
+
var accountAddress, derivedPrivateKey, privateScalarHex, error;
|
|
555
583
|
return _ts_generator(this, function(_state) {
|
|
556
584
|
switch(_state.label){
|
|
557
585
|
case 0:
|
|
586
|
+
accountAddress = walletMetadata.accountAddress;
|
|
587
|
+
_state.label = 1;
|
|
588
|
+
case 1:
|
|
558
589
|
_state.trys.push([
|
|
559
|
-
|
|
560
|
-
|
|
590
|
+
1,
|
|
591
|
+
3,
|
|
561
592
|
,
|
|
562
|
-
|
|
593
|
+
4
|
|
563
594
|
]);
|
|
564
|
-
return [
|
|
565
|
-
4,
|
|
566
|
-
_this.verifyPassword({
|
|
567
|
-
accountAddress: accountAddress,
|
|
568
|
-
password: password
|
|
569
|
-
})
|
|
570
|
-
];
|
|
571
|
-
case 1:
|
|
572
|
-
_state.sent();
|
|
573
|
-
// Attempt to recover key shares from backup if not provided
|
|
574
|
-
return [
|
|
575
|
-
4,
|
|
576
|
-
_this.ensureKeySharesRecovered({
|
|
577
|
-
accountAddress: accountAddress,
|
|
578
|
-
password: password,
|
|
579
|
-
walletOperation: node.WalletOperation.EXPORT_PRIVATE_KEY,
|
|
580
|
-
externalServerKeyShares: externalServerKeyShares,
|
|
581
|
-
errorMessage: 'External server key shares are required to export private key. No backup shares available for recovery.'
|
|
582
|
-
})
|
|
583
|
-
];
|
|
584
|
-
case 2:
|
|
585
|
-
_state.sent();
|
|
586
595
|
return [
|
|
587
596
|
4,
|
|
588
597
|
_this.exportKey({
|
|
589
598
|
accountAddress: accountAddress,
|
|
590
599
|
chainName: _this.chainName,
|
|
591
600
|
password: password,
|
|
592
|
-
externalServerKeyShares: externalServerKeyShares
|
|
601
|
+
externalServerKeyShares: externalServerKeyShares,
|
|
602
|
+
walletMetadata: walletMetadata
|
|
593
603
|
})
|
|
594
604
|
];
|
|
595
|
-
case
|
|
605
|
+
case 2:
|
|
596
606
|
derivedPrivateKey = _state.sent().derivedPrivateKey;
|
|
597
607
|
if (!derivedPrivateKey) {
|
|
598
608
|
throw new Error('Derived private key is undefined');
|
|
@@ -603,7 +613,7 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
603
613
|
2,
|
|
604
614
|
privateScalarHex
|
|
605
615
|
];
|
|
606
|
-
case
|
|
616
|
+
case 3:
|
|
607
617
|
error = _state.sent();
|
|
608
618
|
logError({
|
|
609
619
|
message: ERROR_EXPORT_PRIVATE_KEY,
|
|
@@ -613,7 +623,7 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
613
623
|
}
|
|
614
624
|
});
|
|
615
625
|
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
|
616
|
-
case
|
|
626
|
+
case 4:
|
|
617
627
|
return [
|
|
618
628
|
2
|
|
619
629
|
];
|
|
@@ -629,6 +639,11 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
629
639
|
* @param keyShares - The key shares to export the private key for
|
|
630
640
|
* @param derivationPath - The derivation path
|
|
631
641
|
* @returns The derived private key
|
|
642
|
+
*
|
|
643
|
+
* `derivationPath` is the JSON-serialized index map that
|
|
644
|
+
* `walletMetadata.derivationPath` carries (e.g. `'{"0":44,"1":60,"2":0,"3":0,"4":0}'`
|
|
645
|
+
* or `'[44,60,0,0,0]'`). BIP-32 strings such as `"m/44'/60'/0'/0/0"` are rejected.
|
|
646
|
+
* Omit it to export without path derivation.
|
|
632
647
|
*/ function offlineExportPrivateKey(param) {
|
|
633
648
|
var keyShares = param.keyShares, derivationPath = param.derivationPath;
|
|
634
649
|
var _this = this;
|
|
@@ -667,14 +682,14 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
667
682
|
* @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet.
|
|
668
683
|
* @param password - The password to use for the wallet.
|
|
669
684
|
* @param onError - The function to call if an error occurs.
|
|
670
|
-
* @param
|
|
685
|
+
* @param backUpToDynamic - Whether to back up the external server key shares to the client share service.
|
|
671
686
|
* @param publicAddressCheck - Optional public address to verify against the derived address.
|
|
672
|
-
* @returns The
|
|
687
|
+
* @returns The walletMetadata, public key hex, raw public key, and external server key shares.
|
|
673
688
|
*/ function importPrivateKey(param) {
|
|
674
|
-
var privateKey = param.privateKey, chainName = param.chainName, thresholdSignatureScheme = param.thresholdSignatureScheme,
|
|
689
|
+
var privateKey = param.privateKey, chainName = param.chainName, thresholdSignatureScheme = param.thresholdSignatureScheme, password = param.password, onError = param.onError, _param_backUpToDynamic = param.backUpToDynamic, backUpToDynamic = _param_backUpToDynamic === void 0 ? false : _param_backUpToDynamic, publicAddressCheck = param.publicAddressCheck;
|
|
675
690
|
var _this = this;
|
|
676
691
|
return _async_to_generator(function() {
|
|
677
|
-
var ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, formattedPrivateKey, publicKeyHex, derivedAddress, _ref, rawPublicKey, externalServerKeyShares, resultPublicKeyHex, accountAddress,
|
|
692
|
+
var resolvedWalletId, resolvedShareSetId, ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, formattedPrivateKey, publicKeyHex, derivedAddress, _ref, rawPublicKey, externalServerKeyShares, resultPublicKeyHex, accountAddress, chainConfig, walletMetadata, _ref1, keySharesWithBackupStatus, backupInfo, error;
|
|
678
693
|
return _ts_generator(this, function(_state) {
|
|
679
694
|
switch(_state.label){
|
|
680
695
|
case 0:
|
|
@@ -702,20 +717,12 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
702
717
|
chainName: chainName,
|
|
703
718
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
704
719
|
privateKey: formattedPrivateKey,
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
712
|
-
derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map(function(value, index) {
|
|
713
|
-
return [
|
|
714
|
-
index,
|
|
715
|
-
value
|
|
716
|
-
];
|
|
717
|
-
})))
|
|
718
|
-
});
|
|
720
|
+
password: password,
|
|
721
|
+
backUpToDynamic: backUpToDynamic,
|
|
722
|
+
onCeremonyComplete: function(param) {
|
|
723
|
+
var walletId = param.walletId, shareSetId = param.shareSetId;
|
|
724
|
+
resolvedWalletId = walletId;
|
|
725
|
+
resolvedShareSetId = shareSetId;
|
|
719
726
|
ceremonyCeremonyCompleteResolver(undefined);
|
|
720
727
|
},
|
|
721
728
|
onError: function(e) {
|
|
@@ -736,7 +743,7 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
736
743
|
];
|
|
737
744
|
case 2:
|
|
738
745
|
_state.sent();
|
|
739
|
-
if (!rawPublicKey || !externalServerKeyShares || !(typeof rawPublicKey === 'string' || _instanceof(rawPublicKey, Uint8Array))) {
|
|
746
|
+
if (!rawPublicKey || !externalServerKeyShares || !resolvedWalletId || !(typeof rawPublicKey === 'string' || _instanceof(rawPublicKey, Uint8Array))) {
|
|
740
747
|
throw new Error(ERROR_IMPORT_PRIVATE_KEY);
|
|
741
748
|
}
|
|
742
749
|
resultPublicKeyHex = typeof rawPublicKey === 'string' ? rawPublicKey : Buffer.from(rawPublicKey).toString('hex');
|
|
@@ -747,25 +754,41 @@ var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
747
754
|
if (accountAddress !== derivedAddress) {
|
|
748
755
|
throw new Error("Public key mismatch: derived address ".concat(accountAddress, " !== expected ").concat(derivedAddress));
|
|
749
756
|
}
|
|
757
|
+
chainConfig = node.getMPCChainConfig(_this.chainName);
|
|
758
|
+
walletMetadata = {
|
|
759
|
+
walletId: resolvedWalletId,
|
|
760
|
+
accountAddress: accountAddress,
|
|
761
|
+
chainName: _this.chainName,
|
|
762
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
763
|
+
derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map(function(value, index) {
|
|
764
|
+
return [
|
|
765
|
+
index,
|
|
766
|
+
value
|
|
767
|
+
];
|
|
768
|
+
}))),
|
|
769
|
+
shareSetId: resolvedShareSetId
|
|
770
|
+
};
|
|
750
771
|
return [
|
|
751
772
|
4,
|
|
752
773
|
_this.storeEncryptedBackupByWalletWithRetry({
|
|
753
774
|
accountAddress: accountAddress,
|
|
754
775
|
externalServerKeyShares: externalServerKeyShares,
|
|
755
776
|
password: password,
|
|
756
|
-
|
|
777
|
+
backUpToDynamic: backUpToDynamic,
|
|
778
|
+
walletMetadata: walletMetadata
|
|
757
779
|
})
|
|
758
780
|
];
|
|
759
781
|
case 3:
|
|
760
|
-
|
|
782
|
+
_ref1 = _state.sent(), keySharesWithBackupStatus = _ref1.keySharesWithBackupStatus, backupInfo = _ref1.backupInfo;
|
|
783
|
+
walletMetadata.externalServerKeySharesBackupInfo = backupInfo;
|
|
761
784
|
return [
|
|
762
785
|
2,
|
|
763
786
|
{
|
|
764
|
-
|
|
787
|
+
walletMetadata: walletMetadata,
|
|
765
788
|
publicKeyHex: resultPublicKeyHex,
|
|
766
789
|
rawPublicKey: rawPublicKey,
|
|
767
790
|
externalServerKeyShares: externalServerKeyShares,
|
|
768
|
-
externalKeySharesWithBackupStatus:
|
|
791
|
+
externalKeySharesWithBackupStatus: keySharesWithBackupStatus
|
|
769
792
|
}
|
|
770
793
|
];
|
|
771
794
|
case 4:
|