@stellar/stellar-base 13.0.1 → 13.1.0
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/CHANGELOG.md +17 -0
- package/dist/stellar-base.js +27109 -26606
- package/dist/stellar-base.min.js +1 -1
- package/lib/address.js +3 -3
- package/lib/auth.js +38 -22
- package/lib/scval.js +28 -8
- package/package.json +17 -14
- package/types/curr.d.ts +10 -0
- package/types/index.d.ts +5 -1
package/lib/address.js
CHANGED
|
@@ -155,10 +155,10 @@ var Address = exports.Address = /*#__PURE__*/function () {
|
|
|
155
155
|
}, {
|
|
156
156
|
key: "fromScAddress",
|
|
157
157
|
value: function fromScAddress(scAddress) {
|
|
158
|
-
switch (scAddress["switch"]()) {
|
|
159
|
-
case _xdr["default"].ScAddressType.scAddressTypeAccount():
|
|
158
|
+
switch (scAddress["switch"]().value) {
|
|
159
|
+
case _xdr["default"].ScAddressType.scAddressTypeAccount().value:
|
|
160
160
|
return Address.account(scAddress.accountId().ed25519());
|
|
161
|
-
case _xdr["default"].ScAddressType.scAddressTypeContract():
|
|
161
|
+
case _xdr["default"].ScAddressType.scAddressTypeContract().value:
|
|
162
162
|
return Address.contract(scAddress.contractId());
|
|
163
163
|
default:
|
|
164
164
|
throw new Error('Unsupported address type');
|
package/lib/auth.js
CHANGED
|
@@ -26,11 +26,14 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
26
26
|
* whose hash you should sign, so that you can inspect the entire structure
|
|
27
27
|
* if necessary (rather than blindly signing a hash)
|
|
28
28
|
*
|
|
29
|
-
* @returns {
|
|
30
|
-
*
|
|
29
|
+
* @returns {
|
|
30
|
+
* Promise<Uint8Array> |
|
|
31
|
+
* Promise<{signature: Uint8Array, publicKey: string}
|
|
32
|
+
* } the signature of the raw payload (which is the sha256 hash of the preimage
|
|
33
|
+
* bytes, so `hash(preimage.toXDR())`) either naked, implying it is signed
|
|
31
34
|
* by the key corresponding to the public key in the entry you pass to
|
|
32
35
|
* {@link authorizeEntry} (decipherable from its
|
|
33
|
-
* `credentials().address().address()`)
|
|
36
|
+
* `credentials().address().address()`), or alongside an explicit `publicKey`.
|
|
34
37
|
*/
|
|
35
38
|
/**
|
|
36
39
|
* Actually authorizes an existing authorization entry using the given the
|
|
@@ -51,10 +54,17 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
51
54
|
*
|
|
52
55
|
* @param {xdr.SorobanAuthorizationEntry} entry an unsigned authorization entr
|
|
53
56
|
* @param {Keypair | SigningCallback} signer either a {@link Keypair} instance
|
|
54
|
-
* or a function which takes a
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
57
|
+
* or a function which takes a {@link xdr.HashIdPreimageSorobanAuthorization}
|
|
58
|
+
* input payload and returns EITHER
|
|
59
|
+
*
|
|
60
|
+
* (a) an object containing a `signature` of the hash of the raw payload bytes
|
|
61
|
+
* as a Buffer-like and a `publicKey` string representing who just
|
|
62
|
+
* created this signature, or
|
|
63
|
+
* (b) just the naked signature of the hash of the raw payload bytes (where
|
|
64
|
+
* the signing key is implied to be the address in the `entry`).
|
|
65
|
+
*
|
|
66
|
+
* The latter option (b) is JUST for backwards compatibility and will be
|
|
67
|
+
* removed in the future.
|
|
58
68
|
* @param {number} validUntilLedgerSeq the (exclusive) future ledger sequence
|
|
59
69
|
* number until which this authorization entry should be valid (if
|
|
60
70
|
* `currentLedgerSeq==validUntil`, this is expired))
|
|
@@ -66,8 +76,8 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
66
76
|
* {@link Operation.invokeHostFunction}
|
|
67
77
|
*
|
|
68
78
|
* @note If using the `SigningCallback` variation, the signer is assumed to be
|
|
69
|
-
* the entry's credential address
|
|
70
|
-
*
|
|
79
|
+
* the entry's credential address unless you use the variant that returns
|
|
80
|
+
* the object.
|
|
71
81
|
*
|
|
72
82
|
* @see authorizeInvocation
|
|
73
83
|
* @example
|
|
@@ -160,6 +170,7 @@ function _authorizeEntry() {
|
|
|
160
170
|
payload,
|
|
161
171
|
signature,
|
|
162
172
|
publicKey,
|
|
173
|
+
sigResult,
|
|
163
174
|
sigScVal,
|
|
164
175
|
_args = arguments;
|
|
165
176
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -185,28 +196,33 @@ function _authorizeEntry() {
|
|
|
185
196
|
}));
|
|
186
197
|
payload = (0, _hashing.hash)(preimage.toXDR());
|
|
187
198
|
if (!(typeof signer === 'function')) {
|
|
188
|
-
_context.next =
|
|
199
|
+
_context.next = 16;
|
|
189
200
|
break;
|
|
190
201
|
}
|
|
191
|
-
_context.
|
|
192
|
-
_context.next = 13;
|
|
202
|
+
_context.next = 12;
|
|
193
203
|
return signer(preimage);
|
|
194
|
-
case
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
204
|
+
case 12:
|
|
205
|
+
sigResult = _context.sent;
|
|
206
|
+
if (sigResult !== null && sigResult !== void 0 && sigResult.signature) {
|
|
207
|
+
signature = Buffer.from(sigResult.signature);
|
|
208
|
+
publicKey = sigResult.publicKey;
|
|
209
|
+
} else {
|
|
210
|
+
// if using the deprecated form, assume it's for the entry
|
|
211
|
+
signature = Buffer.from(sigResult);
|
|
212
|
+
publicKey = _address.Address.fromScAddress(addrAuth.address()).toString();
|
|
213
|
+
}
|
|
214
|
+
_context.next = 18;
|
|
199
215
|
break;
|
|
200
|
-
case
|
|
216
|
+
case 16:
|
|
201
217
|
signature = Buffer.from(signer.sign(payload));
|
|
202
218
|
publicKey = signer.publicKey();
|
|
203
|
-
case
|
|
219
|
+
case 18:
|
|
204
220
|
if (_keypair.Keypair.fromPublicKey(publicKey).verify(payload, signature)) {
|
|
205
|
-
_context.next =
|
|
221
|
+
_context.next = 20;
|
|
206
222
|
break;
|
|
207
223
|
}
|
|
208
224
|
throw new Error("signature doesn't match payload");
|
|
209
|
-
case
|
|
225
|
+
case 20:
|
|
210
226
|
// This structure is defined here:
|
|
211
227
|
// https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#stellar-account-signatures
|
|
212
228
|
//
|
|
@@ -223,7 +239,7 @@ function _authorizeEntry() {
|
|
|
223
239
|
});
|
|
224
240
|
addrAuth.signature(_xdr["default"].ScVal.scvVec([sigScVal]));
|
|
225
241
|
return _context.abrupt("return", clone);
|
|
226
|
-
case
|
|
242
|
+
case 23:
|
|
227
243
|
case "end":
|
|
228
244
|
return _context.stop();
|
|
229
245
|
}
|
package/lib/scval.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.nativeToScVal = nativeToScVal;
|
|
7
7
|
exports.scValToNative = scValToNative;
|
|
8
8
|
var _xdr = _interopRequireDefault(require("./xdr"));
|
|
9
|
+
var _keypair = require("./keypair");
|
|
9
10
|
var _address = require("./address");
|
|
10
11
|
var _contract = require("./contract");
|
|
11
12
|
var _index = require("./numbers/index");
|
|
@@ -164,6 +165,11 @@ function nativeToScVal(val) {
|
|
|
164
165
|
if (val instanceof _address.Address) {
|
|
165
166
|
return val.toScVal();
|
|
166
167
|
}
|
|
168
|
+
if (val instanceof _keypair.Keypair) {
|
|
169
|
+
return nativeToScVal(val.publicKey(), {
|
|
170
|
+
type: 'address'
|
|
171
|
+
});
|
|
172
|
+
}
|
|
167
173
|
if (val instanceof _contract.Contract) {
|
|
168
174
|
return val.address().toScVal();
|
|
169
175
|
}
|
|
@@ -182,13 +188,6 @@ function nativeToScVal(val) {
|
|
|
182
188
|
}
|
|
183
189
|
}
|
|
184
190
|
if (Array.isArray(val)) {
|
|
185
|
-
if (val.length > 0 && val.some(function (v) {
|
|
186
|
-
return _typeof(v) !== _typeof(val[0]);
|
|
187
|
-
})) {
|
|
188
|
-
throw new TypeError("array values (".concat(val, ") must have the same type (types: ").concat(val.map(function (v) {
|
|
189
|
-
return _typeof(v);
|
|
190
|
-
}).join(','), ")"));
|
|
191
|
-
}
|
|
192
191
|
return _xdr["default"].ScVal.scvVec(val.map(function (v) {
|
|
193
192
|
return nativeToScVal(v, opts);
|
|
194
193
|
}));
|
|
@@ -389,4 +388,25 @@ function scValToNative(scv) {
|
|
|
389
388
|
default:
|
|
390
389
|
return scv.value();
|
|
391
390
|
}
|
|
392
|
-
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/// Inject a sortable map builder into the xdr module.
|
|
394
|
+
_xdr["default"].scvSortedMap = function (items) {
|
|
395
|
+
var sorted = Array.from(items).sort(function (a, b) {
|
|
396
|
+
// Both a and b are `ScMapEntry`s, so we need to sort by underlying key.
|
|
397
|
+
//
|
|
398
|
+
// We couldn't possibly handle every combination of keys since Soroban
|
|
399
|
+
// maps don't enforce consistent types, so we do a best-effort and try
|
|
400
|
+
// sorting by "number-like" or "string-like."
|
|
401
|
+
var nativeA = scValToNative(a.key());
|
|
402
|
+
var nativeB = scValToNative(b.key());
|
|
403
|
+
switch (_typeof(nativeA)) {
|
|
404
|
+
case 'number':
|
|
405
|
+
case 'bigint':
|
|
406
|
+
return nativeA < nativeB ? -1 : 1;
|
|
407
|
+
default:
|
|
408
|
+
return nativeA.toString().localeCompare(nativeB.toString());
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return _xdr["default"].ScVal.scvMap(sorted);
|
|
412
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellar/stellar-base",
|
|
3
|
-
"version": "13.0
|
|
3
|
+
"version": "13.1.0",
|
|
4
4
|
"description": "Low-level support library for the Stellar network.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build:browser:prod": "cross-env NODE_ENV=production yarn build:browser",
|
|
17
17
|
"build:prod": "cross-env NODE_ENV=production yarn build",
|
|
18
18
|
"test": "yarn build && yarn test:node && yarn test:browser",
|
|
19
|
-
"test:node": "yarn _nyc mocha",
|
|
19
|
+
"test:node": "NODE_OPTIONS=$(test ! $(node -v | awk -F'.' '{printf substr($1,2)}') = '18' && echo '--no-experimental-detect-module') yarn _nyc mocha",
|
|
20
20
|
"test:browser": "karma start ./config/karma.conf.js",
|
|
21
21
|
"docs": "jsdoc -c ./config/.jsdoc.json --verbose",
|
|
22
22
|
"lint": "eslint -c ./config/.eslintrc.js src/ && dtslint --localTs node_modules/typescript/lib types/",
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"clean": "rm -rf lib/ dist/ coverage/ .nyc_output/",
|
|
27
27
|
"_nyc": "nyc --nycrc-path ./config/.nycrc"
|
|
28
28
|
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
29
32
|
"mocha": {
|
|
30
33
|
"require": [
|
|
31
34
|
"@babel/register",
|
|
@@ -70,11 +73,11 @@
|
|
|
70
73
|
},
|
|
71
74
|
"homepage": "https://github.com/stellar/js-stellar-base",
|
|
72
75
|
"devDependencies": {
|
|
73
|
-
"@babel/cli": "^7.
|
|
74
|
-
"@babel/core": "^7.26.
|
|
75
|
-
"@babel/eslint-parser": "^7.
|
|
76
|
-
"@babel/eslint-plugin": "^7.
|
|
77
|
-
"@babel/preset-env": "^7.26.
|
|
76
|
+
"@babel/cli": "^7.27.0",
|
|
77
|
+
"@babel/core": "^7.26.10",
|
|
78
|
+
"@babel/eslint-parser": "^7.27.0",
|
|
79
|
+
"@babel/eslint-plugin": "^7.27.0",
|
|
80
|
+
"@babel/preset-env": "^7.26.9",
|
|
78
81
|
"@babel/register": "^7.25.9",
|
|
79
82
|
"@definitelytyped/dtslint": "^0.0.182",
|
|
80
83
|
"@istanbuljs/nyc-config-babel": "3.0.0",
|
|
@@ -91,7 +94,7 @@
|
|
|
91
94
|
"eslint-plugin-import": "^2.31.0",
|
|
92
95
|
"eslint-plugin-node": "^11.1.0",
|
|
93
96
|
"eslint-plugin-prefer-import": "^0.0.1",
|
|
94
|
-
"eslint-plugin-prettier": "^5.2.
|
|
97
|
+
"eslint-plugin-prettier": "^5.2.5",
|
|
95
98
|
"eslint-webpack-plugin": "^4.2.0",
|
|
96
99
|
"ghooks": "^2.0.4",
|
|
97
100
|
"husky": "^8.0.3",
|
|
@@ -103,20 +106,20 @@
|
|
|
103
106
|
"karma-mocha": "^2.0.0",
|
|
104
107
|
"karma-sinon-chai": "^2.0.2",
|
|
105
108
|
"karma-webpack": "^5.0.1",
|
|
106
|
-
"lint-staged": "^15.
|
|
109
|
+
"lint-staged": "^15.5.0",
|
|
107
110
|
"minami": "^1.1.1",
|
|
108
111
|
"mocha": "^10.8.2",
|
|
109
112
|
"node-polyfill-webpack-plugin": "^3.0.0",
|
|
110
113
|
"nyc": "^15.1.0",
|
|
111
|
-
"prettier": "^3.
|
|
114
|
+
"prettier": "^3.5.3",
|
|
112
115
|
"randombytes": "^2.1.0",
|
|
113
116
|
"sinon": "^16.1.0",
|
|
114
117
|
"sinon-chai": "^3.7.0",
|
|
115
118
|
"taffydb": "^2.7.3",
|
|
116
|
-
"terser-webpack-plugin": "^5.3.
|
|
119
|
+
"terser-webpack-plugin": "^5.3.14",
|
|
117
120
|
"ts-node": "^10.9.2",
|
|
118
|
-
"typescript": "
|
|
119
|
-
"webpack": "^5.
|
|
121
|
+
"typescript": "5.6.3",
|
|
122
|
+
"webpack": "^5.98.0",
|
|
120
123
|
"webpack-cli": "^5.1.1"
|
|
121
124
|
},
|
|
122
125
|
"dependencies": {
|
|
@@ -128,6 +131,6 @@
|
|
|
128
131
|
"tweetnacl": "^1.0.3"
|
|
129
132
|
},
|
|
130
133
|
"optionalDependencies": {
|
|
131
|
-
"sodium-native": "^4.3.
|
|
134
|
+
"sodium-native": "^4.3.3"
|
|
132
135
|
}
|
|
133
136
|
}
|
package/types/curr.d.ts
CHANGED
|
@@ -44,6 +44,16 @@ export namespace xdr {
|
|
|
44
44
|
|
|
45
45
|
type Hash = Opaque[]; // workaround, cause unknown
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Returns an {@link ScVal} with a map type and sorted entries.
|
|
49
|
+
*
|
|
50
|
+
* @param items the key-value pairs to sort.
|
|
51
|
+
*
|
|
52
|
+
* @warning This only performs "best-effort" sorting, working best when the
|
|
53
|
+
* keys are all either numeric or string-like.
|
|
54
|
+
*/
|
|
55
|
+
function scvSortedMap(items: ScMapEntry[]): ScVal;
|
|
56
|
+
|
|
47
57
|
interface SignedInt {
|
|
48
58
|
readonly MAX_VALUE: 2147483647;
|
|
49
59
|
readonly MIN_VALUE: -2147483648;
|
package/types/index.d.ts
CHANGED
|
@@ -1214,9 +1214,13 @@ export class SorobanDataBuilder {
|
|
|
1214
1214
|
build(): xdr.SorobanTransactionData;
|
|
1215
1215
|
}
|
|
1216
1216
|
|
|
1217
|
+
type BufferLike = Buffer | Uint8Array | ArrayBuffer;
|
|
1217
1218
|
export type SigningCallback = (
|
|
1218
1219
|
preimage: xdr.HashIdPreimage
|
|
1219
|
-
) => Promise<
|
|
1220
|
+
) => Promise<
|
|
1221
|
+
BufferLike |
|
|
1222
|
+
{ signature: BufferLike, publicKey: string }
|
|
1223
|
+
>;
|
|
1220
1224
|
|
|
1221
1225
|
export function authorizeInvocation(
|
|
1222
1226
|
signer: Keypair | SigningCallback,
|