@dynamic-labs-wallet/stellar 0.0.354 → 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 +449 -39
- package/index.esm.js +450 -42
- package/package.json +3 -3
- package/src/client/client.d.ts +12 -21
- package/src/client/client.d.ts.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/signingIntent.d.ts +23 -0
- package/src/signingIntent.d.ts.map +1 -0
- package/src/stellarXdr.d.ts +29 -0
- package/src/stellarXdr.d.ts.map +1 -0
- package/src/utils/getNetworkPassphrase/getNetworkPassphrase.d.ts +1 -1
- package/src/utils/getNetworkPassphrase/getNetworkPassphrase.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -65,9 +65,12 @@ var STELLAR_NETWORK_PASSPHRASES = {
|
|
|
65
65
|
'3': STELLAR_NETWORK_PASSPHRASES.FUTURENET
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* Gets the network passphrase from a numeric chainId,
|
|
68
|
+
* Gets the network passphrase from a numeric chainId, throws for any chainId other than '1', '2' or '3'
|
|
69
69
|
*/ var getNetworkPassphraseFromChainId = function(chainId) {
|
|
70
|
-
|
|
70
|
+
if (!Object.keys(STELLAR_CHAIN_ID_TO_PASSPHRASE).includes(chainId)) {
|
|
71
|
+
throw new Error('Unsupported Stellar chainId');
|
|
72
|
+
}
|
|
73
|
+
return STELLAR_CHAIN_ID_TO_PASSPHRASE[chainId];
|
|
71
74
|
};
|
|
72
75
|
|
|
73
76
|
function _assert_this_initialized(self) {
|
|
@@ -159,7 +162,7 @@ function _inherits(subClass, superClass) {
|
|
|
159
162
|
});
|
|
160
163
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
161
164
|
}
|
|
162
|
-
function _instanceof(left, right) {
|
|
165
|
+
function _instanceof$1(left, right) {
|
|
163
166
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
164
167
|
return !!right[Symbol.hasInstance](left);
|
|
165
168
|
} else {
|
|
@@ -201,7 +204,7 @@ function _object_spread_props(target, source) {
|
|
|
201
204
|
return target;
|
|
202
205
|
}
|
|
203
206
|
function _possible_constructor_return(self, call) {
|
|
204
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
207
|
+
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
205
208
|
return call;
|
|
206
209
|
}
|
|
207
210
|
return _assert_this_initialized(self);
|
|
@@ -213,7 +216,7 @@ function _set_prototype_of(o, p) {
|
|
|
213
216
|
};
|
|
214
217
|
return _set_prototype_of(o, p);
|
|
215
218
|
}
|
|
216
|
-
function _type_of(obj) {
|
|
219
|
+
function _type_of$1(obj) {
|
|
217
220
|
"@swc/helpers - typeof";
|
|
218
221
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
219
222
|
}
|
|
@@ -322,33 +325,17 @@ function _ts_generator(thisArg, body) {
|
|
|
322
325
|
}
|
|
323
326
|
var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
324
327
|
_inherits(DynamicStellarWalletClient, DynamicWalletClient);
|
|
325
|
-
function DynamicStellarWalletClient(
|
|
326
|
-
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;
|
|
328
|
+
function DynamicStellarWalletClient() {
|
|
327
329
|
_class_call_check(this, DynamicStellarWalletClient);
|
|
328
330
|
var _this;
|
|
329
|
-
_this = _call_super(this, DynamicStellarWalletClient,
|
|
330
|
-
{
|
|
331
|
-
environmentId: environmentId,
|
|
332
|
-
authToken: authToken,
|
|
333
|
-
baseApiUrl: baseApiUrl,
|
|
334
|
-
baseMPCRelayApiUrl: baseMPCRelayApiUrl,
|
|
335
|
-
storageKey: storageKey,
|
|
336
|
-
debug: debug,
|
|
337
|
-
featureFlags: featureFlags,
|
|
338
|
-
authMode: authMode,
|
|
339
|
-
sdkVersion: sdkVersion,
|
|
340
|
-
forwardMPCClient: forwardMPCClient,
|
|
341
|
-
logger: logger
|
|
342
|
-
},
|
|
343
|
-
internalOptions
|
|
344
|
-
]), _define_property(_this, "chainName", 'STELLAR');
|
|
331
|
+
_this = _call_super(this, DynamicStellarWalletClient, arguments), _define_property(_this, "chainName", 'STELLAR');
|
|
345
332
|
return _this;
|
|
346
333
|
}
|
|
347
334
|
_create_class(DynamicStellarWalletClient, [
|
|
348
335
|
{
|
|
349
336
|
key: "createWalletAccount",
|
|
350
337
|
value: function createWalletAccount(param) {
|
|
351
|
-
var thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, onError = param.onError, signedSessionId = param.signedSessionId;
|
|
338
|
+
var thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, onError = param.onError, signedSessionId = param.signedSessionId, businessAccountId = param.businessAccountId;
|
|
352
339
|
var _this = this;
|
|
353
340
|
return _async_to_generator(function() {
|
|
354
341
|
var ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, _ref, publicKeyHex, clientKeyShares, accountAddress, pubKeyBytes, error;
|
|
@@ -368,9 +355,11 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
368
355
|
4,
|
|
369
356
|
_this.keyGen({
|
|
370
357
|
chainName: _this.chainName,
|
|
358
|
+
businessAccountId: businessAccountId,
|
|
371
359
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
372
360
|
onError: onError,
|
|
373
|
-
onCeremonyComplete: function(
|
|
361
|
+
onCeremonyComplete: function(param) {
|
|
362
|
+
var accountAddress = param.accountAddress, walletId = param.walletId, shareSetId = param.shareSetId;
|
|
374
363
|
var chainConfig = browser.getMPCChainConfig(_this.chainName);
|
|
375
364
|
_this.initializeWalletMapEntry({
|
|
376
365
|
accountAddress: accountAddress,
|
|
@@ -422,7 +411,8 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
422
411
|
accountAddress: accountAddress,
|
|
423
412
|
clientKeyShares: clientKeyShares,
|
|
424
413
|
password: password,
|
|
425
|
-
signedSessionId: signedSessionId
|
|
414
|
+
signedSessionId: signedSessionId,
|
|
415
|
+
businessAccountId: businessAccountId
|
|
426
416
|
})
|
|
427
417
|
];
|
|
428
418
|
case 4:
|
|
@@ -438,12 +428,14 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
438
428
|
];
|
|
439
429
|
case 5:
|
|
440
430
|
error = _state.sent();
|
|
441
|
-
// Re-throw
|
|
442
|
-
if (_instanceof(error, Error) && error.message === browser.ERROR_PASSWORD_MISMATCH) {
|
|
431
|
+
// Re-throw known business-rule rejections without wrapping
|
|
432
|
+
if (_instanceof$1(error, Error) && (error.message === browser.ERROR_PASSWORD_MISMATCH || error.message === browser.ERROR_MULTIPLE_WALLETS_PER_CHAIN)) {
|
|
443
433
|
throw error;
|
|
444
434
|
}
|
|
445
435
|
_this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
446
|
-
throw new Error(ERROR_CREATE_WALLET_ACCOUNT
|
|
436
|
+
throw new Error(ERROR_CREATE_WALLET_ACCOUNT, {
|
|
437
|
+
cause: error
|
|
438
|
+
});
|
|
447
439
|
case 6:
|
|
448
440
|
return [
|
|
449
441
|
2
|
|
@@ -456,7 +448,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
456
448
|
{
|
|
457
449
|
key: "signMessage",
|
|
458
450
|
value: function signMessage(param) {
|
|
459
|
-
var message = param.message, accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, context = param.context, onError = param.onError;
|
|
451
|
+
var message = param.message, accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, context = param.context, approvalQuorum = param.approvalQuorum, onError = param.onError;
|
|
460
452
|
var _this = this;
|
|
461
453
|
return _async_to_generator(function() {
|
|
462
454
|
var resolvedContext, signatureEd25519, formattedSignature, error;
|
|
@@ -498,6 +490,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
498
490
|
mfaToken: mfaToken,
|
|
499
491
|
elevatedAccessToken: elevatedAccessToken,
|
|
500
492
|
context: resolvedContext,
|
|
493
|
+
approvalQuorum: approvalQuorum,
|
|
501
494
|
onError: onError
|
|
502
495
|
})
|
|
503
496
|
];
|
|
@@ -511,8 +504,10 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
511
504
|
];
|
|
512
505
|
case 4:
|
|
513
506
|
error = _state.sent();
|
|
514
|
-
_this.
|
|
515
|
-
throw new Error(ERROR_SIGN_MESSAGE
|
|
507
|
+
_this.logOperationFailure(ERROR_SIGN_MESSAGE, error);
|
|
508
|
+
throw new Error(ERROR_SIGN_MESSAGE, {
|
|
509
|
+
cause: error
|
|
510
|
+
});
|
|
516
511
|
case 5:
|
|
517
512
|
return [
|
|
518
513
|
2
|
|
@@ -525,7 +520,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
525
520
|
{
|
|
526
521
|
key: "signTransaction",
|
|
527
522
|
value: function signTransaction(param) {
|
|
528
|
-
var senderAddress = param.senderAddress, transaction = param.transaction, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, chainId = param.chainId, context = param.context, onError = param.onError;
|
|
523
|
+
var senderAddress = param.senderAddress, transaction = param.transaction, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, chainId = param.chainId, context = param.context, approvalQuorum = param.approvalQuorum, onError = param.onError;
|
|
529
524
|
var _this = this;
|
|
530
525
|
return _async_to_generator(function() {
|
|
531
526
|
var networkPassphrase, stellarTransaction, transactionHash, resolvedContext, signatureEd25519, formattedSignature, error;
|
|
@@ -578,6 +573,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
578
573
|
mfaToken: mfaToken,
|
|
579
574
|
elevatedAccessToken: elevatedAccessToken,
|
|
580
575
|
context: resolvedContext,
|
|
576
|
+
approvalQuorum: approvalQuorum,
|
|
581
577
|
onError: onError
|
|
582
578
|
})
|
|
583
579
|
];
|
|
@@ -591,8 +587,10 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
591
587
|
];
|
|
592
588
|
case 4:
|
|
593
589
|
error = _state.sent();
|
|
594
|
-
_this.
|
|
595
|
-
throw new Error(ERROR_SIGN_TRANSACTION
|
|
590
|
+
_this.logOperationFailure(ERROR_SIGN_TRANSACTION, error);
|
|
591
|
+
throw new Error(ERROR_SIGN_TRANSACTION, {
|
|
592
|
+
cause: error
|
|
593
|
+
});
|
|
596
594
|
case 5:
|
|
597
595
|
return [
|
|
598
596
|
2
|
|
@@ -605,7 +603,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
605
603
|
{
|
|
606
604
|
key: "exportPrivateKey",
|
|
607
605
|
value: function exportPrivateKey(param) {
|
|
608
|
-
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;
|
|
606
|
+
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, approvalQuorum = param.approvalQuorum, proposalId = param.proposalId;
|
|
609
607
|
var _this = this;
|
|
610
608
|
return _async_to_generator(function() {
|
|
611
609
|
var derivedPrivateKey, privateScalarHex, privateKeyBytes, stellarSecretKey, error;
|
|
@@ -626,7 +624,9 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
626
624
|
password: password,
|
|
627
625
|
signedSessionId: signedSessionId,
|
|
628
626
|
mfaToken: mfaToken,
|
|
629
|
-
elevatedAccessToken: elevatedAccessToken
|
|
627
|
+
elevatedAccessToken: elevatedAccessToken,
|
|
628
|
+
approvalQuorum: approvalQuorum,
|
|
629
|
+
proposalId: proposalId
|
|
630
630
|
})
|
|
631
631
|
];
|
|
632
632
|
case 1:
|
|
@@ -646,6 +646,9 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
646
646
|
];
|
|
647
647
|
case 2:
|
|
648
648
|
error = _state.sent();
|
|
649
|
+
// Not a failure: the export needs approvals, and the caller needs the
|
|
650
|
+
// reason and proposalId to continue.
|
|
651
|
+
if (_instanceof$1(error, browser.SigningConsentRequiredError)) throw error;
|
|
649
652
|
_this.logger.error(ERROR_EXPORT_PRIVATE_KEY, error);
|
|
650
653
|
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
|
651
654
|
case 3:
|
|
@@ -700,7 +703,8 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
700
703
|
chainName: chainName,
|
|
701
704
|
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
702
705
|
privateKey: formattedPrivateKey,
|
|
703
|
-
onCeremonyComplete: function(
|
|
706
|
+
onCeremonyComplete: function(param) {
|
|
707
|
+
var accountAddress = param.accountAddress, walletId = param.walletId, shareSetId = param.shareSetId;
|
|
704
708
|
_this.initializeWalletMapEntry({
|
|
705
709
|
accountAddress: accountAddress,
|
|
706
710
|
walletId: walletId,
|
|
@@ -794,7 +798,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
794
798
|
return b.toString(16).padStart(2, '0');
|
|
795
799
|
}).join('');
|
|
796
800
|
} catch (error) {
|
|
797
|
-
this.logger.error('Unable to derive public key from private key. Check private key format', _instanceof(error, Error) ? error.message : 'Unknown error');
|
|
801
|
+
this.logger.error('Unable to derive public key from private key. Check private key format', _instanceof$1(error, Error) ? error.message : 'Unknown error');
|
|
798
802
|
throw error;
|
|
799
803
|
}
|
|
800
804
|
}
|
|
@@ -830,7 +834,413 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
830
834
|
return DynamicStellarWalletClient;
|
|
831
835
|
}(browser.DynamicWalletClient);
|
|
832
836
|
|
|
837
|
+
function _instanceof(left, right) {
|
|
838
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
839
|
+
return !!right[Symbol.hasInstance](left);
|
|
840
|
+
} else {
|
|
841
|
+
return left instanceof right;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
var MAX_OPERATIONS = 100;
|
|
845
|
+
var MAX_PATH_ASSETS = 5;
|
|
846
|
+
var MAX_MEMO_TEXT_BYTES = 28;
|
|
847
|
+
var MAX_FEE = 4294967295n;
|
|
848
|
+
var MAX_SEQUENCE = 9223372036854775806n;
|
|
849
|
+
var MAX_TIME = 18446744073709551615n;
|
|
850
|
+
var DECIMAL = /^(0|[1-9]\d*)$/;
|
|
851
|
+
var HEX_32_BYTES = /^[0-9a-f]{64}$/;
|
|
852
|
+
var assertStellarChainId = function(chainId) {
|
|
853
|
+
if (chainId !== '1' && chainId !== '2' && chainId !== '3') {
|
|
854
|
+
throw new Error('Stellar signing intent requires a network chainId of 1, 2 or 3');
|
|
855
|
+
}
|
|
856
|
+
return chainId;
|
|
857
|
+
};
|
|
858
|
+
var isAccount = function(address) {
|
|
859
|
+
return stellarSdk.StrKey.isValidEd25519PublicKey(address);
|
|
860
|
+
};
|
|
861
|
+
var assertAccount = function(address, message) {
|
|
862
|
+
if (!isAccount(address)) throw new Error(message);
|
|
863
|
+
return address;
|
|
864
|
+
};
|
|
865
|
+
var describeAsset = function(asset) {
|
|
866
|
+
if (!_instanceof(asset, stellarSdk.Asset)) throw new Error('Stellar signing intent does not support liquidity pool assets');
|
|
867
|
+
return asset.isNative() ? 'native' : "".concat(asset.getCode(), ":").concat(asset.getIssuer());
|
|
868
|
+
};
|
|
869
|
+
var toAsset = function(asset) {
|
|
870
|
+
if (asset === 'native') return stellarSdk.Asset.native();
|
|
871
|
+
var separator = asset.indexOf(':');
|
|
872
|
+
return new stellarSdk.Asset(asset.slice(0, separator), asset.slice(separator + 1));
|
|
873
|
+
};
|
|
874
|
+
var toBytes = function(value) {
|
|
875
|
+
if (value === null) throw new Error('Stellar signing intent does not support this memo type');
|
|
876
|
+
return typeof value === 'string' ? new TextEncoder().encode(value) : Uint8Array.from(value);
|
|
877
|
+
};
|
|
878
|
+
var toHex = function(bytes) {
|
|
879
|
+
return Array.from(bytes, function(byte) {
|
|
880
|
+
return byte.toString(16).padStart(2, '0');
|
|
881
|
+
}).join('');
|
|
882
|
+
};
|
|
883
|
+
var describeMemo = function(memo) {
|
|
884
|
+
switch(memo.type){
|
|
885
|
+
case 'none':
|
|
886
|
+
return {
|
|
887
|
+
type: 'none'
|
|
888
|
+
};
|
|
889
|
+
case 'id':
|
|
890
|
+
return {
|
|
891
|
+
type: 'id',
|
|
892
|
+
value: String(memo.value)
|
|
893
|
+
};
|
|
894
|
+
case 'text':
|
|
895
|
+
{
|
|
896
|
+
var bytes = toBytes(memo.value);
|
|
897
|
+
var value;
|
|
898
|
+
try {
|
|
899
|
+
value = new TextDecoder('utf-8', {
|
|
900
|
+
fatal: true,
|
|
901
|
+
ignoreBOM: true
|
|
902
|
+
}).decode(bytes);
|
|
903
|
+
} catch (e) {
|
|
904
|
+
throw new Error('Stellar signing intent requires a UTF-8 text memo');
|
|
905
|
+
}
|
|
906
|
+
if (bytes.length > MAX_MEMO_TEXT_BYTES) throw new Error('Stellar text memo is too long');
|
|
907
|
+
return {
|
|
908
|
+
type: 'text',
|
|
909
|
+
value: value
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
case 'hash':
|
|
913
|
+
case 'return':
|
|
914
|
+
return {
|
|
915
|
+
type: memo.type,
|
|
916
|
+
value: toHex(toBytes(memo.value))
|
|
917
|
+
};
|
|
918
|
+
default:
|
|
919
|
+
throw new Error('Stellar signing intent does not support this memo type');
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
var describePath = function(path) {
|
|
923
|
+
if (path.length > MAX_PATH_ASSETS) throw new Error('Stellar path payment path is too long');
|
|
924
|
+
return path.map(describeAsset);
|
|
925
|
+
};
|
|
926
|
+
var describeOperation = function(operation) {
|
|
927
|
+
if (operation.source !== undefined) throw new Error('Stellar signing intent does not support operation sources');
|
|
928
|
+
switch(operation.type){
|
|
929
|
+
case 'payment':
|
|
930
|
+
return {
|
|
931
|
+
type: 'payment',
|
|
932
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
933
|
+
asset: describeAsset(operation.asset),
|
|
934
|
+
amount: operation.amount
|
|
935
|
+
};
|
|
936
|
+
case 'pathPaymentStrictSend':
|
|
937
|
+
return {
|
|
938
|
+
type: 'pathPaymentStrictSend',
|
|
939
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
940
|
+
sendAsset: describeAsset(operation.sendAsset),
|
|
941
|
+
sendAmount: operation.sendAmount,
|
|
942
|
+
destAsset: describeAsset(operation.destAsset),
|
|
943
|
+
destMin: operation.destMin,
|
|
944
|
+
path: describePath(operation.path)
|
|
945
|
+
};
|
|
946
|
+
case 'pathPaymentStrictReceive':
|
|
947
|
+
return {
|
|
948
|
+
type: 'pathPaymentStrictReceive',
|
|
949
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
950
|
+
sendAsset: describeAsset(operation.sendAsset),
|
|
951
|
+
sendMax: operation.sendMax,
|
|
952
|
+
destAsset: describeAsset(operation.destAsset),
|
|
953
|
+
destAmount: operation.destAmount,
|
|
954
|
+
path: describePath(operation.path)
|
|
955
|
+
};
|
|
956
|
+
case 'createAccount':
|
|
957
|
+
return {
|
|
958
|
+
type: 'createAccount',
|
|
959
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
960
|
+
startingBalance: operation.startingBalance
|
|
961
|
+
};
|
|
962
|
+
case 'changeTrust':
|
|
963
|
+
return {
|
|
964
|
+
type: 'changeTrust',
|
|
965
|
+
asset: describeAsset(operation.line),
|
|
966
|
+
limit: operation.limit
|
|
967
|
+
};
|
|
968
|
+
default:
|
|
969
|
+
throw new Error("Stellar signing intent does not support the ".concat(operation.type, " operation"));
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
var assertClassicEnvelope = function(envelope) {
|
|
973
|
+
if (envelope.switch().name !== 'envelopeTypeTx') {
|
|
974
|
+
throw new Error('Stellar signing intent supports only v1 transaction envelopes, not fee-bump envelopes');
|
|
975
|
+
}
|
|
976
|
+
var tx = envelope.v1().tx();
|
|
977
|
+
if (tx.cond().switch().name !== 'precondTime') {
|
|
978
|
+
throw new Error('Stellar signing intent supports only time-bound preconditions');
|
|
979
|
+
}
|
|
980
|
+
if (tx.ext().switch() !== 0) throw new Error('Stellar signing intent does not support Soroban transactions');
|
|
981
|
+
return envelope.v1();
|
|
982
|
+
};
|
|
983
|
+
/**
|
|
984
|
+
* Describes a classic Stellar transaction envelope for a signing-quorum intent.
|
|
985
|
+
* The sequence number and time bounds are not part of the description: they are
|
|
986
|
+
* refreshed when the approved intent is resumed.
|
|
987
|
+
*/ var parseStellarTransaction = function(param) {
|
|
988
|
+
var transaction = param.transaction, chainId = param.chainId;
|
|
989
|
+
var envelope;
|
|
990
|
+
try {
|
|
991
|
+
envelope = stellarSdk.xdr.TransactionEnvelope.fromXDR(transaction, 'base64');
|
|
992
|
+
} catch (e) {
|
|
993
|
+
throw new Error('Stellar signing intent requires a base64 XDR transaction envelope');
|
|
994
|
+
}
|
|
995
|
+
if (envelope.toXDR('base64') !== transaction) {
|
|
996
|
+
throw new Error('Stellar signing intent requires a canonical XDR transaction envelope');
|
|
997
|
+
}
|
|
998
|
+
assertClassicEnvelope(envelope);
|
|
999
|
+
var parsed = stellarSdk.TransactionBuilder.fromXDR(transaction, getNetworkPassphraseFromChainId(chainId));
|
|
1000
|
+
if (!isAccount(parsed.source)) throw new Error('Stellar signing intent does not support muxed accounts');
|
|
1001
|
+
if (parsed.operations.length === 0 || parsed.operations.length > MAX_OPERATIONS) {
|
|
1002
|
+
throw new Error('Stellar signing intent requires between 1 and 100 operations');
|
|
1003
|
+
}
|
|
1004
|
+
return {
|
|
1005
|
+
kind: 'transaction',
|
|
1006
|
+
chainName: 'STELLAR',
|
|
1007
|
+
chainId: chainId,
|
|
1008
|
+
source: parsed.source,
|
|
1009
|
+
fee: parsed.fee,
|
|
1010
|
+
memo: describeMemo(parsed.memo),
|
|
1011
|
+
operations: parsed.operations.map(describeOperation)
|
|
1012
|
+
};
|
|
1013
|
+
};
|
|
1014
|
+
var buildMemo = function(memo) {
|
|
1015
|
+
switch(memo.type){
|
|
1016
|
+
case 'none':
|
|
1017
|
+
return stellarSdk.Memo.none();
|
|
1018
|
+
case 'text':
|
|
1019
|
+
return stellarSdk.Memo.text(memo.value);
|
|
1020
|
+
case 'id':
|
|
1021
|
+
return stellarSdk.Memo.id(memo.value);
|
|
1022
|
+
case 'hash':
|
|
1023
|
+
case 'return':
|
|
1024
|
+
if (!HEX_32_BYTES.test(memo.value)) throw new Error('Stored Stellar transaction intent is malformed');
|
|
1025
|
+
return memo.type === 'hash' ? stellarSdk.Memo.hash(memo.value) : stellarSdk.Memo.return(memo.value);
|
|
1026
|
+
default:
|
|
1027
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
var addOperation = function(builder, operation) {
|
|
1031
|
+
switch(operation.type){
|
|
1032
|
+
case 'payment':
|
|
1033
|
+
builder.addOperation(stellarSdk.Operation.payment({
|
|
1034
|
+
destination: operation.destination,
|
|
1035
|
+
asset: toAsset(operation.asset),
|
|
1036
|
+
amount: operation.amount
|
|
1037
|
+
}));
|
|
1038
|
+
return;
|
|
1039
|
+
case 'pathPaymentStrictSend':
|
|
1040
|
+
builder.addOperation(stellarSdk.Operation.pathPaymentStrictSend({
|
|
1041
|
+
destination: operation.destination,
|
|
1042
|
+
sendAsset: toAsset(operation.sendAsset),
|
|
1043
|
+
sendAmount: operation.sendAmount,
|
|
1044
|
+
destAsset: toAsset(operation.destAsset),
|
|
1045
|
+
destMin: operation.destMin,
|
|
1046
|
+
path: operation.path.map(toAsset)
|
|
1047
|
+
}));
|
|
1048
|
+
return;
|
|
1049
|
+
case 'pathPaymentStrictReceive':
|
|
1050
|
+
builder.addOperation(stellarSdk.Operation.pathPaymentStrictReceive({
|
|
1051
|
+
destination: operation.destination,
|
|
1052
|
+
sendAsset: toAsset(operation.sendAsset),
|
|
1053
|
+
sendMax: operation.sendMax,
|
|
1054
|
+
destAsset: toAsset(operation.destAsset),
|
|
1055
|
+
destAmount: operation.destAmount,
|
|
1056
|
+
path: operation.path.map(toAsset)
|
|
1057
|
+
}));
|
|
1058
|
+
return;
|
|
1059
|
+
case 'createAccount':
|
|
1060
|
+
builder.addOperation(stellarSdk.Operation.createAccount({
|
|
1061
|
+
destination: operation.destination,
|
|
1062
|
+
startingBalance: operation.startingBalance
|
|
1063
|
+
}));
|
|
1064
|
+
return;
|
|
1065
|
+
case 'changeTrust':
|
|
1066
|
+
builder.addOperation(stellarSdk.Operation.changeTrust({
|
|
1067
|
+
asset: toAsset(operation.asset),
|
|
1068
|
+
limit: operation.limit
|
|
1069
|
+
}));
|
|
1070
|
+
return;
|
|
1071
|
+
default:
|
|
1072
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
var decimalWithin = function(value, max) {
|
|
1076
|
+
if (typeof value !== 'string' || !DECIMAL.test(value)) return undefined;
|
|
1077
|
+
var parsed = BigInt(value);
|
|
1078
|
+
return parsed <= max ? parsed : undefined;
|
|
1079
|
+
};
|
|
1080
|
+
var parseStellarTransactionLifetime = function(lifetimeValue) {
|
|
1081
|
+
var parsed;
|
|
1082
|
+
try {
|
|
1083
|
+
parsed = lifetimeValue ? JSON.parse(lifetimeValue) : undefined;
|
|
1084
|
+
} catch (e) {
|
|
1085
|
+
parsed = undefined;
|
|
1086
|
+
}
|
|
1087
|
+
var _ref = parsed !== null && parsed !== void 0 ? parsed : {}, sequence = _ref.sequence, minTime = _ref.minTime, maxTime = _ref.maxTime;
|
|
1088
|
+
var parsedMinTime = decimalWithin(minTime, MAX_TIME);
|
|
1089
|
+
var parsedMaxTime = decimalWithin(maxTime, MAX_TIME);
|
|
1090
|
+
if (decimalWithin(sequence, MAX_SEQUENCE) === undefined || parsedMinTime === undefined || parsedMaxTime === undefined || parsedMaxTime === 0n || parsedMinTime > parsedMaxTime) {
|
|
1091
|
+
throw new Error('Stellar transaction intent requires an account sequence and time bounds');
|
|
1092
|
+
}
|
|
1093
|
+
return {
|
|
1094
|
+
sequence: sequence,
|
|
1095
|
+
minTime: minTime,
|
|
1096
|
+
maxTime: maxTime
|
|
1097
|
+
};
|
|
1098
|
+
};
|
|
1099
|
+
/**
|
|
1100
|
+
* Rebuilds the envelope of an approved Stellar transaction operation. The
|
|
1101
|
+
* operation carries the total fee, but the builder prices every operation at a
|
|
1102
|
+
* base fee, so a total that is not a multiple of the operation count is written
|
|
1103
|
+
* onto the envelope after the build.
|
|
1104
|
+
*/ var buildStellarTransaction = function(param) {
|
|
1105
|
+
var operation = param.operation, lifetime = param.lifetime;
|
|
1106
|
+
var totalFee = decimalWithin(operation.fee, MAX_FEE);
|
|
1107
|
+
var count = BigInt(operation.operations.length);
|
|
1108
|
+
if (totalFee === undefined || count === 0n || count > BigInt(MAX_OPERATIONS) || !isAccount(operation.source)) {
|
|
1109
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1110
|
+
}
|
|
1111
|
+
var builder = new stellarSdk.TransactionBuilder(new stellarSdk.Account(operation.source, lifetime.sequence), {
|
|
1112
|
+
fee: (totalFee / count).toString(),
|
|
1113
|
+
networkPassphrase: getNetworkPassphraseFromChainId(assertStellarChainId(operation.chainId)),
|
|
1114
|
+
memo: buildMemo(operation.memo),
|
|
1115
|
+
timebounds: {
|
|
1116
|
+
minTime: lifetime.minTime,
|
|
1117
|
+
maxTime: lifetime.maxTime
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
operation.operations.forEach(function(stellarOperation) {
|
|
1121
|
+
return addOperation(builder, stellarOperation);
|
|
1122
|
+
});
|
|
1123
|
+
var envelope = builder.build().toEnvelope();
|
|
1124
|
+
envelope.v1().tx().fee(Number(totalFee));
|
|
1125
|
+
return envelope.toXDR('base64');
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
function _array_like_to_array(arr, len) {
|
|
1129
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1130
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1131
|
+
return arr2;
|
|
1132
|
+
}
|
|
1133
|
+
function _array_with_holes(arr) {
|
|
1134
|
+
if (Array.isArray(arr)) return arr;
|
|
1135
|
+
}
|
|
1136
|
+
function _iterable_to_array_limit(arr, i) {
|
|
1137
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
1138
|
+
if (_i == null) return;
|
|
1139
|
+
var _arr = [];
|
|
1140
|
+
var _n = true;
|
|
1141
|
+
var _d = false;
|
|
1142
|
+
var _s, _e;
|
|
1143
|
+
try {
|
|
1144
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
1145
|
+
_arr.push(_s.value);
|
|
1146
|
+
if (i && _arr.length === i) break;
|
|
1147
|
+
}
|
|
1148
|
+
} catch (err) {
|
|
1149
|
+
_d = true;
|
|
1150
|
+
_e = err;
|
|
1151
|
+
} finally{
|
|
1152
|
+
try {
|
|
1153
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
1154
|
+
} finally{
|
|
1155
|
+
if (_d) throw _e;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return _arr;
|
|
1159
|
+
}
|
|
1160
|
+
function _non_iterable_rest() {
|
|
1161
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1162
|
+
}
|
|
1163
|
+
function _sliced_to_array(arr, i) {
|
|
1164
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
1165
|
+
}
|
|
1166
|
+
function _type_of(obj) {
|
|
1167
|
+
"@swc/helpers - typeof";
|
|
1168
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1169
|
+
}
|
|
1170
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
1171
|
+
if (!o) return;
|
|
1172
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1173
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1174
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1175
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1176
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Describes a Stellar transaction for a signing-quorum intent from its XDR
|
|
1180
|
+
* envelope. The sequence number and time bounds are not part of the
|
|
1181
|
+
* description: they are refreshed when the approved intent is resumed.
|
|
1182
|
+
*/ var prepareStellarTransactionSigningOperation = function(param) {
|
|
1183
|
+
var transaction = param.transaction, accountAddress = param.accountAddress, chainId = param.chainId;
|
|
1184
|
+
var operation = parseStellarTransaction({
|
|
1185
|
+
transaction: transaction,
|
|
1186
|
+
chainId: assertStellarChainId(chainId)
|
|
1187
|
+
});
|
|
1188
|
+
if (operation.source !== accountAddress) throw new Error('Stellar transaction source must be the signing account');
|
|
1189
|
+
return {
|
|
1190
|
+
operation: operation,
|
|
1191
|
+
lifetime: {
|
|
1192
|
+
refreshable: 'expiration'
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
};
|
|
1196
|
+
var byKey = function(param, param1) {
|
|
1197
|
+
var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
|
1198
|
+
if (a < b) return -1;
|
|
1199
|
+
if (a > b) return 1;
|
|
1200
|
+
return 0;
|
|
1201
|
+
};
|
|
1202
|
+
var withSortedKeys = function(_key, nested) {
|
|
1203
|
+
if (!nested || (typeof nested === "undefined" ? "undefined" : _type_of(nested)) !== 'object' || Array.isArray(nested)) return nested;
|
|
1204
|
+
return Object.fromEntries(Object.entries(nested).sort(byKey));
|
|
1205
|
+
};
|
|
1206
|
+
var canonicalJson = function(value) {
|
|
1207
|
+
return JSON.stringify(value, withSortedKeys);
|
|
1208
|
+
};
|
|
1209
|
+
var signedStellarOperation = function(intent) {
|
|
1210
|
+
var _intent_lifetime;
|
|
1211
|
+
var operation = intent.operation;
|
|
1212
|
+
if (operation.kind !== 'transaction' || operation.chainName !== 'STELLAR' || ((_intent_lifetime = intent.lifetime) === null || _intent_lifetime === void 0 ? void 0 : _intent_lifetime.refreshable) !== 'expiration') {
|
|
1213
|
+
throw new Error('Stored signing intent is not a Stellar transaction');
|
|
1214
|
+
}
|
|
1215
|
+
return operation;
|
|
1216
|
+
};
|
|
1217
|
+
/**
|
|
1218
|
+
* Rebuilds the XDR envelope of an approved Stellar transaction intent. The
|
|
1219
|
+
* signed intent carries no sequence number or time bounds, so the caller
|
|
1220
|
+
* supplies them as `lifetimeValue`, a JSON object with the account's current
|
|
1221
|
+
* `sequence` as Horizon returns it (the builder increments it) and `minTime`
|
|
1222
|
+
* and `maxTime` in seconds, all as decimal strings.
|
|
1223
|
+
*/ var resumeStellarTransactionSigningIntent = function(param) {
|
|
1224
|
+
var intent = param.intent, lifetimeValue = param.lifetimeValue;
|
|
1225
|
+
var operation = signedStellarOperation(intent);
|
|
1226
|
+
var lifetime = parseStellarTransactionLifetime(lifetimeValue);
|
|
1227
|
+
var transaction = buildStellarTransaction({
|
|
1228
|
+
operation: operation,
|
|
1229
|
+
lifetime: lifetime
|
|
1230
|
+
});
|
|
1231
|
+
var rebuilt = parseStellarTransaction({
|
|
1232
|
+
transaction: transaction,
|
|
1233
|
+
chainId: assertStellarChainId(operation.chainId)
|
|
1234
|
+
});
|
|
1235
|
+
if (canonicalJson(rebuilt) !== canonicalJson(operation)) {
|
|
1236
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1237
|
+
}
|
|
1238
|
+
return transaction;
|
|
1239
|
+
};
|
|
1240
|
+
|
|
833
1241
|
exports.sdkApiCore = sdkApiCore__namespace;
|
|
834
1242
|
exports.DynamicStellarWalletClient = DynamicStellarWalletClient;
|
|
835
1243
|
exports.STELLAR_HORIZON_URLS = STELLAR_HORIZON_URLS;
|
|
836
1244
|
exports.STELLAR_NETWORK_PASSPHRASES = STELLAR_NETWORK_PASSPHRASES;
|
|
1245
|
+
exports.prepareStellarTransactionSigningOperation = prepareStellarTransactionSigningOperation;
|
|
1246
|
+
exports.resumeStellarTransactionSigningIntent = resumeStellarTransactionSigningIntent;
|