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