@dynamic-labs-wallet/stellar 1.1.78 → 1.1.80
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 +417 -8
- package/index.esm.js +417 -10
- package/package.json +2 -2
- 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
|
}
|
|
@@ -425,7 +428,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
425
428
|
case 5:
|
|
426
429
|
error = _state.sent();
|
|
427
430
|
// Re-throw known business-rule rejections without wrapping
|
|
428
|
-
if (_instanceof(error, Error) && (error.message === browser.ERROR_PASSWORD_MISMATCH || error.message === browser.ERROR_MULTIPLE_WALLETS_PER_CHAIN)) {
|
|
431
|
+
if (_instanceof$1(error, Error) && (error.message === browser.ERROR_PASSWORD_MISMATCH || error.message === browser.ERROR_MULTIPLE_WALLETS_PER_CHAIN)) {
|
|
429
432
|
throw error;
|
|
430
433
|
}
|
|
431
434
|
_this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
@@ -644,7 +647,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
644
647
|
error = _state.sent();
|
|
645
648
|
// Not a failure: the export needs approvals, and the caller needs the
|
|
646
649
|
// reason and proposalId to continue.
|
|
647
|
-
if (_instanceof(error, browser.SigningConsentRequiredError)) throw error;
|
|
650
|
+
if (_instanceof$1(error, browser.SigningConsentRequiredError)) throw error;
|
|
648
651
|
_this.logger.error(ERROR_EXPORT_PRIVATE_KEY, error);
|
|
649
652
|
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
|
650
653
|
case 3:
|
|
@@ -793,7 +796,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
793
796
|
return b.toString(16).padStart(2, '0');
|
|
794
797
|
}).join('');
|
|
795
798
|
} catch (error) {
|
|
796
|
-
this.logger.error('Unable to derive public key from private key. Check private key format', _instanceof(error, Error) ? error.message : 'Unknown error');
|
|
799
|
+
this.logger.error('Unable to derive public key from private key. Check private key format', _instanceof$1(error, Error) ? error.message : 'Unknown error');
|
|
797
800
|
throw error;
|
|
798
801
|
}
|
|
799
802
|
}
|
|
@@ -829,7 +832,413 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
829
832
|
return DynamicStellarWalletClient;
|
|
830
833
|
}(browser.DynamicWalletClient);
|
|
831
834
|
|
|
835
|
+
function _instanceof(left, right) {
|
|
836
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
837
|
+
return !!right[Symbol.hasInstance](left);
|
|
838
|
+
} else {
|
|
839
|
+
return left instanceof right;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
var MAX_OPERATIONS = 100;
|
|
843
|
+
var MAX_PATH_ASSETS = 5;
|
|
844
|
+
var MAX_MEMO_TEXT_BYTES = 28;
|
|
845
|
+
var MAX_FEE = 4294967295n;
|
|
846
|
+
var MAX_SEQUENCE = 9223372036854775806n;
|
|
847
|
+
var MAX_TIME = 18446744073709551615n;
|
|
848
|
+
var DECIMAL = /^(0|[1-9]\d*)$/;
|
|
849
|
+
var HEX_32_BYTES = /^[0-9a-f]{64}$/;
|
|
850
|
+
var assertStellarChainId = function(chainId) {
|
|
851
|
+
if (chainId !== '1' && chainId !== '2' && chainId !== '3') {
|
|
852
|
+
throw new Error('Stellar signing intent requires a network chainId of 1, 2 or 3');
|
|
853
|
+
}
|
|
854
|
+
return chainId;
|
|
855
|
+
};
|
|
856
|
+
var isAccount = function(address) {
|
|
857
|
+
return stellarSdk.StrKey.isValidEd25519PublicKey(address);
|
|
858
|
+
};
|
|
859
|
+
var assertAccount = function(address, message) {
|
|
860
|
+
if (!isAccount(address)) throw new Error(message);
|
|
861
|
+
return address;
|
|
862
|
+
};
|
|
863
|
+
var describeAsset = function(asset) {
|
|
864
|
+
if (!_instanceof(asset, stellarSdk.Asset)) throw new Error('Stellar signing intent does not support liquidity pool assets');
|
|
865
|
+
return asset.isNative() ? 'native' : "".concat(asset.getCode(), ":").concat(asset.getIssuer());
|
|
866
|
+
};
|
|
867
|
+
var toAsset = function(asset) {
|
|
868
|
+
if (asset === 'native') return stellarSdk.Asset.native();
|
|
869
|
+
var separator = asset.indexOf(':');
|
|
870
|
+
return new stellarSdk.Asset(asset.slice(0, separator), asset.slice(separator + 1));
|
|
871
|
+
};
|
|
872
|
+
var toBytes = function(value) {
|
|
873
|
+
if (value === null) throw new Error('Stellar signing intent does not support this memo type');
|
|
874
|
+
return typeof value === 'string' ? new TextEncoder().encode(value) : Uint8Array.from(value);
|
|
875
|
+
};
|
|
876
|
+
var toHex = function(bytes) {
|
|
877
|
+
return Array.from(bytes, function(byte) {
|
|
878
|
+
return byte.toString(16).padStart(2, '0');
|
|
879
|
+
}).join('');
|
|
880
|
+
};
|
|
881
|
+
var describeMemo = function(memo) {
|
|
882
|
+
switch(memo.type){
|
|
883
|
+
case 'none':
|
|
884
|
+
return {
|
|
885
|
+
type: 'none'
|
|
886
|
+
};
|
|
887
|
+
case 'id':
|
|
888
|
+
return {
|
|
889
|
+
type: 'id',
|
|
890
|
+
value: String(memo.value)
|
|
891
|
+
};
|
|
892
|
+
case 'text':
|
|
893
|
+
{
|
|
894
|
+
var bytes = toBytes(memo.value);
|
|
895
|
+
var value;
|
|
896
|
+
try {
|
|
897
|
+
value = new TextDecoder('utf-8', {
|
|
898
|
+
fatal: true,
|
|
899
|
+
ignoreBOM: true
|
|
900
|
+
}).decode(bytes);
|
|
901
|
+
} catch (e) {
|
|
902
|
+
throw new Error('Stellar signing intent requires a UTF-8 text memo');
|
|
903
|
+
}
|
|
904
|
+
if (bytes.length > MAX_MEMO_TEXT_BYTES) throw new Error('Stellar text memo is too long');
|
|
905
|
+
return {
|
|
906
|
+
type: 'text',
|
|
907
|
+
value: value
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
case 'hash':
|
|
911
|
+
case 'return':
|
|
912
|
+
return {
|
|
913
|
+
type: memo.type,
|
|
914
|
+
value: toHex(toBytes(memo.value))
|
|
915
|
+
};
|
|
916
|
+
default:
|
|
917
|
+
throw new Error('Stellar signing intent does not support this memo type');
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
var describePath = function(path) {
|
|
921
|
+
if (path.length > MAX_PATH_ASSETS) throw new Error('Stellar path payment path is too long');
|
|
922
|
+
return path.map(describeAsset);
|
|
923
|
+
};
|
|
924
|
+
var describeOperation = function(operation) {
|
|
925
|
+
if (operation.source !== undefined) throw new Error('Stellar signing intent does not support operation sources');
|
|
926
|
+
switch(operation.type){
|
|
927
|
+
case 'payment':
|
|
928
|
+
return {
|
|
929
|
+
type: 'payment',
|
|
930
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
931
|
+
asset: describeAsset(operation.asset),
|
|
932
|
+
amount: operation.amount
|
|
933
|
+
};
|
|
934
|
+
case 'pathPaymentStrictSend':
|
|
935
|
+
return {
|
|
936
|
+
type: 'pathPaymentStrictSend',
|
|
937
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
938
|
+
sendAsset: describeAsset(operation.sendAsset),
|
|
939
|
+
sendAmount: operation.sendAmount,
|
|
940
|
+
destAsset: describeAsset(operation.destAsset),
|
|
941
|
+
destMin: operation.destMin,
|
|
942
|
+
path: describePath(operation.path)
|
|
943
|
+
};
|
|
944
|
+
case 'pathPaymentStrictReceive':
|
|
945
|
+
return {
|
|
946
|
+
type: 'pathPaymentStrictReceive',
|
|
947
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
948
|
+
sendAsset: describeAsset(operation.sendAsset),
|
|
949
|
+
sendMax: operation.sendMax,
|
|
950
|
+
destAsset: describeAsset(operation.destAsset),
|
|
951
|
+
destAmount: operation.destAmount,
|
|
952
|
+
path: describePath(operation.path)
|
|
953
|
+
};
|
|
954
|
+
case 'createAccount':
|
|
955
|
+
return {
|
|
956
|
+
type: 'createAccount',
|
|
957
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
958
|
+
startingBalance: operation.startingBalance
|
|
959
|
+
};
|
|
960
|
+
case 'changeTrust':
|
|
961
|
+
return {
|
|
962
|
+
type: 'changeTrust',
|
|
963
|
+
asset: describeAsset(operation.line),
|
|
964
|
+
limit: operation.limit
|
|
965
|
+
};
|
|
966
|
+
default:
|
|
967
|
+
throw new Error("Stellar signing intent does not support the ".concat(operation.type, " operation"));
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
var assertClassicEnvelope = function(envelope) {
|
|
971
|
+
if (envelope.switch().name !== 'envelopeTypeTx') {
|
|
972
|
+
throw new Error('Stellar signing intent supports only v1 transaction envelopes, not fee-bump envelopes');
|
|
973
|
+
}
|
|
974
|
+
var tx = envelope.v1().tx();
|
|
975
|
+
if (tx.cond().switch().name !== 'precondTime') {
|
|
976
|
+
throw new Error('Stellar signing intent supports only time-bound preconditions');
|
|
977
|
+
}
|
|
978
|
+
if (tx.ext().switch() !== 0) throw new Error('Stellar signing intent does not support Soroban transactions');
|
|
979
|
+
return envelope.v1();
|
|
980
|
+
};
|
|
981
|
+
/**
|
|
982
|
+
* Describes a classic Stellar transaction envelope for a signing-quorum intent.
|
|
983
|
+
* The sequence number and time bounds are not part of the description: they are
|
|
984
|
+
* refreshed when the approved intent is resumed.
|
|
985
|
+
*/ var parseStellarTransaction = function(param) {
|
|
986
|
+
var transaction = param.transaction, chainId = param.chainId;
|
|
987
|
+
var envelope;
|
|
988
|
+
try {
|
|
989
|
+
envelope = stellarSdk.xdr.TransactionEnvelope.fromXDR(transaction, 'base64');
|
|
990
|
+
} catch (e) {
|
|
991
|
+
throw new Error('Stellar signing intent requires a base64 XDR transaction envelope');
|
|
992
|
+
}
|
|
993
|
+
if (envelope.toXDR('base64') !== transaction) {
|
|
994
|
+
throw new Error('Stellar signing intent requires a canonical XDR transaction envelope');
|
|
995
|
+
}
|
|
996
|
+
assertClassicEnvelope(envelope);
|
|
997
|
+
var parsed = stellarSdk.TransactionBuilder.fromXDR(transaction, getNetworkPassphraseFromChainId(chainId));
|
|
998
|
+
if (!isAccount(parsed.source)) throw new Error('Stellar signing intent does not support muxed accounts');
|
|
999
|
+
if (parsed.operations.length === 0 || parsed.operations.length > MAX_OPERATIONS) {
|
|
1000
|
+
throw new Error('Stellar signing intent requires between 1 and 100 operations');
|
|
1001
|
+
}
|
|
1002
|
+
return {
|
|
1003
|
+
kind: 'transaction',
|
|
1004
|
+
chainName: 'STELLAR',
|
|
1005
|
+
chainId: chainId,
|
|
1006
|
+
source: parsed.source,
|
|
1007
|
+
fee: parsed.fee,
|
|
1008
|
+
memo: describeMemo(parsed.memo),
|
|
1009
|
+
operations: parsed.operations.map(describeOperation)
|
|
1010
|
+
};
|
|
1011
|
+
};
|
|
1012
|
+
var buildMemo = function(memo) {
|
|
1013
|
+
switch(memo.type){
|
|
1014
|
+
case 'none':
|
|
1015
|
+
return stellarSdk.Memo.none();
|
|
1016
|
+
case 'text':
|
|
1017
|
+
return stellarSdk.Memo.text(memo.value);
|
|
1018
|
+
case 'id':
|
|
1019
|
+
return stellarSdk.Memo.id(memo.value);
|
|
1020
|
+
case 'hash':
|
|
1021
|
+
case 'return':
|
|
1022
|
+
if (!HEX_32_BYTES.test(memo.value)) throw new Error('Stored Stellar transaction intent is malformed');
|
|
1023
|
+
return memo.type === 'hash' ? stellarSdk.Memo.hash(memo.value) : stellarSdk.Memo.return(memo.value);
|
|
1024
|
+
default:
|
|
1025
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
var addOperation = function(builder, operation) {
|
|
1029
|
+
switch(operation.type){
|
|
1030
|
+
case 'payment':
|
|
1031
|
+
builder.addOperation(stellarSdk.Operation.payment({
|
|
1032
|
+
destination: operation.destination,
|
|
1033
|
+
asset: toAsset(operation.asset),
|
|
1034
|
+
amount: operation.amount
|
|
1035
|
+
}));
|
|
1036
|
+
return;
|
|
1037
|
+
case 'pathPaymentStrictSend':
|
|
1038
|
+
builder.addOperation(stellarSdk.Operation.pathPaymentStrictSend({
|
|
1039
|
+
destination: operation.destination,
|
|
1040
|
+
sendAsset: toAsset(operation.sendAsset),
|
|
1041
|
+
sendAmount: operation.sendAmount,
|
|
1042
|
+
destAsset: toAsset(operation.destAsset),
|
|
1043
|
+
destMin: operation.destMin,
|
|
1044
|
+
path: operation.path.map(toAsset)
|
|
1045
|
+
}));
|
|
1046
|
+
return;
|
|
1047
|
+
case 'pathPaymentStrictReceive':
|
|
1048
|
+
builder.addOperation(stellarSdk.Operation.pathPaymentStrictReceive({
|
|
1049
|
+
destination: operation.destination,
|
|
1050
|
+
sendAsset: toAsset(operation.sendAsset),
|
|
1051
|
+
sendMax: operation.sendMax,
|
|
1052
|
+
destAsset: toAsset(operation.destAsset),
|
|
1053
|
+
destAmount: operation.destAmount,
|
|
1054
|
+
path: operation.path.map(toAsset)
|
|
1055
|
+
}));
|
|
1056
|
+
return;
|
|
1057
|
+
case 'createAccount':
|
|
1058
|
+
builder.addOperation(stellarSdk.Operation.createAccount({
|
|
1059
|
+
destination: operation.destination,
|
|
1060
|
+
startingBalance: operation.startingBalance
|
|
1061
|
+
}));
|
|
1062
|
+
return;
|
|
1063
|
+
case 'changeTrust':
|
|
1064
|
+
builder.addOperation(stellarSdk.Operation.changeTrust({
|
|
1065
|
+
asset: toAsset(operation.asset),
|
|
1066
|
+
limit: operation.limit
|
|
1067
|
+
}));
|
|
1068
|
+
return;
|
|
1069
|
+
default:
|
|
1070
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
var decimalWithin = function(value, max) {
|
|
1074
|
+
if (typeof value !== 'string' || !DECIMAL.test(value)) return undefined;
|
|
1075
|
+
var parsed = BigInt(value);
|
|
1076
|
+
return parsed <= max ? parsed : undefined;
|
|
1077
|
+
};
|
|
1078
|
+
var parseStellarTransactionLifetime = function(lifetimeValue) {
|
|
1079
|
+
var parsed;
|
|
1080
|
+
try {
|
|
1081
|
+
parsed = lifetimeValue ? JSON.parse(lifetimeValue) : undefined;
|
|
1082
|
+
} catch (e) {
|
|
1083
|
+
parsed = undefined;
|
|
1084
|
+
}
|
|
1085
|
+
var _ref = parsed !== null && parsed !== void 0 ? parsed : {}, sequence = _ref.sequence, minTime = _ref.minTime, maxTime = _ref.maxTime;
|
|
1086
|
+
var parsedMinTime = decimalWithin(minTime, MAX_TIME);
|
|
1087
|
+
var parsedMaxTime = decimalWithin(maxTime, MAX_TIME);
|
|
1088
|
+
if (decimalWithin(sequence, MAX_SEQUENCE) === undefined || parsedMinTime === undefined || parsedMaxTime === undefined || parsedMaxTime === 0n || parsedMinTime > parsedMaxTime) {
|
|
1089
|
+
throw new Error('Stellar transaction intent requires an account sequence and time bounds');
|
|
1090
|
+
}
|
|
1091
|
+
return {
|
|
1092
|
+
sequence: sequence,
|
|
1093
|
+
minTime: minTime,
|
|
1094
|
+
maxTime: maxTime
|
|
1095
|
+
};
|
|
1096
|
+
};
|
|
1097
|
+
/**
|
|
1098
|
+
* Rebuilds the envelope of an approved Stellar transaction operation. The
|
|
1099
|
+
* operation carries the total fee, but the builder prices every operation at a
|
|
1100
|
+
* base fee, so a total that is not a multiple of the operation count is written
|
|
1101
|
+
* onto the envelope after the build.
|
|
1102
|
+
*/ var buildStellarTransaction = function(param) {
|
|
1103
|
+
var operation = param.operation, lifetime = param.lifetime;
|
|
1104
|
+
var totalFee = decimalWithin(operation.fee, MAX_FEE);
|
|
1105
|
+
var count = BigInt(operation.operations.length);
|
|
1106
|
+
if (totalFee === undefined || count === 0n || count > BigInt(MAX_OPERATIONS) || !isAccount(operation.source)) {
|
|
1107
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1108
|
+
}
|
|
1109
|
+
var builder = new stellarSdk.TransactionBuilder(new stellarSdk.Account(operation.source, lifetime.sequence), {
|
|
1110
|
+
fee: (totalFee / count).toString(),
|
|
1111
|
+
networkPassphrase: getNetworkPassphraseFromChainId(assertStellarChainId(operation.chainId)),
|
|
1112
|
+
memo: buildMemo(operation.memo),
|
|
1113
|
+
timebounds: {
|
|
1114
|
+
minTime: lifetime.minTime,
|
|
1115
|
+
maxTime: lifetime.maxTime
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
operation.operations.forEach(function(stellarOperation) {
|
|
1119
|
+
return addOperation(builder, stellarOperation);
|
|
1120
|
+
});
|
|
1121
|
+
var envelope = builder.build().toEnvelope();
|
|
1122
|
+
envelope.v1().tx().fee(Number(totalFee));
|
|
1123
|
+
return envelope.toXDR('base64');
|
|
1124
|
+
};
|
|
1125
|
+
|
|
1126
|
+
function _array_like_to_array(arr, len) {
|
|
1127
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1128
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1129
|
+
return arr2;
|
|
1130
|
+
}
|
|
1131
|
+
function _array_with_holes(arr) {
|
|
1132
|
+
if (Array.isArray(arr)) return arr;
|
|
1133
|
+
}
|
|
1134
|
+
function _iterable_to_array_limit(arr, i) {
|
|
1135
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
1136
|
+
if (_i == null) return;
|
|
1137
|
+
var _arr = [];
|
|
1138
|
+
var _n = true;
|
|
1139
|
+
var _d = false;
|
|
1140
|
+
var _s, _e;
|
|
1141
|
+
try {
|
|
1142
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
1143
|
+
_arr.push(_s.value);
|
|
1144
|
+
if (i && _arr.length === i) break;
|
|
1145
|
+
}
|
|
1146
|
+
} catch (err) {
|
|
1147
|
+
_d = true;
|
|
1148
|
+
_e = err;
|
|
1149
|
+
} finally{
|
|
1150
|
+
try {
|
|
1151
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
1152
|
+
} finally{
|
|
1153
|
+
if (_d) throw _e;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return _arr;
|
|
1157
|
+
}
|
|
1158
|
+
function _non_iterable_rest() {
|
|
1159
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1160
|
+
}
|
|
1161
|
+
function _sliced_to_array(arr, i) {
|
|
1162
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
1163
|
+
}
|
|
1164
|
+
function _type_of(obj) {
|
|
1165
|
+
"@swc/helpers - typeof";
|
|
1166
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1167
|
+
}
|
|
1168
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
1169
|
+
if (!o) return;
|
|
1170
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1171
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1172
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1173
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1174
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Describes a Stellar transaction for a signing-quorum intent from its XDR
|
|
1178
|
+
* envelope. The sequence number and time bounds are not part of the
|
|
1179
|
+
* description: they are refreshed when the approved intent is resumed.
|
|
1180
|
+
*/ var prepareStellarTransactionSigningOperation = function(param) {
|
|
1181
|
+
var transaction = param.transaction, accountAddress = param.accountAddress, chainId = param.chainId;
|
|
1182
|
+
var operation = parseStellarTransaction({
|
|
1183
|
+
transaction: transaction,
|
|
1184
|
+
chainId: assertStellarChainId(chainId)
|
|
1185
|
+
});
|
|
1186
|
+
if (operation.source !== accountAddress) throw new Error('Stellar transaction source must be the signing account');
|
|
1187
|
+
return {
|
|
1188
|
+
operation: operation,
|
|
1189
|
+
lifetime: {
|
|
1190
|
+
refreshable: 'expiration'
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
};
|
|
1194
|
+
var byKey = function(param, param1) {
|
|
1195
|
+
var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
|
1196
|
+
if (a < b) return -1;
|
|
1197
|
+
if (a > b) return 1;
|
|
1198
|
+
return 0;
|
|
1199
|
+
};
|
|
1200
|
+
var withSortedKeys = function(_key, nested) {
|
|
1201
|
+
if (!nested || (typeof nested === "undefined" ? "undefined" : _type_of(nested)) !== 'object' || Array.isArray(nested)) return nested;
|
|
1202
|
+
return Object.fromEntries(Object.entries(nested).sort(byKey));
|
|
1203
|
+
};
|
|
1204
|
+
var canonicalJson = function(value) {
|
|
1205
|
+
return JSON.stringify(value, withSortedKeys);
|
|
1206
|
+
};
|
|
1207
|
+
var signedStellarOperation = function(intent) {
|
|
1208
|
+
var _intent_lifetime;
|
|
1209
|
+
var operation = intent.operation;
|
|
1210
|
+
if (operation.kind !== 'transaction' || operation.chainName !== 'STELLAR' || ((_intent_lifetime = intent.lifetime) === null || _intent_lifetime === void 0 ? void 0 : _intent_lifetime.refreshable) !== 'expiration') {
|
|
1211
|
+
throw new Error('Stored signing intent is not a Stellar transaction');
|
|
1212
|
+
}
|
|
1213
|
+
return operation;
|
|
1214
|
+
};
|
|
1215
|
+
/**
|
|
1216
|
+
* Rebuilds the XDR envelope of an approved Stellar transaction intent. The
|
|
1217
|
+
* signed intent carries no sequence number or time bounds, so the caller
|
|
1218
|
+
* supplies them as `lifetimeValue`, a JSON object with the account's current
|
|
1219
|
+
* `sequence` as Horizon returns it (the builder increments it) and `minTime`
|
|
1220
|
+
* and `maxTime` in seconds, all as decimal strings.
|
|
1221
|
+
*/ var resumeStellarTransactionSigningIntent = function(param) {
|
|
1222
|
+
var intent = param.intent, lifetimeValue = param.lifetimeValue;
|
|
1223
|
+
var operation = signedStellarOperation(intent);
|
|
1224
|
+
var lifetime = parseStellarTransactionLifetime(lifetimeValue);
|
|
1225
|
+
var transaction = buildStellarTransaction({
|
|
1226
|
+
operation: operation,
|
|
1227
|
+
lifetime: lifetime
|
|
1228
|
+
});
|
|
1229
|
+
var rebuilt = parseStellarTransaction({
|
|
1230
|
+
transaction: transaction,
|
|
1231
|
+
chainId: assertStellarChainId(operation.chainId)
|
|
1232
|
+
});
|
|
1233
|
+
if (canonicalJson(rebuilt) !== canonicalJson(operation)) {
|
|
1234
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1235
|
+
}
|
|
1236
|
+
return transaction;
|
|
1237
|
+
};
|
|
1238
|
+
|
|
832
1239
|
exports.sdkApiCore = sdkApiCore__namespace;
|
|
833
1240
|
exports.DynamicStellarWalletClient = DynamicStellarWalletClient;
|
|
834
1241
|
exports.STELLAR_HORIZON_URLS = STELLAR_HORIZON_URLS;
|
|
835
1242
|
exports.STELLAR_NETWORK_PASSPHRASES = STELLAR_NETWORK_PASSPHRASES;
|
|
1243
|
+
exports.prepareStellarTransactionSigningOperation = prepareStellarTransactionSigningOperation;
|
|
1244
|
+
exports.resumeStellarTransactionSigningIntent = resumeStellarTransactionSigningIntent;
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicWalletClient, ERROR_PASSWORD_MISMATCH, ERROR_MULTIPLE_WALLETS_PER_CHAIN, getMPCChainConfig, SigningConsentRequiredError } from '@dynamic-labs-wallet/browser';
|
|
2
|
-
import { StrKey, Keypair, TransactionBuilder } from '@stellar/stellar-sdk';
|
|
2
|
+
import { StrKey, Keypair, TransactionBuilder, xdr, Account, Memo, Operation, Asset } from '@stellar/stellar-sdk';
|
|
3
3
|
import * as sdkApiCore from '@dynamic-labs/sdk-api-core';
|
|
4
4
|
export { sdkApiCore };
|
|
5
5
|
|
|
@@ -45,9 +45,12 @@ var STELLAR_NETWORK_PASSPHRASES = {
|
|
|
45
45
|
'3': STELLAR_NETWORK_PASSPHRASES.FUTURENET
|
|
46
46
|
};
|
|
47
47
|
/**
|
|
48
|
-
* Gets the network passphrase from a numeric chainId,
|
|
48
|
+
* Gets the network passphrase from a numeric chainId, throws for any chainId other than '1', '2' or '3'
|
|
49
49
|
*/ var getNetworkPassphraseFromChainId = function(chainId) {
|
|
50
|
-
|
|
50
|
+
if (!Object.keys(STELLAR_CHAIN_ID_TO_PASSPHRASE).includes(chainId)) {
|
|
51
|
+
throw new Error('Unsupported Stellar chainId');
|
|
52
|
+
}
|
|
53
|
+
return STELLAR_CHAIN_ID_TO_PASSPHRASE[chainId];
|
|
51
54
|
};
|
|
52
55
|
|
|
53
56
|
function _assert_this_initialized(self) {
|
|
@@ -139,7 +142,7 @@ function _inherits(subClass, superClass) {
|
|
|
139
142
|
});
|
|
140
143
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
141
144
|
}
|
|
142
|
-
function _instanceof(left, right) {
|
|
145
|
+
function _instanceof$1(left, right) {
|
|
143
146
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
144
147
|
return !!right[Symbol.hasInstance](left);
|
|
145
148
|
} else {
|
|
@@ -181,7 +184,7 @@ function _object_spread_props(target, source) {
|
|
|
181
184
|
return target;
|
|
182
185
|
}
|
|
183
186
|
function _possible_constructor_return(self, call) {
|
|
184
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
187
|
+
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
185
188
|
return call;
|
|
186
189
|
}
|
|
187
190
|
return _assert_this_initialized(self);
|
|
@@ -193,7 +196,7 @@ function _set_prototype_of(o, p) {
|
|
|
193
196
|
};
|
|
194
197
|
return _set_prototype_of(o, p);
|
|
195
198
|
}
|
|
196
|
-
function _type_of(obj) {
|
|
199
|
+
function _type_of$1(obj) {
|
|
197
200
|
"@swc/helpers - typeof";
|
|
198
201
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
199
202
|
}
|
|
@@ -405,7 +408,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
405
408
|
case 5:
|
|
406
409
|
error = _state.sent();
|
|
407
410
|
// Re-throw known business-rule rejections without wrapping
|
|
408
|
-
if (_instanceof(error, Error) && (error.message === ERROR_PASSWORD_MISMATCH || error.message === ERROR_MULTIPLE_WALLETS_PER_CHAIN)) {
|
|
411
|
+
if (_instanceof$1(error, Error) && (error.message === ERROR_PASSWORD_MISMATCH || error.message === ERROR_MULTIPLE_WALLETS_PER_CHAIN)) {
|
|
409
412
|
throw error;
|
|
410
413
|
}
|
|
411
414
|
_this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
@@ -624,7 +627,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
624
627
|
error = _state.sent();
|
|
625
628
|
// Not a failure: the export needs approvals, and the caller needs the
|
|
626
629
|
// reason and proposalId to continue.
|
|
627
|
-
if (_instanceof(error, SigningConsentRequiredError)) throw error;
|
|
630
|
+
if (_instanceof$1(error, SigningConsentRequiredError)) throw error;
|
|
628
631
|
_this.logger.error(ERROR_EXPORT_PRIVATE_KEY, error);
|
|
629
632
|
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
|
630
633
|
case 3:
|
|
@@ -773,7 +776,7 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
773
776
|
return b.toString(16).padStart(2, '0');
|
|
774
777
|
}).join('');
|
|
775
778
|
} catch (error) {
|
|
776
|
-
this.logger.error('Unable to derive public key from private key. Check private key format', _instanceof(error, Error) ? error.message : 'Unknown error');
|
|
779
|
+
this.logger.error('Unable to derive public key from private key. Check private key format', _instanceof$1(error, Error) ? error.message : 'Unknown error');
|
|
777
780
|
throw error;
|
|
778
781
|
}
|
|
779
782
|
}
|
|
@@ -809,4 +812,408 @@ var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
809
812
|
return DynamicStellarWalletClient;
|
|
810
813
|
}(DynamicWalletClient);
|
|
811
814
|
|
|
812
|
-
|
|
815
|
+
function _instanceof(left, right) {
|
|
816
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
817
|
+
return !!right[Symbol.hasInstance](left);
|
|
818
|
+
} else {
|
|
819
|
+
return left instanceof right;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
var MAX_OPERATIONS = 100;
|
|
823
|
+
var MAX_PATH_ASSETS = 5;
|
|
824
|
+
var MAX_MEMO_TEXT_BYTES = 28;
|
|
825
|
+
var MAX_FEE = 4294967295n;
|
|
826
|
+
var MAX_SEQUENCE = 9223372036854775806n;
|
|
827
|
+
var MAX_TIME = 18446744073709551615n;
|
|
828
|
+
var DECIMAL = /^(0|[1-9]\d*)$/;
|
|
829
|
+
var HEX_32_BYTES = /^[0-9a-f]{64}$/;
|
|
830
|
+
var assertStellarChainId = function(chainId) {
|
|
831
|
+
if (chainId !== '1' && chainId !== '2' && chainId !== '3') {
|
|
832
|
+
throw new Error('Stellar signing intent requires a network chainId of 1, 2 or 3');
|
|
833
|
+
}
|
|
834
|
+
return chainId;
|
|
835
|
+
};
|
|
836
|
+
var isAccount = function(address) {
|
|
837
|
+
return StrKey.isValidEd25519PublicKey(address);
|
|
838
|
+
};
|
|
839
|
+
var assertAccount = function(address, message) {
|
|
840
|
+
if (!isAccount(address)) throw new Error(message);
|
|
841
|
+
return address;
|
|
842
|
+
};
|
|
843
|
+
var describeAsset = function(asset) {
|
|
844
|
+
if (!_instanceof(asset, Asset)) throw new Error('Stellar signing intent does not support liquidity pool assets');
|
|
845
|
+
return asset.isNative() ? 'native' : "".concat(asset.getCode(), ":").concat(asset.getIssuer());
|
|
846
|
+
};
|
|
847
|
+
var toAsset = function(asset) {
|
|
848
|
+
if (asset === 'native') return Asset.native();
|
|
849
|
+
var separator = asset.indexOf(':');
|
|
850
|
+
return new Asset(asset.slice(0, separator), asset.slice(separator + 1));
|
|
851
|
+
};
|
|
852
|
+
var toBytes = function(value) {
|
|
853
|
+
if (value === null) throw new Error('Stellar signing intent does not support this memo type');
|
|
854
|
+
return typeof value === 'string' ? new TextEncoder().encode(value) : Uint8Array.from(value);
|
|
855
|
+
};
|
|
856
|
+
var toHex = function(bytes) {
|
|
857
|
+
return Array.from(bytes, function(byte) {
|
|
858
|
+
return byte.toString(16).padStart(2, '0');
|
|
859
|
+
}).join('');
|
|
860
|
+
};
|
|
861
|
+
var describeMemo = function(memo) {
|
|
862
|
+
switch(memo.type){
|
|
863
|
+
case 'none':
|
|
864
|
+
return {
|
|
865
|
+
type: 'none'
|
|
866
|
+
};
|
|
867
|
+
case 'id':
|
|
868
|
+
return {
|
|
869
|
+
type: 'id',
|
|
870
|
+
value: String(memo.value)
|
|
871
|
+
};
|
|
872
|
+
case 'text':
|
|
873
|
+
{
|
|
874
|
+
var bytes = toBytes(memo.value);
|
|
875
|
+
var value;
|
|
876
|
+
try {
|
|
877
|
+
value = new TextDecoder('utf-8', {
|
|
878
|
+
fatal: true,
|
|
879
|
+
ignoreBOM: true
|
|
880
|
+
}).decode(bytes);
|
|
881
|
+
} catch (e) {
|
|
882
|
+
throw new Error('Stellar signing intent requires a UTF-8 text memo');
|
|
883
|
+
}
|
|
884
|
+
if (bytes.length > MAX_MEMO_TEXT_BYTES) throw new Error('Stellar text memo is too long');
|
|
885
|
+
return {
|
|
886
|
+
type: 'text',
|
|
887
|
+
value: value
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
case 'hash':
|
|
891
|
+
case 'return':
|
|
892
|
+
return {
|
|
893
|
+
type: memo.type,
|
|
894
|
+
value: toHex(toBytes(memo.value))
|
|
895
|
+
};
|
|
896
|
+
default:
|
|
897
|
+
throw new Error('Stellar signing intent does not support this memo type');
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
var describePath = function(path) {
|
|
901
|
+
if (path.length > MAX_PATH_ASSETS) throw new Error('Stellar path payment path is too long');
|
|
902
|
+
return path.map(describeAsset);
|
|
903
|
+
};
|
|
904
|
+
var describeOperation = function(operation) {
|
|
905
|
+
if (operation.source !== undefined) throw new Error('Stellar signing intent does not support operation sources');
|
|
906
|
+
switch(operation.type){
|
|
907
|
+
case 'payment':
|
|
908
|
+
return {
|
|
909
|
+
type: 'payment',
|
|
910
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
911
|
+
asset: describeAsset(operation.asset),
|
|
912
|
+
amount: operation.amount
|
|
913
|
+
};
|
|
914
|
+
case 'pathPaymentStrictSend':
|
|
915
|
+
return {
|
|
916
|
+
type: 'pathPaymentStrictSend',
|
|
917
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
918
|
+
sendAsset: describeAsset(operation.sendAsset),
|
|
919
|
+
sendAmount: operation.sendAmount,
|
|
920
|
+
destAsset: describeAsset(operation.destAsset),
|
|
921
|
+
destMin: operation.destMin,
|
|
922
|
+
path: describePath(operation.path)
|
|
923
|
+
};
|
|
924
|
+
case 'pathPaymentStrictReceive':
|
|
925
|
+
return {
|
|
926
|
+
type: 'pathPaymentStrictReceive',
|
|
927
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
928
|
+
sendAsset: describeAsset(operation.sendAsset),
|
|
929
|
+
sendMax: operation.sendMax,
|
|
930
|
+
destAsset: describeAsset(operation.destAsset),
|
|
931
|
+
destAmount: operation.destAmount,
|
|
932
|
+
path: describePath(operation.path)
|
|
933
|
+
};
|
|
934
|
+
case 'createAccount':
|
|
935
|
+
return {
|
|
936
|
+
type: 'createAccount',
|
|
937
|
+
destination: assertAccount(operation.destination, 'Stellar signing intent does not support muxed accounts'),
|
|
938
|
+
startingBalance: operation.startingBalance
|
|
939
|
+
};
|
|
940
|
+
case 'changeTrust':
|
|
941
|
+
return {
|
|
942
|
+
type: 'changeTrust',
|
|
943
|
+
asset: describeAsset(operation.line),
|
|
944
|
+
limit: operation.limit
|
|
945
|
+
};
|
|
946
|
+
default:
|
|
947
|
+
throw new Error("Stellar signing intent does not support the ".concat(operation.type, " operation"));
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
var assertClassicEnvelope = function(envelope) {
|
|
951
|
+
if (envelope.switch().name !== 'envelopeTypeTx') {
|
|
952
|
+
throw new Error('Stellar signing intent supports only v1 transaction envelopes, not fee-bump envelopes');
|
|
953
|
+
}
|
|
954
|
+
var tx = envelope.v1().tx();
|
|
955
|
+
if (tx.cond().switch().name !== 'precondTime') {
|
|
956
|
+
throw new Error('Stellar signing intent supports only time-bound preconditions');
|
|
957
|
+
}
|
|
958
|
+
if (tx.ext().switch() !== 0) throw new Error('Stellar signing intent does not support Soroban transactions');
|
|
959
|
+
return envelope.v1();
|
|
960
|
+
};
|
|
961
|
+
/**
|
|
962
|
+
* Describes a classic Stellar transaction envelope for a signing-quorum intent.
|
|
963
|
+
* The sequence number and time bounds are not part of the description: they are
|
|
964
|
+
* refreshed when the approved intent is resumed.
|
|
965
|
+
*/ var parseStellarTransaction = function(param) {
|
|
966
|
+
var transaction = param.transaction, chainId = param.chainId;
|
|
967
|
+
var envelope;
|
|
968
|
+
try {
|
|
969
|
+
envelope = xdr.TransactionEnvelope.fromXDR(transaction, 'base64');
|
|
970
|
+
} catch (e) {
|
|
971
|
+
throw new Error('Stellar signing intent requires a base64 XDR transaction envelope');
|
|
972
|
+
}
|
|
973
|
+
if (envelope.toXDR('base64') !== transaction) {
|
|
974
|
+
throw new Error('Stellar signing intent requires a canonical XDR transaction envelope');
|
|
975
|
+
}
|
|
976
|
+
assertClassicEnvelope(envelope);
|
|
977
|
+
var parsed = TransactionBuilder.fromXDR(transaction, getNetworkPassphraseFromChainId(chainId));
|
|
978
|
+
if (!isAccount(parsed.source)) throw new Error('Stellar signing intent does not support muxed accounts');
|
|
979
|
+
if (parsed.operations.length === 0 || parsed.operations.length > MAX_OPERATIONS) {
|
|
980
|
+
throw new Error('Stellar signing intent requires between 1 and 100 operations');
|
|
981
|
+
}
|
|
982
|
+
return {
|
|
983
|
+
kind: 'transaction',
|
|
984
|
+
chainName: 'STELLAR',
|
|
985
|
+
chainId: chainId,
|
|
986
|
+
source: parsed.source,
|
|
987
|
+
fee: parsed.fee,
|
|
988
|
+
memo: describeMemo(parsed.memo),
|
|
989
|
+
operations: parsed.operations.map(describeOperation)
|
|
990
|
+
};
|
|
991
|
+
};
|
|
992
|
+
var buildMemo = function(memo) {
|
|
993
|
+
switch(memo.type){
|
|
994
|
+
case 'none':
|
|
995
|
+
return Memo.none();
|
|
996
|
+
case 'text':
|
|
997
|
+
return Memo.text(memo.value);
|
|
998
|
+
case 'id':
|
|
999
|
+
return Memo.id(memo.value);
|
|
1000
|
+
case 'hash':
|
|
1001
|
+
case 'return':
|
|
1002
|
+
if (!HEX_32_BYTES.test(memo.value)) throw new Error('Stored Stellar transaction intent is malformed');
|
|
1003
|
+
return memo.type === 'hash' ? Memo.hash(memo.value) : Memo.return(memo.value);
|
|
1004
|
+
default:
|
|
1005
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
var addOperation = function(builder, operation) {
|
|
1009
|
+
switch(operation.type){
|
|
1010
|
+
case 'payment':
|
|
1011
|
+
builder.addOperation(Operation.payment({
|
|
1012
|
+
destination: operation.destination,
|
|
1013
|
+
asset: toAsset(operation.asset),
|
|
1014
|
+
amount: operation.amount
|
|
1015
|
+
}));
|
|
1016
|
+
return;
|
|
1017
|
+
case 'pathPaymentStrictSend':
|
|
1018
|
+
builder.addOperation(Operation.pathPaymentStrictSend({
|
|
1019
|
+
destination: operation.destination,
|
|
1020
|
+
sendAsset: toAsset(operation.sendAsset),
|
|
1021
|
+
sendAmount: operation.sendAmount,
|
|
1022
|
+
destAsset: toAsset(operation.destAsset),
|
|
1023
|
+
destMin: operation.destMin,
|
|
1024
|
+
path: operation.path.map(toAsset)
|
|
1025
|
+
}));
|
|
1026
|
+
return;
|
|
1027
|
+
case 'pathPaymentStrictReceive':
|
|
1028
|
+
builder.addOperation(Operation.pathPaymentStrictReceive({
|
|
1029
|
+
destination: operation.destination,
|
|
1030
|
+
sendAsset: toAsset(operation.sendAsset),
|
|
1031
|
+
sendMax: operation.sendMax,
|
|
1032
|
+
destAsset: toAsset(operation.destAsset),
|
|
1033
|
+
destAmount: operation.destAmount,
|
|
1034
|
+
path: operation.path.map(toAsset)
|
|
1035
|
+
}));
|
|
1036
|
+
return;
|
|
1037
|
+
case 'createAccount':
|
|
1038
|
+
builder.addOperation(Operation.createAccount({
|
|
1039
|
+
destination: operation.destination,
|
|
1040
|
+
startingBalance: operation.startingBalance
|
|
1041
|
+
}));
|
|
1042
|
+
return;
|
|
1043
|
+
case 'changeTrust':
|
|
1044
|
+
builder.addOperation(Operation.changeTrust({
|
|
1045
|
+
asset: toAsset(operation.asset),
|
|
1046
|
+
limit: operation.limit
|
|
1047
|
+
}));
|
|
1048
|
+
return;
|
|
1049
|
+
default:
|
|
1050
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
var decimalWithin = function(value, max) {
|
|
1054
|
+
if (typeof value !== 'string' || !DECIMAL.test(value)) return undefined;
|
|
1055
|
+
var parsed = BigInt(value);
|
|
1056
|
+
return parsed <= max ? parsed : undefined;
|
|
1057
|
+
};
|
|
1058
|
+
var parseStellarTransactionLifetime = function(lifetimeValue) {
|
|
1059
|
+
var parsed;
|
|
1060
|
+
try {
|
|
1061
|
+
parsed = lifetimeValue ? JSON.parse(lifetimeValue) : undefined;
|
|
1062
|
+
} catch (e) {
|
|
1063
|
+
parsed = undefined;
|
|
1064
|
+
}
|
|
1065
|
+
var _ref = parsed !== null && parsed !== void 0 ? parsed : {}, sequence = _ref.sequence, minTime = _ref.minTime, maxTime = _ref.maxTime;
|
|
1066
|
+
var parsedMinTime = decimalWithin(minTime, MAX_TIME);
|
|
1067
|
+
var parsedMaxTime = decimalWithin(maxTime, MAX_TIME);
|
|
1068
|
+
if (decimalWithin(sequence, MAX_SEQUENCE) === undefined || parsedMinTime === undefined || parsedMaxTime === undefined || parsedMaxTime === 0n || parsedMinTime > parsedMaxTime) {
|
|
1069
|
+
throw new Error('Stellar transaction intent requires an account sequence and time bounds');
|
|
1070
|
+
}
|
|
1071
|
+
return {
|
|
1072
|
+
sequence: sequence,
|
|
1073
|
+
minTime: minTime,
|
|
1074
|
+
maxTime: maxTime
|
|
1075
|
+
};
|
|
1076
|
+
};
|
|
1077
|
+
/**
|
|
1078
|
+
* Rebuilds the envelope of an approved Stellar transaction operation. The
|
|
1079
|
+
* operation carries the total fee, but the builder prices every operation at a
|
|
1080
|
+
* base fee, so a total that is not a multiple of the operation count is written
|
|
1081
|
+
* onto the envelope after the build.
|
|
1082
|
+
*/ var buildStellarTransaction = function(param) {
|
|
1083
|
+
var operation = param.operation, lifetime = param.lifetime;
|
|
1084
|
+
var totalFee = decimalWithin(operation.fee, MAX_FEE);
|
|
1085
|
+
var count = BigInt(operation.operations.length);
|
|
1086
|
+
if (totalFee === undefined || count === 0n || count > BigInt(MAX_OPERATIONS) || !isAccount(operation.source)) {
|
|
1087
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1088
|
+
}
|
|
1089
|
+
var builder = new TransactionBuilder(new Account(operation.source, lifetime.sequence), {
|
|
1090
|
+
fee: (totalFee / count).toString(),
|
|
1091
|
+
networkPassphrase: getNetworkPassphraseFromChainId(assertStellarChainId(operation.chainId)),
|
|
1092
|
+
memo: buildMemo(operation.memo),
|
|
1093
|
+
timebounds: {
|
|
1094
|
+
minTime: lifetime.minTime,
|
|
1095
|
+
maxTime: lifetime.maxTime
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
operation.operations.forEach(function(stellarOperation) {
|
|
1099
|
+
return addOperation(builder, stellarOperation);
|
|
1100
|
+
});
|
|
1101
|
+
var envelope = builder.build().toEnvelope();
|
|
1102
|
+
envelope.v1().tx().fee(Number(totalFee));
|
|
1103
|
+
return envelope.toXDR('base64');
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
function _array_like_to_array(arr, len) {
|
|
1107
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1108
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1109
|
+
return arr2;
|
|
1110
|
+
}
|
|
1111
|
+
function _array_with_holes(arr) {
|
|
1112
|
+
if (Array.isArray(arr)) return arr;
|
|
1113
|
+
}
|
|
1114
|
+
function _iterable_to_array_limit(arr, i) {
|
|
1115
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
1116
|
+
if (_i == null) return;
|
|
1117
|
+
var _arr = [];
|
|
1118
|
+
var _n = true;
|
|
1119
|
+
var _d = false;
|
|
1120
|
+
var _s, _e;
|
|
1121
|
+
try {
|
|
1122
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
1123
|
+
_arr.push(_s.value);
|
|
1124
|
+
if (i && _arr.length === i) break;
|
|
1125
|
+
}
|
|
1126
|
+
} catch (err) {
|
|
1127
|
+
_d = true;
|
|
1128
|
+
_e = err;
|
|
1129
|
+
} finally{
|
|
1130
|
+
try {
|
|
1131
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
1132
|
+
} finally{
|
|
1133
|
+
if (_d) throw _e;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return _arr;
|
|
1137
|
+
}
|
|
1138
|
+
function _non_iterable_rest() {
|
|
1139
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1140
|
+
}
|
|
1141
|
+
function _sliced_to_array(arr, i) {
|
|
1142
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
1143
|
+
}
|
|
1144
|
+
function _type_of(obj) {
|
|
1145
|
+
"@swc/helpers - typeof";
|
|
1146
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1147
|
+
}
|
|
1148
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
1149
|
+
if (!o) return;
|
|
1150
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1151
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1152
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1153
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1154
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Describes a Stellar transaction for a signing-quorum intent from its XDR
|
|
1158
|
+
* envelope. The sequence number and time bounds are not part of the
|
|
1159
|
+
* description: they are refreshed when the approved intent is resumed.
|
|
1160
|
+
*/ var prepareStellarTransactionSigningOperation = function(param) {
|
|
1161
|
+
var transaction = param.transaction, accountAddress = param.accountAddress, chainId = param.chainId;
|
|
1162
|
+
var operation = parseStellarTransaction({
|
|
1163
|
+
transaction: transaction,
|
|
1164
|
+
chainId: assertStellarChainId(chainId)
|
|
1165
|
+
});
|
|
1166
|
+
if (operation.source !== accountAddress) throw new Error('Stellar transaction source must be the signing account');
|
|
1167
|
+
return {
|
|
1168
|
+
operation: operation,
|
|
1169
|
+
lifetime: {
|
|
1170
|
+
refreshable: 'expiration'
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
1174
|
+
var byKey = function(param, param1) {
|
|
1175
|
+
var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
|
1176
|
+
if (a < b) return -1;
|
|
1177
|
+
if (a > b) return 1;
|
|
1178
|
+
return 0;
|
|
1179
|
+
};
|
|
1180
|
+
var withSortedKeys = function(_key, nested) {
|
|
1181
|
+
if (!nested || (typeof nested === "undefined" ? "undefined" : _type_of(nested)) !== 'object' || Array.isArray(nested)) return nested;
|
|
1182
|
+
return Object.fromEntries(Object.entries(nested).sort(byKey));
|
|
1183
|
+
};
|
|
1184
|
+
var canonicalJson = function(value) {
|
|
1185
|
+
return JSON.stringify(value, withSortedKeys);
|
|
1186
|
+
};
|
|
1187
|
+
var signedStellarOperation = function(intent) {
|
|
1188
|
+
var _intent_lifetime;
|
|
1189
|
+
var operation = intent.operation;
|
|
1190
|
+
if (operation.kind !== 'transaction' || operation.chainName !== 'STELLAR' || ((_intent_lifetime = intent.lifetime) === null || _intent_lifetime === void 0 ? void 0 : _intent_lifetime.refreshable) !== 'expiration') {
|
|
1191
|
+
throw new Error('Stored signing intent is not a Stellar transaction');
|
|
1192
|
+
}
|
|
1193
|
+
return operation;
|
|
1194
|
+
};
|
|
1195
|
+
/**
|
|
1196
|
+
* Rebuilds the XDR envelope of an approved Stellar transaction intent. The
|
|
1197
|
+
* signed intent carries no sequence number or time bounds, so the caller
|
|
1198
|
+
* supplies them as `lifetimeValue`, a JSON object with the account's current
|
|
1199
|
+
* `sequence` as Horizon returns it (the builder increments it) and `minTime`
|
|
1200
|
+
* and `maxTime` in seconds, all as decimal strings.
|
|
1201
|
+
*/ var resumeStellarTransactionSigningIntent = function(param) {
|
|
1202
|
+
var intent = param.intent, lifetimeValue = param.lifetimeValue;
|
|
1203
|
+
var operation = signedStellarOperation(intent);
|
|
1204
|
+
var lifetime = parseStellarTransactionLifetime(lifetimeValue);
|
|
1205
|
+
var transaction = buildStellarTransaction({
|
|
1206
|
+
operation: operation,
|
|
1207
|
+
lifetime: lifetime
|
|
1208
|
+
});
|
|
1209
|
+
var rebuilt = parseStellarTransaction({
|
|
1210
|
+
transaction: transaction,
|
|
1211
|
+
chainId: assertStellarChainId(operation.chainId)
|
|
1212
|
+
});
|
|
1213
|
+
if (canonicalJson(rebuilt) !== canonicalJson(operation)) {
|
|
1214
|
+
throw new Error('Stored Stellar transaction intent is malformed');
|
|
1215
|
+
}
|
|
1216
|
+
return transaction;
|
|
1217
|
+
};
|
|
1218
|
+
|
|
1219
|
+
export { DynamicStellarWalletClient, STELLAR_HORIZON_URLS, STELLAR_NETWORK_PASSPHRASES, prepareStellarTransactionSigningOperation, resumeStellarTransactionSigningIntent };
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/stellar",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.80",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/browser": "1.1.
|
|
7
|
+
"@dynamic-labs-wallet/browser": "1.1.80",
|
|
8
8
|
"@stellar/stellar-sdk": "^12.3.0",
|
|
9
9
|
"@dynamic-labs/sdk-api-core": "0.167.0"
|
|
10
10
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './client/index.js';
|
|
2
2
|
export { STELLAR_NETWORK_PASSPHRASES, STELLAR_HORIZON_URLS, type StellarNetwork } from './client/constants.js';
|
|
3
3
|
export * as sdkApiCore from '@dynamic-labs/sdk-api-core';
|
|
4
|
+
export { prepareStellarTransactionSigningOperation, resumeStellarTransactionSigningIntent } from './signingIntent.js';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/G,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/G,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,yCAAyC,EAAE,qCAAqC,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PreparedStellarTransactionSigningIntent, SigningIntent } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
/**
|
|
3
|
+
* Describes a Stellar transaction for a signing-quorum intent from its XDR
|
|
4
|
+
* envelope. The sequence number and time bounds are not part of the
|
|
5
|
+
* description: they are refreshed when the approved intent is resumed.
|
|
6
|
+
*/
|
|
7
|
+
export declare const prepareStellarTransactionSigningOperation: ({ transaction, accountAddress, chainId, }: {
|
|
8
|
+
transaction: string;
|
|
9
|
+
accountAddress: string;
|
|
10
|
+
chainId: string | undefined;
|
|
11
|
+
}) => PreparedStellarTransactionSigningIntent;
|
|
12
|
+
/**
|
|
13
|
+
* Rebuilds the XDR envelope of an approved Stellar transaction intent. The
|
|
14
|
+
* signed intent carries no sequence number or time bounds, so the caller
|
|
15
|
+
* supplies them as `lifetimeValue`, a JSON object with the account's current
|
|
16
|
+
* `sequence` as Horizon returns it (the builder increments it) and `minTime`
|
|
17
|
+
* and `maxTime` in seconds, all as decimal strings.
|
|
18
|
+
*/
|
|
19
|
+
export declare const resumeStellarTransactionSigningIntent: ({ intent, lifetimeValue, }: {
|
|
20
|
+
intent: SigningIntent;
|
|
21
|
+
lifetimeValue: string | undefined;
|
|
22
|
+
}) => string;
|
|
23
|
+
//# sourceMappingURL=signingIntent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signingIntent.d.ts","sourceRoot":"","sources":["../../packages/src/signingIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uCAAuC,EACvC,aAAa,EAEd,MAAM,8BAA8B,CAAC;AAQtC;;;;GAIG;AACH,eAAO,MAAM,yCAAyC,8CAInD;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,KAAG,uCAKH,CAAC;AA2BF;;;;;;GAMG;AACH,eAAO,MAAM,qCAAqC,+BAG/C;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC,KAAG,MAUH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { StellarTransactionOperation } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
export type StellarTransactionChainId = StellarTransactionOperation['chainId'];
|
|
3
|
+
export type StellarTransactionLifetime = {
|
|
4
|
+
sequence: string;
|
|
5
|
+
minTime: string;
|
|
6
|
+
maxTime: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const assertStellarChainId: (chainId: string | undefined) => StellarTransactionChainId;
|
|
9
|
+
/**
|
|
10
|
+
* Describes a classic Stellar transaction envelope for a signing-quorum intent.
|
|
11
|
+
* The sequence number and time bounds are not part of the description: they are
|
|
12
|
+
* refreshed when the approved intent is resumed.
|
|
13
|
+
*/
|
|
14
|
+
export declare const parseStellarTransaction: ({ transaction, chainId, }: {
|
|
15
|
+
transaction: string;
|
|
16
|
+
chainId: StellarTransactionChainId;
|
|
17
|
+
}) => StellarTransactionOperation;
|
|
18
|
+
export declare const parseStellarTransactionLifetime: (lifetimeValue: string | undefined) => StellarTransactionLifetime;
|
|
19
|
+
/**
|
|
20
|
+
* Rebuilds the envelope of an approved Stellar transaction operation. The
|
|
21
|
+
* operation carries the total fee, but the builder prices every operation at a
|
|
22
|
+
* base fee, so a total that is not a multiple of the operation count is written
|
|
23
|
+
* onto the envelope after the build.
|
|
24
|
+
*/
|
|
25
|
+
export declare const buildStellarTransaction: ({ operation, lifetime, }: {
|
|
26
|
+
operation: StellarTransactionOperation;
|
|
27
|
+
lifetime: StellarTransactionLifetime;
|
|
28
|
+
}) => string;
|
|
29
|
+
//# sourceMappingURL=stellarXdr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stellarXdr.d.ts","sourceRoot":"","sources":["../../packages/src/stellarXdr.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAiC,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAG/G,MAAM,MAAM,yBAAyB,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;AAE/E,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAWF,eAAO,MAAM,oBAAoB,YAAa,MAAM,GAAG,SAAS,KAAG,yBAKlE,CAAC;AAmHF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,8BAGjC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,yBAAyB,CAAC;CACpC,KAAG,2BA2BH,CAAC;AAyEF,eAAO,MAAM,+BAA+B,kBAAmB,MAAM,GAAG,SAAS,KAAG,0BAoBnF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,6BAGjC;IACD,SAAS,EAAE,2BAA2B,CAAC;IACvC,QAAQ,EAAE,0BAA0B,CAAC;CACtC,KAAG,MAkBH,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const STELLAR_CHAIN_ID_TO_PASSPHRASE: Record<string, string>;
|
|
6
6
|
/**
|
|
7
|
-
* Gets the network passphrase from a numeric chainId,
|
|
7
|
+
* Gets the network passphrase from a numeric chainId, throws for any chainId other than '1', '2' or '3'
|
|
8
8
|
*/
|
|
9
9
|
export declare const getNetworkPassphraseFromChainId: (chainId: string) => string;
|
|
10
10
|
//# sourceMappingURL=getNetworkPassphrase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNetworkPassphrase.d.ts","sourceRoot":"","sources":["../../../src/utils/getNetworkPassphrase/getNetworkPassphrase.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIjE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,+BAA+B,YAAa,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"getNetworkPassphrase.d.ts","sourceRoot":"","sources":["../../../src/utils/getNetworkPassphrase/getNetworkPassphrase.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIjE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,+BAA+B,YAAa,MAAM,KAAG,MAKjE,CAAC"}
|