@stellar/stellar-sdk 14.6.1 → 15.0.1
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/dist/stellar-sdk-minimal.js +18890 -18853
- package/dist/stellar-sdk-minimal.min.js +1 -1
- package/dist/stellar-sdk-no-axios.js +30113 -29952
- package/dist/stellar-sdk-no-axios.min.js +1 -1
- package/dist/stellar-sdk-no-eventsource.js +22770 -22385
- package/dist/stellar-sdk-no-eventsource.min.js +1 -1
- package/dist/stellar-sdk.js +34122 -33613
- package/dist/stellar-sdk.min.js +1 -1
- package/lib/bindings/client.js +3 -3
- package/lib/bindings/types.js +5 -5
- package/lib/bindings/utils.d.ts +4 -0
- package/lib/bindings/utils.js +13 -5
- package/lib/contract/assembled_transaction.d.ts +5 -0
- package/lib/contract/assembled_transaction.js +38 -9
- package/lib/horizon/horizon_axios_client.js +1 -1
- package/lib/minimal/bindings/client.js +3 -3
- package/lib/minimal/bindings/types.js +5 -5
- package/lib/minimal/bindings/utils.d.ts +4 -0
- package/lib/minimal/bindings/utils.js +13 -5
- package/lib/minimal/contract/assembled_transaction.d.ts +5 -0
- package/lib/minimal/contract/assembled_transaction.js +38 -9
- package/lib/minimal/horizon/horizon_axios_client.js +1 -1
- package/lib/minimal/rpc/axios.js +1 -1
- package/lib/minimal/webauth/challenge_transaction.js +1 -1
- package/lib/no-axios/bindings/client.js +3 -3
- package/lib/no-axios/bindings/types.js +5 -5
- package/lib/no-axios/bindings/utils.d.ts +4 -0
- package/lib/no-axios/bindings/utils.js +13 -5
- package/lib/no-axios/contract/assembled_transaction.d.ts +5 -0
- package/lib/no-axios/contract/assembled_transaction.js +38 -9
- package/lib/no-axios/horizon/horizon_axios_client.js +1 -1
- package/lib/no-axios/rpc/axios.js +1 -1
- package/lib/no-axios/webauth/challenge_transaction.js +1 -1
- package/lib/no-eventsource/bindings/client.js +3 -3
- package/lib/no-eventsource/bindings/types.js +5 -5
- package/lib/no-eventsource/bindings/utils.d.ts +4 -0
- package/lib/no-eventsource/bindings/utils.js +13 -5
- package/lib/no-eventsource/contract/assembled_transaction.d.ts +5 -0
- package/lib/no-eventsource/contract/assembled_transaction.js +38 -9
- package/lib/no-eventsource/horizon/horizon_axios_client.js +1 -1
- package/lib/no-eventsource/rpc/axios.js +1 -1
- package/lib/no-eventsource/webauth/challenge_transaction.js +1 -1
- package/lib/rpc/axios.js +1 -1
- package/lib/webauth/challenge_transaction.js +1 -1
- package/package.json +26 -26
package/lib/bindings/client.js
CHANGED
|
@@ -65,7 +65,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
65
65
|
var name = (0, _utils.sanitizeIdentifier)(func.name().toString());
|
|
66
66
|
var inputs = func.inputs().map(function (input) {
|
|
67
67
|
return {
|
|
68
|
-
name: input.name().toString(),
|
|
68
|
+
name: (0, _utils.sanitizeIdentifier)(input.name().toString()),
|
|
69
69
|
type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
|
|
70
70
|
};
|
|
71
71
|
});
|
|
@@ -77,7 +77,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
77
77
|
}, {
|
|
78
78
|
key: "generateFromJSONMethod",
|
|
79
79
|
value: function generateFromJSONMethod(func) {
|
|
80
|
-
var name = func.name().toString();
|
|
80
|
+
var name = (0, _utils.sanitizeIdentifier)(func.name().toString());
|
|
81
81
|
var outputType = func.outputs().length > 0 ? (0, _utils.parseTypeFromTypeDef)(func.outputs()[0]) : "void";
|
|
82
82
|
return " ".concat(name, " : this.txFromJSON<").concat(outputType, ">");
|
|
83
83
|
}
|
|
@@ -90,7 +90,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
90
90
|
}
|
|
91
91
|
var inputs = constructorFunc.inputs().map(function (input) {
|
|
92
92
|
return {
|
|
93
|
-
name: input.name().toString(),
|
|
93
|
+
name: (0, _utils.sanitizeIdentifier)(input.name().toString()),
|
|
94
94
|
type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
|
|
95
95
|
};
|
|
96
96
|
});
|
package/lib/bindings/types.js
CHANGED
|
@@ -82,7 +82,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
82
82
|
var name = (0, _utils.sanitizeIdentifier)(struct.name().toString());
|
|
83
83
|
var doc = (0, _utils.formatJSDocComment)(struct.doc().toString() || "Struct: ".concat(name), 0);
|
|
84
84
|
var fields = struct.fields().map(function (field) {
|
|
85
|
-
var fieldName = field.name().toString();
|
|
85
|
+
var fieldName = (0, _utils.sanitizeIdentifier)(field.name().toString());
|
|
86
86
|
var fieldType = (0, _utils.parseTypeFromTypeDef)(field.type());
|
|
87
87
|
var fieldDoc = (0, _utils.formatJSDocComment)(field.doc().toString(), 2);
|
|
88
88
|
return "".concat(fieldDoc, " ").concat(fieldName, ": ").concat(fieldType, ";");
|
|
@@ -100,9 +100,9 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
100
100
|
});
|
|
101
101
|
var caseTypes = cases.map(function (c) {
|
|
102
102
|
if (c.types.length > 0) {
|
|
103
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat(c.name, "\"; values: readonly [").concat(c.types.join(", "), "] }");
|
|
103
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\"; values: readonly [").concat(c.types.join(", "), "] }");
|
|
104
104
|
}
|
|
105
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat(c.name, "\"; values: void }");
|
|
105
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\"; values: void }");
|
|
106
106
|
}).join(" |\n");
|
|
107
107
|
return "".concat(doc, " export type ").concat(name, " =\n").concat(caseTypes, ";");
|
|
108
108
|
}
|
|
@@ -112,7 +112,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
112
112
|
var name = (0, _utils.sanitizeIdentifier)(enumEntry.name().toString());
|
|
113
113
|
var doc = (0, _utils.formatJSDocComment)(enumEntry.doc().toString() || "Enum: ".concat(name), 0);
|
|
114
114
|
var members = enumEntry.cases().map(function (enumCase) {
|
|
115
|
-
var caseName = enumCase.name().toString();
|
|
115
|
+
var caseName = (0, _utils.sanitizeIdentifier)(enumCase.name().toString());
|
|
116
116
|
var caseValue = enumCase.value();
|
|
117
117
|
var caseDoc = enumCase.doc().toString() || "Enum Case: ".concat(caseName);
|
|
118
118
|
return "".concat((0, _utils.formatJSDocComment)(caseDoc, 2), " ").concat(caseName, " = ").concat(caseValue);
|
|
@@ -129,7 +129,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
129
129
|
return _this3.generateEnumCase(enumCase);
|
|
130
130
|
});
|
|
131
131
|
var members = cases.map(function (c) {
|
|
132
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " ").concat(c.value, " : { message: \"").concat(c.name, "\" }");
|
|
132
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " ").concat(c.value, " : { message: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\" }");
|
|
133
133
|
}).join(",\n");
|
|
134
134
|
return "".concat(doc, "export const ").concat(name, " = {\n").concat(members, "\n}");
|
|
135
135
|
}
|
package/lib/bindings/utils.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare function isNameReserved(name: string): boolean;
|
|
|
6
6
|
* @returns The sanitized identifier
|
|
7
7
|
*/
|
|
8
8
|
export declare function sanitizeIdentifier(identifier: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Escape a string for safe interpolation inside a double-quoted JavaScript string literal.
|
|
11
|
+
*/
|
|
12
|
+
export declare function escapeStringLiteral(str: string): string;
|
|
9
13
|
/**
|
|
10
14
|
* Generate TypeScript type from XDR type definition
|
|
11
15
|
*/
|
package/lib/bindings/utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.escapeStringLiteral = escapeStringLiteral;
|
|
6
7
|
exports.formatImports = formatImports;
|
|
7
8
|
exports.formatJSDocComment = formatJSDocComment;
|
|
8
9
|
exports.generateTypeImports = generateTypeImports;
|
|
@@ -22,13 +23,20 @@ function isNameReserved(name) {
|
|
|
22
23
|
return reservedNames.includes(name);
|
|
23
24
|
}
|
|
24
25
|
function sanitizeIdentifier(identifier) {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
var sanitized = identifier.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
27
|
+
if (isNameReserved(sanitized)) {
|
|
28
|
+
return sanitized + "_";
|
|
27
29
|
}
|
|
28
|
-
if (/^\d/.test(
|
|
29
|
-
return "_" +
|
|
30
|
+
if (/^\d/.test(sanitized)) {
|
|
31
|
+
return "_" + sanitized;
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
if (sanitized === "" || /^_+$/.test(sanitized)) {
|
|
34
|
+
return "_unnamed";
|
|
35
|
+
}
|
|
36
|
+
return sanitized;
|
|
37
|
+
}
|
|
38
|
+
function escapeStringLiteral(str) {
|
|
39
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
32
40
|
}
|
|
33
41
|
function parseTypeFromTypeDef(typeDef) {
|
|
34
42
|
var isFunctionInput = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -301,6 +301,11 @@ export declare class AssembledTransaction<T> {
|
|
|
301
301
|
* transaction. This only works with transactions that have been simulated.
|
|
302
302
|
*/
|
|
303
303
|
toJSON(): string;
|
|
304
|
+
/**
|
|
305
|
+
* Validate that a built transaction is a single invokeContract operation
|
|
306
|
+
* targeting the expected contract, and return the parsed InvokeContractArgs.
|
|
307
|
+
*/
|
|
308
|
+
private static validateInvokeContractOp;
|
|
304
309
|
static fromJSON<T>(options: Omit<AssembledTransactionOptions<T>, "args">, { tx, simulationResult, simulationTransactionData, }: {
|
|
305
310
|
tx: XDR_BASE64;
|
|
306
311
|
simulationResult: {
|
|
@@ -598,6 +598,38 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
598
598
|
return restoreFootprint;
|
|
599
599
|
}())
|
|
600
600
|
}], [{
|
|
601
|
+
key: "validateInvokeContractOp",
|
|
602
|
+
value: function validateInvokeContractOp(built, expectedContractId) {
|
|
603
|
+
if (built.operations.length !== 1) {
|
|
604
|
+
throw new Error("Transaction envelope must contain exactly one operation.");
|
|
605
|
+
}
|
|
606
|
+
var operation = built.operations[0];
|
|
607
|
+
if (operation.type !== "invokeHostFunction") {
|
|
608
|
+
throw new Error("Transaction envelope does not contain an invokeHostFunction operation.");
|
|
609
|
+
}
|
|
610
|
+
var invokeOp = operation;
|
|
611
|
+
if (invokeOp.func.switch().name !== "hostFunctionTypeInvokeContract") {
|
|
612
|
+
throw new Error("Transaction envelope does not contain an invokeContract host function.");
|
|
613
|
+
}
|
|
614
|
+
var invokeContractArgs = invokeOp.func.value();
|
|
615
|
+
var contractAddress;
|
|
616
|
+
var functionName;
|
|
617
|
+
try {
|
|
618
|
+
contractAddress = invokeContractArgs.contractAddress();
|
|
619
|
+
functionName = invokeContractArgs.functionName().toString("utf-8");
|
|
620
|
+
} catch (_unused) {
|
|
621
|
+
throw new Error("Could not extract contract address or method name from the transaction envelope.");
|
|
622
|
+
}
|
|
623
|
+
if (!contractAddress || !functionName) {
|
|
624
|
+
throw new Error("Could not extract contract address or method name from the transaction envelope.");
|
|
625
|
+
}
|
|
626
|
+
var xdrContractId = _stellarBase.Address.fromScAddress(contractAddress).toString();
|
|
627
|
+
if (xdrContractId !== expectedContractId) {
|
|
628
|
+
throw new Error("Transaction envelope targets contract ".concat(xdrContractId, ", but this Client is configured for ").concat(expectedContractId, "."));
|
|
629
|
+
}
|
|
630
|
+
return invokeContractArgs;
|
|
631
|
+
}
|
|
632
|
+
}, {
|
|
601
633
|
key: "fromJSON",
|
|
602
634
|
value: function fromJSON(options, _ref10) {
|
|
603
635
|
var tx = _ref10.tx,
|
|
@@ -605,6 +637,11 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
605
637
|
simulationTransactionData = _ref10.simulationTransactionData;
|
|
606
638
|
var txn = new AssembledTransaction(options);
|
|
607
639
|
txn.built = _stellarBase.TransactionBuilder.fromXDR(tx, options.networkPassphrase);
|
|
640
|
+
var invokeContractArgs = AssembledTransaction.validateInvokeContractOp(txn.built, options.contractId);
|
|
641
|
+
var xdrMethod = invokeContractArgs.functionName().toString("utf-8");
|
|
642
|
+
if (xdrMethod !== options.method) {
|
|
643
|
+
throw new Error("Transaction envelope calls method '".concat(xdrMethod, "', but the provided method is '").concat(options.method, "'."));
|
|
644
|
+
}
|
|
608
645
|
txn.simulationResult = {
|
|
609
646
|
auth: simulationResult.auth.map(function (a) {
|
|
610
647
|
return _stellarBase.xdr.SorobanAuthorizationEntry.fromXDR(a, "base64");
|
|
@@ -617,17 +654,9 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
617
654
|
}, {
|
|
618
655
|
key: "fromXDR",
|
|
619
656
|
value: function fromXDR(options, encodedXDR, spec) {
|
|
620
|
-
var _operation$func;
|
|
621
657
|
var envelope = _stellarBase.xdr.TransactionEnvelope.fromXDR(encodedXDR, "base64");
|
|
622
658
|
var built = _stellarBase.TransactionBuilder.fromXDR(envelope, options.networkPassphrase);
|
|
623
|
-
var
|
|
624
|
-
if (!(operation !== null && operation !== void 0 && (_operation$func = operation.func) !== null && _operation$func !== void 0 && _operation$func.value) || typeof operation.func.value !== "function") {
|
|
625
|
-
throw new Error("Could not extract the method from the transaction envelope.");
|
|
626
|
-
}
|
|
627
|
-
var invokeContractArgs = operation.func.value();
|
|
628
|
-
if (!(invokeContractArgs !== null && invokeContractArgs !== void 0 && invokeContractArgs.functionName)) {
|
|
629
|
-
throw new Error("Could not extract the method name from the transaction envelope.");
|
|
630
|
-
}
|
|
659
|
+
var invokeContractArgs = AssembledTransaction.validateInvokeContractOp(built, options.contractId);
|
|
631
660
|
var method = invokeContractArgs.functionName().toString("utf-8");
|
|
632
661
|
var txn = new AssembledTransaction(_objectSpread(_objectSpread({}, options), {}, {
|
|
633
662
|
method: method,
|
|
@@ -16,7 +16,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
16
16
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
18
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
-
var version = exports.version = "
|
|
19
|
+
var version = exports.version = "15.0.1";
|
|
20
20
|
var SERVER_TIME_MAP = exports.SERVER_TIME_MAP = {};
|
|
21
21
|
function toSeconds(ms) {
|
|
22
22
|
return Math.floor(ms / 1000);
|
|
@@ -65,7 +65,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
65
65
|
var name = (0, _utils.sanitizeIdentifier)(func.name().toString());
|
|
66
66
|
var inputs = func.inputs().map(function (input) {
|
|
67
67
|
return {
|
|
68
|
-
name: input.name().toString(),
|
|
68
|
+
name: (0, _utils.sanitizeIdentifier)(input.name().toString()),
|
|
69
69
|
type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
|
|
70
70
|
};
|
|
71
71
|
});
|
|
@@ -77,7 +77,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
77
77
|
}, {
|
|
78
78
|
key: "generateFromJSONMethod",
|
|
79
79
|
value: function generateFromJSONMethod(func) {
|
|
80
|
-
var name = func.name().toString();
|
|
80
|
+
var name = (0, _utils.sanitizeIdentifier)(func.name().toString());
|
|
81
81
|
var outputType = func.outputs().length > 0 ? (0, _utils.parseTypeFromTypeDef)(func.outputs()[0]) : "void";
|
|
82
82
|
return " ".concat(name, " : this.txFromJSON<").concat(outputType, ">");
|
|
83
83
|
}
|
|
@@ -90,7 +90,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
90
90
|
}
|
|
91
91
|
var inputs = constructorFunc.inputs().map(function (input) {
|
|
92
92
|
return {
|
|
93
|
-
name: input.name().toString(),
|
|
93
|
+
name: (0, _utils.sanitizeIdentifier)(input.name().toString()),
|
|
94
94
|
type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
|
|
95
95
|
};
|
|
96
96
|
});
|
|
@@ -82,7 +82,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
82
82
|
var name = (0, _utils.sanitizeIdentifier)(struct.name().toString());
|
|
83
83
|
var doc = (0, _utils.formatJSDocComment)(struct.doc().toString() || "Struct: ".concat(name), 0);
|
|
84
84
|
var fields = struct.fields().map(function (field) {
|
|
85
|
-
var fieldName = field.name().toString();
|
|
85
|
+
var fieldName = (0, _utils.sanitizeIdentifier)(field.name().toString());
|
|
86
86
|
var fieldType = (0, _utils.parseTypeFromTypeDef)(field.type());
|
|
87
87
|
var fieldDoc = (0, _utils.formatJSDocComment)(field.doc().toString(), 2);
|
|
88
88
|
return "".concat(fieldDoc, " ").concat(fieldName, ": ").concat(fieldType, ";");
|
|
@@ -100,9 +100,9 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
100
100
|
});
|
|
101
101
|
var caseTypes = cases.map(function (c) {
|
|
102
102
|
if (c.types.length > 0) {
|
|
103
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat(c.name, "\"; values: readonly [").concat(c.types.join(", "), "] }");
|
|
103
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\"; values: readonly [").concat(c.types.join(", "), "] }");
|
|
104
104
|
}
|
|
105
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat(c.name, "\"; values: void }");
|
|
105
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\"; values: void }");
|
|
106
106
|
}).join(" |\n");
|
|
107
107
|
return "".concat(doc, " export type ").concat(name, " =\n").concat(caseTypes, ";");
|
|
108
108
|
}
|
|
@@ -112,7 +112,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
112
112
|
var name = (0, _utils.sanitizeIdentifier)(enumEntry.name().toString());
|
|
113
113
|
var doc = (0, _utils.formatJSDocComment)(enumEntry.doc().toString() || "Enum: ".concat(name), 0);
|
|
114
114
|
var members = enumEntry.cases().map(function (enumCase) {
|
|
115
|
-
var caseName = enumCase.name().toString();
|
|
115
|
+
var caseName = (0, _utils.sanitizeIdentifier)(enumCase.name().toString());
|
|
116
116
|
var caseValue = enumCase.value();
|
|
117
117
|
var caseDoc = enumCase.doc().toString() || "Enum Case: ".concat(caseName);
|
|
118
118
|
return "".concat((0, _utils.formatJSDocComment)(caseDoc, 2), " ").concat(caseName, " = ").concat(caseValue);
|
|
@@ -129,7 +129,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
129
129
|
return _this3.generateEnumCase(enumCase);
|
|
130
130
|
});
|
|
131
131
|
var members = cases.map(function (c) {
|
|
132
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " ").concat(c.value, " : { message: \"").concat(c.name, "\" }");
|
|
132
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " ").concat(c.value, " : { message: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\" }");
|
|
133
133
|
}).join(",\n");
|
|
134
134
|
return "".concat(doc, "export const ").concat(name, " = {\n").concat(members, "\n}");
|
|
135
135
|
}
|
|
@@ -6,6 +6,10 @@ export declare function isNameReserved(name: string): boolean;
|
|
|
6
6
|
* @returns The sanitized identifier
|
|
7
7
|
*/
|
|
8
8
|
export declare function sanitizeIdentifier(identifier: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Escape a string for safe interpolation inside a double-quoted JavaScript string literal.
|
|
11
|
+
*/
|
|
12
|
+
export declare function escapeStringLiteral(str: string): string;
|
|
9
13
|
/**
|
|
10
14
|
* Generate TypeScript type from XDR type definition
|
|
11
15
|
*/
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.escapeStringLiteral = escapeStringLiteral;
|
|
6
7
|
exports.formatImports = formatImports;
|
|
7
8
|
exports.formatJSDocComment = formatJSDocComment;
|
|
8
9
|
exports.generateTypeImports = generateTypeImports;
|
|
@@ -22,13 +23,20 @@ function isNameReserved(name) {
|
|
|
22
23
|
return reservedNames.includes(name);
|
|
23
24
|
}
|
|
24
25
|
function sanitizeIdentifier(identifier) {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
var sanitized = identifier.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
27
|
+
if (isNameReserved(sanitized)) {
|
|
28
|
+
return sanitized + "_";
|
|
27
29
|
}
|
|
28
|
-
if (/^\d/.test(
|
|
29
|
-
return "_" +
|
|
30
|
+
if (/^\d/.test(sanitized)) {
|
|
31
|
+
return "_" + sanitized;
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
if (sanitized === "" || /^_+$/.test(sanitized)) {
|
|
34
|
+
return "_unnamed";
|
|
35
|
+
}
|
|
36
|
+
return sanitized;
|
|
37
|
+
}
|
|
38
|
+
function escapeStringLiteral(str) {
|
|
39
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
32
40
|
}
|
|
33
41
|
function parseTypeFromTypeDef(typeDef) {
|
|
34
42
|
var isFunctionInput = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -301,6 +301,11 @@ export declare class AssembledTransaction<T> {
|
|
|
301
301
|
* transaction. This only works with transactions that have been simulated.
|
|
302
302
|
*/
|
|
303
303
|
toJSON(): string;
|
|
304
|
+
/**
|
|
305
|
+
* Validate that a built transaction is a single invokeContract operation
|
|
306
|
+
* targeting the expected contract, and return the parsed InvokeContractArgs.
|
|
307
|
+
*/
|
|
308
|
+
private static validateInvokeContractOp;
|
|
304
309
|
static fromJSON<T>(options: Omit<AssembledTransactionOptions<T>, "args">, { tx, simulationResult, simulationTransactionData, }: {
|
|
305
310
|
tx: XDR_BASE64;
|
|
306
311
|
simulationResult: {
|
|
@@ -598,6 +598,38 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
598
598
|
return restoreFootprint;
|
|
599
599
|
}())
|
|
600
600
|
}], [{
|
|
601
|
+
key: "validateInvokeContractOp",
|
|
602
|
+
value: function validateInvokeContractOp(built, expectedContractId) {
|
|
603
|
+
if (built.operations.length !== 1) {
|
|
604
|
+
throw new Error("Transaction envelope must contain exactly one operation.");
|
|
605
|
+
}
|
|
606
|
+
var operation = built.operations[0];
|
|
607
|
+
if (operation.type !== "invokeHostFunction") {
|
|
608
|
+
throw new Error("Transaction envelope does not contain an invokeHostFunction operation.");
|
|
609
|
+
}
|
|
610
|
+
var invokeOp = operation;
|
|
611
|
+
if (invokeOp.func.switch().name !== "hostFunctionTypeInvokeContract") {
|
|
612
|
+
throw new Error("Transaction envelope does not contain an invokeContract host function.");
|
|
613
|
+
}
|
|
614
|
+
var invokeContractArgs = invokeOp.func.value();
|
|
615
|
+
var contractAddress;
|
|
616
|
+
var functionName;
|
|
617
|
+
try {
|
|
618
|
+
contractAddress = invokeContractArgs.contractAddress();
|
|
619
|
+
functionName = invokeContractArgs.functionName().toString("utf-8");
|
|
620
|
+
} catch (_unused) {
|
|
621
|
+
throw new Error("Could not extract contract address or method name from the transaction envelope.");
|
|
622
|
+
}
|
|
623
|
+
if (!contractAddress || !functionName) {
|
|
624
|
+
throw new Error("Could not extract contract address or method name from the transaction envelope.");
|
|
625
|
+
}
|
|
626
|
+
var xdrContractId = _stellarBase.Address.fromScAddress(contractAddress).toString();
|
|
627
|
+
if (xdrContractId !== expectedContractId) {
|
|
628
|
+
throw new Error("Transaction envelope targets contract ".concat(xdrContractId, ", but this Client is configured for ").concat(expectedContractId, "."));
|
|
629
|
+
}
|
|
630
|
+
return invokeContractArgs;
|
|
631
|
+
}
|
|
632
|
+
}, {
|
|
601
633
|
key: "fromJSON",
|
|
602
634
|
value: function fromJSON(options, _ref10) {
|
|
603
635
|
var tx = _ref10.tx,
|
|
@@ -605,6 +637,11 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
605
637
|
simulationTransactionData = _ref10.simulationTransactionData;
|
|
606
638
|
var txn = new AssembledTransaction(options);
|
|
607
639
|
txn.built = _stellarBase.TransactionBuilder.fromXDR(tx, options.networkPassphrase);
|
|
640
|
+
var invokeContractArgs = AssembledTransaction.validateInvokeContractOp(txn.built, options.contractId);
|
|
641
|
+
var xdrMethod = invokeContractArgs.functionName().toString("utf-8");
|
|
642
|
+
if (xdrMethod !== options.method) {
|
|
643
|
+
throw new Error("Transaction envelope calls method '".concat(xdrMethod, "', but the provided method is '").concat(options.method, "'."));
|
|
644
|
+
}
|
|
608
645
|
txn.simulationResult = {
|
|
609
646
|
auth: simulationResult.auth.map(function (a) {
|
|
610
647
|
return _stellarBase.xdr.SorobanAuthorizationEntry.fromXDR(a, "base64");
|
|
@@ -617,17 +654,9 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
617
654
|
}, {
|
|
618
655
|
key: "fromXDR",
|
|
619
656
|
value: function fromXDR(options, encodedXDR, spec) {
|
|
620
|
-
var _operation$func;
|
|
621
657
|
var envelope = _stellarBase.xdr.TransactionEnvelope.fromXDR(encodedXDR, "base64");
|
|
622
658
|
var built = _stellarBase.TransactionBuilder.fromXDR(envelope, options.networkPassphrase);
|
|
623
|
-
var
|
|
624
|
-
if (!(operation !== null && operation !== void 0 && (_operation$func = operation.func) !== null && _operation$func !== void 0 && _operation$func.value) || typeof operation.func.value !== "function") {
|
|
625
|
-
throw new Error("Could not extract the method from the transaction envelope.");
|
|
626
|
-
}
|
|
627
|
-
var invokeContractArgs = operation.func.value();
|
|
628
|
-
if (!(invokeContractArgs !== null && invokeContractArgs !== void 0 && invokeContractArgs.functionName)) {
|
|
629
|
-
throw new Error("Could not extract the method name from the transaction envelope.");
|
|
630
|
-
}
|
|
659
|
+
var invokeContractArgs = AssembledTransaction.validateInvokeContractOp(built, options.contractId);
|
|
631
660
|
var method = invokeContractArgs.functionName().toString("utf-8");
|
|
632
661
|
var txn = new AssembledTransaction(_objectSpread(_objectSpread({}, options), {}, {
|
|
633
662
|
method: method,
|
|
@@ -16,7 +16,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
16
16
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
18
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
-
var version = exports.version = "
|
|
19
|
+
var version = exports.version = "15.0.1";
|
|
20
20
|
var SERVER_TIME_MAP = exports.SERVER_TIME_MAP = {};
|
|
21
21
|
function toSeconds(ms) {
|
|
22
22
|
return Math.floor(ms / 1000);
|
package/lib/minimal/rpc/axios.js
CHANGED
|
@@ -12,7 +12,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
12
12
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
13
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
14
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
-
var version = exports.version = "
|
|
15
|
+
var version = exports.version = "15.0.1";
|
|
16
16
|
function createHttpClient(headers) {
|
|
17
17
|
return (0, _httpClient.create)({
|
|
18
18
|
headers: _objectSpread(_objectSpread({}, headers), {}, {
|
|
@@ -98,7 +98,7 @@ function readChallengeTx(challengeTx, serverAccountID, networkPassphrase, homeDo
|
|
|
98
98
|
}
|
|
99
99
|
var _transaction$operatio = _toArray(transaction.operations),
|
|
100
100
|
operation = _transaction$operatio[0],
|
|
101
|
-
subsequentOperations = _transaction$operatio.slice(1);
|
|
101
|
+
subsequentOperations = _arrayLikeToArray(_transaction$operatio).slice(1);
|
|
102
102
|
if (!operation.source) {
|
|
103
103
|
throw new _errors.InvalidChallengeError("The transaction's operation should contain a source account");
|
|
104
104
|
}
|
|
@@ -65,7 +65,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
65
65
|
var name = (0, _utils.sanitizeIdentifier)(func.name().toString());
|
|
66
66
|
var inputs = func.inputs().map(function (input) {
|
|
67
67
|
return {
|
|
68
|
-
name: input.name().toString(),
|
|
68
|
+
name: (0, _utils.sanitizeIdentifier)(input.name().toString()),
|
|
69
69
|
type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
|
|
70
70
|
};
|
|
71
71
|
});
|
|
@@ -77,7 +77,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
77
77
|
}, {
|
|
78
78
|
key: "generateFromJSONMethod",
|
|
79
79
|
value: function generateFromJSONMethod(func) {
|
|
80
|
-
var name = func.name().toString();
|
|
80
|
+
var name = (0, _utils.sanitizeIdentifier)(func.name().toString());
|
|
81
81
|
var outputType = func.outputs().length > 0 ? (0, _utils.parseTypeFromTypeDef)(func.outputs()[0]) : "void";
|
|
82
82
|
return " ".concat(name, " : this.txFromJSON<").concat(outputType, ">");
|
|
83
83
|
}
|
|
@@ -90,7 +90,7 @@ var ClientGenerator = exports.ClientGenerator = function () {
|
|
|
90
90
|
}
|
|
91
91
|
var inputs = constructorFunc.inputs().map(function (input) {
|
|
92
92
|
return {
|
|
93
|
-
name: input.name().toString(),
|
|
93
|
+
name: (0, _utils.sanitizeIdentifier)(input.name().toString()),
|
|
94
94
|
type: (0, _utils.parseTypeFromTypeDef)(input.type(), true)
|
|
95
95
|
};
|
|
96
96
|
});
|
|
@@ -82,7 +82,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
82
82
|
var name = (0, _utils.sanitizeIdentifier)(struct.name().toString());
|
|
83
83
|
var doc = (0, _utils.formatJSDocComment)(struct.doc().toString() || "Struct: ".concat(name), 0);
|
|
84
84
|
var fields = struct.fields().map(function (field) {
|
|
85
|
-
var fieldName = field.name().toString();
|
|
85
|
+
var fieldName = (0, _utils.sanitizeIdentifier)(field.name().toString());
|
|
86
86
|
var fieldType = (0, _utils.parseTypeFromTypeDef)(field.type());
|
|
87
87
|
var fieldDoc = (0, _utils.formatJSDocComment)(field.doc().toString(), 2);
|
|
88
88
|
return "".concat(fieldDoc, " ").concat(fieldName, ": ").concat(fieldType, ";");
|
|
@@ -100,9 +100,9 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
100
100
|
});
|
|
101
101
|
var caseTypes = cases.map(function (c) {
|
|
102
102
|
if (c.types.length > 0) {
|
|
103
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat(c.name, "\"; values: readonly [").concat(c.types.join(", "), "] }");
|
|
103
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\"; values: readonly [").concat(c.types.join(", "), "] }");
|
|
104
104
|
}
|
|
105
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat(c.name, "\"; values: void }");
|
|
105
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " { tag: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\"; values: void }");
|
|
106
106
|
}).join(" |\n");
|
|
107
107
|
return "".concat(doc, " export type ").concat(name, " =\n").concat(caseTypes, ";");
|
|
108
108
|
}
|
|
@@ -112,7 +112,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
112
112
|
var name = (0, _utils.sanitizeIdentifier)(enumEntry.name().toString());
|
|
113
113
|
var doc = (0, _utils.formatJSDocComment)(enumEntry.doc().toString() || "Enum: ".concat(name), 0);
|
|
114
114
|
var members = enumEntry.cases().map(function (enumCase) {
|
|
115
|
-
var caseName = enumCase.name().toString();
|
|
115
|
+
var caseName = (0, _utils.sanitizeIdentifier)(enumCase.name().toString());
|
|
116
116
|
var caseValue = enumCase.value();
|
|
117
117
|
var caseDoc = enumCase.doc().toString() || "Enum Case: ".concat(caseName);
|
|
118
118
|
return "".concat((0, _utils.formatJSDocComment)(caseDoc, 2), " ").concat(caseName, " = ").concat(caseValue);
|
|
@@ -129,7 +129,7 @@ var TypeGenerator = exports.TypeGenerator = function () {
|
|
|
129
129
|
return _this3.generateEnumCase(enumCase);
|
|
130
130
|
});
|
|
131
131
|
var members = cases.map(function (c) {
|
|
132
|
-
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " ").concat(c.value, " : { message: \"").concat(c.name, "\" }");
|
|
132
|
+
return "".concat((0, _utils.formatJSDocComment)(c.doc, 2), " ").concat(c.value, " : { message: \"").concat((0, _utils.escapeStringLiteral)(c.name), "\" }");
|
|
133
133
|
}).join(",\n");
|
|
134
134
|
return "".concat(doc, "export const ").concat(name, " = {\n").concat(members, "\n}");
|
|
135
135
|
}
|
|
@@ -6,6 +6,10 @@ export declare function isNameReserved(name: string): boolean;
|
|
|
6
6
|
* @returns The sanitized identifier
|
|
7
7
|
*/
|
|
8
8
|
export declare function sanitizeIdentifier(identifier: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Escape a string for safe interpolation inside a double-quoted JavaScript string literal.
|
|
11
|
+
*/
|
|
12
|
+
export declare function escapeStringLiteral(str: string): string;
|
|
9
13
|
/**
|
|
10
14
|
* Generate TypeScript type from XDR type definition
|
|
11
15
|
*/
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.escapeStringLiteral = escapeStringLiteral;
|
|
6
7
|
exports.formatImports = formatImports;
|
|
7
8
|
exports.formatJSDocComment = formatJSDocComment;
|
|
8
9
|
exports.generateTypeImports = generateTypeImports;
|
|
@@ -22,13 +23,20 @@ function isNameReserved(name) {
|
|
|
22
23
|
return reservedNames.includes(name);
|
|
23
24
|
}
|
|
24
25
|
function sanitizeIdentifier(identifier) {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
var sanitized = identifier.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
27
|
+
if (isNameReserved(sanitized)) {
|
|
28
|
+
return sanitized + "_";
|
|
27
29
|
}
|
|
28
|
-
if (/^\d/.test(
|
|
29
|
-
return "_" +
|
|
30
|
+
if (/^\d/.test(sanitized)) {
|
|
31
|
+
return "_" + sanitized;
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
if (sanitized === "" || /^_+$/.test(sanitized)) {
|
|
34
|
+
return "_unnamed";
|
|
35
|
+
}
|
|
36
|
+
return sanitized;
|
|
37
|
+
}
|
|
38
|
+
function escapeStringLiteral(str) {
|
|
39
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
32
40
|
}
|
|
33
41
|
function parseTypeFromTypeDef(typeDef) {
|
|
34
42
|
var isFunctionInput = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -301,6 +301,11 @@ export declare class AssembledTransaction<T> {
|
|
|
301
301
|
* transaction. This only works with transactions that have been simulated.
|
|
302
302
|
*/
|
|
303
303
|
toJSON(): string;
|
|
304
|
+
/**
|
|
305
|
+
* Validate that a built transaction is a single invokeContract operation
|
|
306
|
+
* targeting the expected contract, and return the parsed InvokeContractArgs.
|
|
307
|
+
*/
|
|
308
|
+
private static validateInvokeContractOp;
|
|
304
309
|
static fromJSON<T>(options: Omit<AssembledTransactionOptions<T>, "args">, { tx, simulationResult, simulationTransactionData, }: {
|
|
305
310
|
tx: XDR_BASE64;
|
|
306
311
|
simulationResult: {
|
|
@@ -598,6 +598,38 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
598
598
|
return restoreFootprint;
|
|
599
599
|
}())
|
|
600
600
|
}], [{
|
|
601
|
+
key: "validateInvokeContractOp",
|
|
602
|
+
value: function validateInvokeContractOp(built, expectedContractId) {
|
|
603
|
+
if (built.operations.length !== 1) {
|
|
604
|
+
throw new Error("Transaction envelope must contain exactly one operation.");
|
|
605
|
+
}
|
|
606
|
+
var operation = built.operations[0];
|
|
607
|
+
if (operation.type !== "invokeHostFunction") {
|
|
608
|
+
throw new Error("Transaction envelope does not contain an invokeHostFunction operation.");
|
|
609
|
+
}
|
|
610
|
+
var invokeOp = operation;
|
|
611
|
+
if (invokeOp.func.switch().name !== "hostFunctionTypeInvokeContract") {
|
|
612
|
+
throw new Error("Transaction envelope does not contain an invokeContract host function.");
|
|
613
|
+
}
|
|
614
|
+
var invokeContractArgs = invokeOp.func.value();
|
|
615
|
+
var contractAddress;
|
|
616
|
+
var functionName;
|
|
617
|
+
try {
|
|
618
|
+
contractAddress = invokeContractArgs.contractAddress();
|
|
619
|
+
functionName = invokeContractArgs.functionName().toString("utf-8");
|
|
620
|
+
} catch (_unused) {
|
|
621
|
+
throw new Error("Could not extract contract address or method name from the transaction envelope.");
|
|
622
|
+
}
|
|
623
|
+
if (!contractAddress || !functionName) {
|
|
624
|
+
throw new Error("Could not extract contract address or method name from the transaction envelope.");
|
|
625
|
+
}
|
|
626
|
+
var xdrContractId = _stellarBase.Address.fromScAddress(contractAddress).toString();
|
|
627
|
+
if (xdrContractId !== expectedContractId) {
|
|
628
|
+
throw new Error("Transaction envelope targets contract ".concat(xdrContractId, ", but this Client is configured for ").concat(expectedContractId, "."));
|
|
629
|
+
}
|
|
630
|
+
return invokeContractArgs;
|
|
631
|
+
}
|
|
632
|
+
}, {
|
|
601
633
|
key: "fromJSON",
|
|
602
634
|
value: function fromJSON(options, _ref10) {
|
|
603
635
|
var tx = _ref10.tx,
|
|
@@ -605,6 +637,11 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
605
637
|
simulationTransactionData = _ref10.simulationTransactionData;
|
|
606
638
|
var txn = new AssembledTransaction(options);
|
|
607
639
|
txn.built = _stellarBase.TransactionBuilder.fromXDR(tx, options.networkPassphrase);
|
|
640
|
+
var invokeContractArgs = AssembledTransaction.validateInvokeContractOp(txn.built, options.contractId);
|
|
641
|
+
var xdrMethod = invokeContractArgs.functionName().toString("utf-8");
|
|
642
|
+
if (xdrMethod !== options.method) {
|
|
643
|
+
throw new Error("Transaction envelope calls method '".concat(xdrMethod, "', but the provided method is '").concat(options.method, "'."));
|
|
644
|
+
}
|
|
608
645
|
txn.simulationResult = {
|
|
609
646
|
auth: simulationResult.auth.map(function (a) {
|
|
610
647
|
return _stellarBase.xdr.SorobanAuthorizationEntry.fromXDR(a, "base64");
|
|
@@ -617,17 +654,9 @@ var AssembledTransaction = exports.AssembledTransaction = function () {
|
|
|
617
654
|
}, {
|
|
618
655
|
key: "fromXDR",
|
|
619
656
|
value: function fromXDR(options, encodedXDR, spec) {
|
|
620
|
-
var _operation$func;
|
|
621
657
|
var envelope = _stellarBase.xdr.TransactionEnvelope.fromXDR(encodedXDR, "base64");
|
|
622
658
|
var built = _stellarBase.TransactionBuilder.fromXDR(envelope, options.networkPassphrase);
|
|
623
|
-
var
|
|
624
|
-
if (!(operation !== null && operation !== void 0 && (_operation$func = operation.func) !== null && _operation$func !== void 0 && _operation$func.value) || typeof operation.func.value !== "function") {
|
|
625
|
-
throw new Error("Could not extract the method from the transaction envelope.");
|
|
626
|
-
}
|
|
627
|
-
var invokeContractArgs = operation.func.value();
|
|
628
|
-
if (!(invokeContractArgs !== null && invokeContractArgs !== void 0 && invokeContractArgs.functionName)) {
|
|
629
|
-
throw new Error("Could not extract the method name from the transaction envelope.");
|
|
630
|
-
}
|
|
659
|
+
var invokeContractArgs = AssembledTransaction.validateInvokeContractOp(built, options.contractId);
|
|
631
660
|
var method = invokeContractArgs.functionName().toString("utf-8");
|
|
632
661
|
var txn = new AssembledTransaction(_objectSpread(_objectSpread({}, options), {}, {
|
|
633
662
|
method: method,
|