@stellar/stellar-sdk 16.0.1 → 16.2.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/README.md +41 -2
- package/dist/stellar-sdk-axios.js +5401 -3690
- package/dist/stellar-sdk-axios.js.map +1 -1
- package/dist/stellar-sdk-axios.min.js +12 -11
- package/dist/stellar-sdk-axios.min.js.map +1 -1
- package/dist/stellar-sdk.js +4850 -3681
- package/dist/stellar-sdk.js.map +1 -1
- package/dist/stellar-sdk.min.js +17 -17
- package/dist/stellar-sdk.min.js.map +1 -1
- package/lib/axios/cjs/base/auth.js +147 -30
- package/lib/axios/cjs/base/auth.js.map +1 -1
- package/lib/axios/cjs/base/index.js +113 -0
- package/lib/axios/cjs/base/index.js.map +1 -0
- package/lib/axios/cjs/base/keypair.js +39 -0
- package/lib/axios/cjs/base/keypair.js.map +1 -1
- package/lib/axios/cjs/base/scval.js +34 -0
- package/lib/axios/cjs/base/scval.js.map +1 -1
- package/lib/axios/cjs/bindings/client.js +170 -0
- package/lib/axios/cjs/bindings/client.js.map +1 -1
- package/lib/axios/cjs/bindings/config.js +1 -1
- package/lib/axios/cjs/bindings/generator.js +45 -16
- package/lib/axios/cjs/bindings/generator.js.map +1 -1
- package/lib/axios/cjs/bindings/types.js +151 -1
- package/lib/axios/cjs/bindings/types.js.map +1 -1
- package/lib/axios/cjs/bindings/utils.js +10 -0
- package/lib/axios/cjs/bindings/utils.js.map +1 -1
- package/lib/axios/cjs/cli/index.js +19 -22
- package/lib/axios/cjs/cli/index.js.map +1 -1
- package/lib/axios/cjs/cli/util.js +1 -20
- package/lib/axios/cjs/cli/util.js.map +1 -1
- package/lib/axios/cjs/contract/assembled_transaction.js +39 -17
- package/lib/axios/cjs/contract/assembled_transaction.js.map +1 -1
- package/lib/axios/cjs/contract/basic_node_signer.js +8 -42
- package/lib/axios/cjs/contract/basic_node_signer.js.map +1 -1
- package/lib/axios/cjs/contract/client.js +56 -3
- package/lib/axios/cjs/contract/client.js.map +1 -1
- package/lib/axios/cjs/contract/event_spec.js +164 -0
- package/lib/axios/cjs/contract/event_spec.js.map +1 -0
- package/lib/axios/cjs/contract/index.js +2 -0
- package/lib/axios/cjs/contract/index.js.map +1 -1
- package/lib/axios/cjs/contract/sent_transaction.js +0 -20
- package/lib/axios/cjs/contract/sent_transaction.js.map +1 -1
- package/lib/axios/cjs/contract/signer.js +96 -0
- package/lib/axios/cjs/contract/signer.js.map +1 -0
- package/lib/axios/cjs/contract/spec.js +107 -3
- package/lib/axios/cjs/contract/spec.js.map +1 -1
- package/lib/axios/cjs/contract/types.js.map +1 -1
- package/lib/axios/cjs/errors/transaction_failed.js +62 -0
- package/lib/axios/cjs/errors/transaction_failed.js.map +1 -0
- package/lib/axios/cjs/errors/wrap_http_error.js +20 -0
- package/lib/axios/cjs/errors/wrap_http_error.js.map +1 -0
- package/lib/axios/cjs/federation/server.js +15 -35
- package/lib/axios/cjs/federation/server.js.map +1 -1
- package/lib/axios/cjs/horizon/account_response.js +0 -20
- package/lib/axios/cjs/horizon/account_response.js.map +1 -1
- package/lib/axios/cjs/horizon/horizon_api.js +5 -0
- package/lib/axios/cjs/horizon/horizon_api.js.map +1 -1
- package/lib/axios/cjs/horizon/horizon_axios_client.js +1 -1
- package/lib/axios/cjs/horizon/server.js +20 -26
- package/lib/axios/cjs/horizon/server.js.map +1 -1
- package/lib/axios/cjs/index.js +66 -65
- package/lib/axios/cjs/index.js.map +1 -1
- package/lib/axios/cjs/rpc/api.js.map +1 -1
- package/lib/axios/cjs/rpc/axios.js +1 -1
- package/lib/axios/cjs/rpc/server.js +181 -13
- package/lib/axios/cjs/rpc/server.js.map +1 -1
- package/lib/axios/cjs/rpc/transaction.js +2 -20
- package/lib/axios/cjs/rpc/transaction.js.map +1 -1
- package/lib/axios/cjs/webauth/challenge_transaction.js +7 -22
- package/lib/axios/cjs/webauth/challenge_transaction.js.map +1 -1
- package/lib/axios/cjs/webauth/utils.js +1 -20
- package/lib/axios/cjs/webauth/utils.js.map +1 -1
- package/lib/axios/esm/base/auth.d.ts +181 -13
- package/lib/axios/esm/base/auth.js +146 -31
- package/lib/axios/esm/base/auth.js.map +1 -1
- package/lib/axios/esm/base/index.d.ts +2 -2
- package/lib/axios/esm/base/index.js +44 -0
- package/lib/axios/esm/base/index.js.map +1 -0
- package/lib/axios/esm/base/keypair.d.ts +27 -0
- package/lib/axios/esm/base/keypair.js +39 -0
- package/lib/axios/esm/base/keypair.js.map +1 -1
- package/lib/axios/esm/base/scval.d.ts +4 -0
- package/lib/axios/esm/base/scval.js +34 -0
- package/lib/axios/esm/base/scval.js.map +1 -1
- package/lib/axios/esm/bindings/client.d.ts +39 -0
- package/lib/axios/esm/bindings/client.js +171 -1
- package/lib/axios/esm/bindings/client.js.map +1 -1
- package/lib/axios/esm/bindings/config.js +1 -1
- package/lib/axios/esm/bindings/generator.d.ts +34 -0
- package/lib/axios/esm/bindings/generator.js +45 -16
- package/lib/axios/esm/bindings/generator.js.map +1 -1
- package/lib/axios/esm/bindings/types.d.ts +42 -0
- package/lib/axios/esm/bindings/types.js +153 -3
- package/lib/axios/esm/bindings/types.js.map +1 -1
- package/lib/axios/esm/bindings/utils.d.ts +10 -0
- package/lib/axios/esm/bindings/utils.js +9 -1
- package/lib/axios/esm/bindings/utils.js.map +1 -1
- package/lib/axios/esm/cli/index.js +19 -22
- package/lib/axios/esm/cli/index.js.map +1 -1
- package/lib/axios/esm/cli/util.d.ts +1 -1
- package/lib/axios/esm/cli/util.js +1 -20
- package/lib/axios/esm/cli/util.js.map +1 -1
- package/lib/axios/esm/contract/assembled_transaction.d.ts +7 -5
- package/lib/axios/esm/contract/assembled_transaction.js +39 -17
- package/lib/axios/esm/contract/assembled_transaction.js.map +1 -1
- package/lib/axios/esm/contract/basic_node_signer.d.ts +3 -0
- package/lib/axios/esm/contract/basic_node_signer.js +8 -42
- package/lib/axios/esm/contract/basic_node_signer.js.map +1 -1
- package/lib/axios/esm/contract/client.d.ts +49 -3
- package/lib/axios/esm/contract/client.js +56 -3
- package/lib/axios/esm/contract/client.js.map +1 -1
- package/lib/axios/esm/contract/event_spec.d.ts +78 -0
- package/lib/axios/esm/contract/event_spec.js +159 -0
- package/lib/axios/esm/contract/event_spec.js.map +1 -0
- package/lib/axios/esm/contract/index.d.ts +3 -0
- package/lib/axios/esm/contract/index.js +1 -0
- package/lib/axios/esm/contract/index.js.map +1 -1
- package/lib/axios/esm/contract/sent_transaction.js +0 -20
- package/lib/axios/esm/contract/sent_transaction.js.map +1 -1
- package/lib/axios/esm/contract/signer.d.ts +104 -0
- package/lib/axios/esm/contract/signer.js +91 -0
- package/lib/axios/esm/contract/signer.js.map +1 -0
- package/lib/axios/esm/contract/spec.d.ts +84 -0
- package/lib/axios/esm/contract/spec.js +107 -3
- package/lib/axios/esm/contract/spec.js.map +1 -1
- package/lib/axios/esm/contract/types.d.ts +25 -8
- package/lib/axios/esm/contract/types.js.map +1 -1
- package/lib/axios/esm/errors/index.d.ts +1 -0
- package/lib/axios/esm/errors/transaction_failed.d.ts +55 -0
- package/lib/axios/esm/errors/transaction_failed.js +60 -0
- package/lib/axios/esm/errors/transaction_failed.js.map +1 -0
- package/lib/axios/esm/errors/wrap_http_error.d.ts +20 -0
- package/lib/axios/esm/errors/wrap_http_error.js +18 -0
- package/lib/axios/esm/errors/wrap_http_error.js.map +1 -0
- package/lib/axios/esm/federation/server.js +15 -35
- package/lib/axios/esm/federation/server.js.map +1 -1
- package/lib/axios/esm/horizon/account_response.js +0 -20
- package/lib/axios/esm/horizon/account_response.js.map +1 -1
- package/lib/axios/esm/horizon/horizon_api.d.ts +12 -1
- package/lib/axios/esm/horizon/horizon_api.js +5 -0
- package/lib/axios/esm/horizon/horizon_api.js.map +1 -1
- package/lib/axios/esm/horizon/horizon_axios_client.js +1 -1
- package/lib/axios/esm/horizon/server.d.ts +10 -4
- package/lib/axios/esm/horizon/server.js +20 -26
- package/lib/axios/esm/horizon/server.js.map +1 -1
- package/lib/axios/esm/index.js +27 -29
- package/lib/axios/esm/index.js.map +1 -1
- package/lib/axios/esm/rpc/api.d.ts +21 -0
- package/lib/axios/esm/rpc/api.js.map +1 -1
- package/lib/axios/esm/rpc/axios.js +1 -1
- package/lib/axios/esm/rpc/server.d.ts +115 -3
- package/lib/axios/esm/rpc/server.js +181 -13
- package/lib/axios/esm/rpc/server.js.map +1 -1
- package/lib/axios/esm/rpc/transaction.js +2 -20
- package/lib/axios/esm/rpc/transaction.js.map +1 -1
- package/lib/axios/esm/webauth/challenge_transaction.js +7 -22
- package/lib/axios/esm/webauth/challenge_transaction.js.map +1 -1
- package/lib/axios/esm/webauth/utils.js +1 -20
- package/lib/axios/esm/webauth/utils.js.map +1 -1
- package/lib/cjs/base/auth.js +147 -30
- package/lib/cjs/base/auth.js.map +1 -1
- package/lib/cjs/base/index.js +113 -0
- package/lib/cjs/base/index.js.map +1 -0
- package/lib/cjs/base/keypair.js +39 -0
- package/lib/cjs/base/keypair.js.map +1 -1
- package/lib/cjs/base/scval.js +34 -0
- package/lib/cjs/base/scval.js.map +1 -1
- package/lib/cjs/bindings/client.js +170 -0
- package/lib/cjs/bindings/client.js.map +1 -1
- package/lib/cjs/bindings/config.js +1 -1
- package/lib/cjs/bindings/generator.js +45 -16
- package/lib/cjs/bindings/generator.js.map +1 -1
- package/lib/cjs/bindings/types.js +151 -1
- package/lib/cjs/bindings/types.js.map +1 -1
- package/lib/cjs/bindings/utils.js +10 -0
- package/lib/cjs/bindings/utils.js.map +1 -1
- package/lib/cjs/cli/index.js +19 -22
- package/lib/cjs/cli/index.js.map +1 -1
- package/lib/cjs/cli/util.js +1 -20
- package/lib/cjs/cli/util.js.map +1 -1
- package/lib/cjs/contract/assembled_transaction.js +39 -17
- package/lib/cjs/contract/assembled_transaction.js.map +1 -1
- package/lib/cjs/contract/basic_node_signer.js +8 -42
- package/lib/cjs/contract/basic_node_signer.js.map +1 -1
- package/lib/cjs/contract/client.js +56 -3
- package/lib/cjs/contract/client.js.map +1 -1
- package/lib/cjs/contract/event_spec.js +164 -0
- package/lib/cjs/contract/event_spec.js.map +1 -0
- package/lib/cjs/contract/index.js +2 -0
- package/lib/cjs/contract/index.js.map +1 -1
- package/lib/cjs/contract/sent_transaction.js +0 -20
- package/lib/cjs/contract/sent_transaction.js.map +1 -1
- package/lib/cjs/contract/signer.js +96 -0
- package/lib/cjs/contract/signer.js.map +1 -0
- package/lib/cjs/contract/spec.js +107 -3
- package/lib/cjs/contract/spec.js.map +1 -1
- package/lib/cjs/contract/types.js.map +1 -1
- package/lib/cjs/errors/transaction_failed.js +62 -0
- package/lib/cjs/errors/transaction_failed.js.map +1 -0
- package/lib/cjs/errors/wrap_http_error.js +20 -0
- package/lib/cjs/errors/wrap_http_error.js.map +1 -0
- package/lib/cjs/federation/server.js +15 -35
- package/lib/cjs/federation/server.js.map +1 -1
- package/lib/cjs/horizon/account_response.js +0 -20
- package/lib/cjs/horizon/account_response.js.map +1 -1
- package/lib/cjs/horizon/horizon_api.js +5 -0
- package/lib/cjs/horizon/horizon_api.js.map +1 -1
- package/lib/cjs/horizon/horizon_axios_client.js +1 -1
- package/lib/cjs/horizon/server.js +20 -26
- package/lib/cjs/horizon/server.js.map +1 -1
- package/lib/cjs/index.js +66 -65
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/rpc/api.js.map +1 -1
- package/lib/cjs/rpc/axios.js +1 -1
- package/lib/cjs/rpc/server.js +181 -13
- package/lib/cjs/rpc/server.js.map +1 -1
- package/lib/cjs/rpc/transaction.js +2 -20
- package/lib/cjs/rpc/transaction.js.map +1 -1
- package/lib/cjs/webauth/challenge_transaction.js +7 -22
- package/lib/cjs/webauth/challenge_transaction.js.map +1 -1
- package/lib/cjs/webauth/utils.js +1 -20
- package/lib/cjs/webauth/utils.js.map +1 -1
- package/lib/esm/base/auth.d.ts +181 -13
- package/lib/esm/base/auth.js +146 -31
- package/lib/esm/base/auth.js.map +1 -1
- package/lib/esm/base/index.d.ts +2 -2
- package/lib/esm/base/index.js +44 -0
- package/lib/esm/base/index.js.map +1 -0
- package/lib/esm/base/keypair.d.ts +27 -0
- package/lib/esm/base/keypair.js +39 -0
- package/lib/esm/base/keypair.js.map +1 -1
- package/lib/esm/base/scval.d.ts +4 -0
- package/lib/esm/base/scval.js +34 -0
- package/lib/esm/base/scval.js.map +1 -1
- package/lib/esm/bindings/client.d.ts +39 -0
- package/lib/esm/bindings/client.js +171 -1
- package/lib/esm/bindings/client.js.map +1 -1
- package/lib/esm/bindings/config.js +1 -1
- package/lib/esm/bindings/generator.d.ts +34 -0
- package/lib/esm/bindings/generator.js +45 -16
- package/lib/esm/bindings/generator.js.map +1 -1
- package/lib/esm/bindings/types.d.ts +42 -0
- package/lib/esm/bindings/types.js +153 -3
- package/lib/esm/bindings/types.js.map +1 -1
- package/lib/esm/bindings/utils.d.ts +10 -0
- package/lib/esm/bindings/utils.js +9 -1
- package/lib/esm/bindings/utils.js.map +1 -1
- package/lib/esm/cli/index.js +19 -22
- package/lib/esm/cli/index.js.map +1 -1
- package/lib/esm/cli/util.d.ts +1 -1
- package/lib/esm/cli/util.js +1 -20
- package/lib/esm/cli/util.js.map +1 -1
- package/lib/esm/contract/assembled_transaction.d.ts +7 -5
- package/lib/esm/contract/assembled_transaction.js +39 -17
- package/lib/esm/contract/assembled_transaction.js.map +1 -1
- package/lib/esm/contract/basic_node_signer.d.ts +3 -0
- package/lib/esm/contract/basic_node_signer.js +8 -42
- package/lib/esm/contract/basic_node_signer.js.map +1 -1
- package/lib/esm/contract/client.d.ts +49 -3
- package/lib/esm/contract/client.js +56 -3
- package/lib/esm/contract/client.js.map +1 -1
- package/lib/esm/contract/event_spec.d.ts +78 -0
- package/lib/esm/contract/event_spec.js +159 -0
- package/lib/esm/contract/event_spec.js.map +1 -0
- package/lib/esm/contract/index.d.ts +3 -0
- package/lib/esm/contract/index.js +1 -0
- package/lib/esm/contract/index.js.map +1 -1
- package/lib/esm/contract/sent_transaction.js +0 -20
- package/lib/esm/contract/sent_transaction.js.map +1 -1
- package/lib/esm/contract/signer.d.ts +104 -0
- package/lib/esm/contract/signer.js +91 -0
- package/lib/esm/contract/signer.js.map +1 -0
- package/lib/esm/contract/spec.d.ts +84 -0
- package/lib/esm/contract/spec.js +107 -3
- package/lib/esm/contract/spec.js.map +1 -1
- package/lib/esm/contract/types.d.ts +25 -8
- package/lib/esm/contract/types.js.map +1 -1
- package/lib/esm/errors/index.d.ts +1 -0
- package/lib/esm/errors/transaction_failed.d.ts +55 -0
- package/lib/esm/errors/transaction_failed.js +60 -0
- package/lib/esm/errors/transaction_failed.js.map +1 -0
- package/lib/esm/errors/wrap_http_error.d.ts +20 -0
- package/lib/esm/errors/wrap_http_error.js +18 -0
- package/lib/esm/errors/wrap_http_error.js.map +1 -0
- package/lib/esm/federation/server.js +15 -35
- package/lib/esm/federation/server.js.map +1 -1
- package/lib/esm/horizon/account_response.js +0 -20
- package/lib/esm/horizon/account_response.js.map +1 -1
- package/lib/esm/horizon/horizon_api.d.ts +12 -1
- package/lib/esm/horizon/horizon_api.js +5 -0
- package/lib/esm/horizon/horizon_api.js.map +1 -1
- package/lib/esm/horizon/horizon_axios_client.js +1 -1
- package/lib/esm/horizon/server.d.ts +10 -4
- package/lib/esm/horizon/server.js +20 -26
- package/lib/esm/horizon/server.js.map +1 -1
- package/lib/esm/index.js +27 -29
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/rpc/api.d.ts +21 -0
- package/lib/esm/rpc/api.js.map +1 -1
- package/lib/esm/rpc/axios.js +1 -1
- package/lib/esm/rpc/server.d.ts +115 -3
- package/lib/esm/rpc/server.js +181 -13
- package/lib/esm/rpc/server.js.map +1 -1
- package/lib/esm/rpc/transaction.js +2 -20
- package/lib/esm/rpc/transaction.js.map +1 -1
- package/lib/esm/webauth/challenge_transaction.js +7 -22
- package/lib/esm/webauth/challenge_transaction.js.map +1 -1
- package/lib/esm/webauth/utils.js +1 -20
- package/lib/esm/webauth/utils.js.map +1 -1
- package/package.json +35 -30
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/int.js');
|
|
4
|
+
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/hyper.js');
|
|
5
|
+
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-int.js');
|
|
6
|
+
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-hyper.js');
|
|
7
|
+
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/xdr-type.js');
|
|
8
|
+
require('buffer');
|
|
9
|
+
var curr_generated = require('../base/generated/curr_generated.js');
|
|
10
|
+
require('@noble/hashes/sha2.js');
|
|
11
|
+
require('../base/signing.js');
|
|
12
|
+
require('../base/keypair.js');
|
|
13
|
+
require('base32.js');
|
|
14
|
+
require('../base/util/continued_fraction.js');
|
|
15
|
+
require('../base/util/bignumber.js');
|
|
16
|
+
require('../base/transaction_builder.js');
|
|
17
|
+
require('../base/muxed_account.js');
|
|
18
|
+
require('../base/scval.js');
|
|
19
|
+
require('../base/numbers/uint128.js');
|
|
20
|
+
require('../base/numbers/uint256.js');
|
|
21
|
+
require('../base/numbers/int128.js');
|
|
22
|
+
require('../base/numbers/int256.js');
|
|
23
|
+
|
|
24
|
+
function events(entries) {
|
|
25
|
+
return entries.filter(
|
|
26
|
+
(entry) => entry.switch().value === curr_generated.default.ScSpecEntryKind.scSpecEntryEventV0().value
|
|
27
|
+
).map((entry) => entry.eventV0());
|
|
28
|
+
}
|
|
29
|
+
function findEvent(entries, name, occurrence = 0) {
|
|
30
|
+
if (!Number.isInteger(occurrence) || occurrence < 0) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`invalid occurrence for event ${name}: ${occurrence} (expected a non-negative integer)`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return events(entries).filter((e) => e.name().toString() === name)[occurrence];
|
|
36
|
+
}
|
|
37
|
+
function topicListParams(event) {
|
|
38
|
+
return event.params().filter(
|
|
39
|
+
(p) => p.location().value === curr_generated.default.ScSpecEventParamLocationV0.scSpecEventParamLocationTopicList().value
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function dataParams(event) {
|
|
43
|
+
return event.params().filter(
|
|
44
|
+
(p) => p.location().value === curr_generated.default.ScSpecEventParamLocationV0.scSpecEventParamLocationData().value
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function prefixTopicText(topic) {
|
|
48
|
+
switch (topic.switch().value) {
|
|
49
|
+
case curr_generated.default.ScValType.scvSymbol().value:
|
|
50
|
+
return topic.sym().toString();
|
|
51
|
+
case curr_generated.default.ScValType.scvString().value:
|
|
52
|
+
return topic.str().toString();
|
|
53
|
+
default:
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function matchesTopics(event, topics) {
|
|
58
|
+
const prefixTopics = event.prefixTopics();
|
|
59
|
+
const tlParams = topicListParams(event);
|
|
60
|
+
if (topics.length < prefixTopics.length + tlParams.length) {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
for (let i = 0; i < prefixTopics.length; i++) {
|
|
64
|
+
if (prefixTopicText(topics[i]) !== prefixTopics[i].toString()) {
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return tlParams;
|
|
69
|
+
}
|
|
70
|
+
function parseEvent(spec, entries, topics, data) {
|
|
71
|
+
let topicVals;
|
|
72
|
+
let dataVal;
|
|
73
|
+
try {
|
|
74
|
+
topicVals = topics.map(
|
|
75
|
+
(t) => typeof t === "string" ? curr_generated.default.ScVal.fromXDR(t, "base64") : t
|
|
76
|
+
);
|
|
77
|
+
dataVal = typeof data === "string" ? curr_generated.default.ScVal.fromXDR(data, "base64") : data;
|
|
78
|
+
} catch {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
const specEvents = events(entries);
|
|
82
|
+
for (const event of specEvents) {
|
|
83
|
+
const tlParams = matchesTopics(event, topicVals);
|
|
84
|
+
if (!tlParams) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const prefixLen = event.prefixTopics().length;
|
|
89
|
+
const dataOut = /* @__PURE__ */ Object.create(null);
|
|
90
|
+
tlParams.forEach((param, i) => {
|
|
91
|
+
const val = topicVals[prefixLen + i];
|
|
92
|
+
dataOut[param.name().toString()] = spec.scValToNative(
|
|
93
|
+
val,
|
|
94
|
+
param.type()
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
const dParams = dataParams(event);
|
|
98
|
+
const format = event.dataFormat().value;
|
|
99
|
+
if (format === curr_generated.default.ScSpecEventDataFormat.scSpecEventDataFormatSingleValue().value) {
|
|
100
|
+
const param = dParams[0];
|
|
101
|
+
if (param) {
|
|
102
|
+
dataOut[param.name().toString()] = spec.scValToNative(
|
|
103
|
+
dataVal,
|
|
104
|
+
param.type()
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
} else if (format === curr_generated.default.ScSpecEventDataFormat.scSpecEventDataFormatVec().value) {
|
|
108
|
+
const vec = dataVal.vec() ?? [];
|
|
109
|
+
if (vec.length < dParams.length) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
dParams.forEach((param, i) => {
|
|
113
|
+
dataOut[param.name().toString()] = spec.scValToNative(
|
|
114
|
+
vec[i],
|
|
115
|
+
param.type()
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
} else if (format === curr_generated.default.ScSpecEventDataFormat.scSpecEventDataFormatMap().value) {
|
|
119
|
+
const map = dataVal.map() ?? [];
|
|
120
|
+
dParams.forEach((param) => {
|
|
121
|
+
const name = param.name().toString();
|
|
122
|
+
const entry = map.find(
|
|
123
|
+
(e) => e.key().switch().value === curr_generated.default.ScValType.scvSymbol().value && e.key().sym().toString() === name
|
|
124
|
+
);
|
|
125
|
+
if (entry) {
|
|
126
|
+
dataOut[name] = spec.scValToNative(entry.val(), param.type());
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
name: event.name().toString(),
|
|
132
|
+
data: dataOut
|
|
133
|
+
};
|
|
134
|
+
} catch {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
function eventTopicFilter(spec, entries, name, topicValues, occurrence = 0) {
|
|
141
|
+
const event = findEvent(entries, name, occurrence);
|
|
142
|
+
if (!event) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
occurrence > 0 ? `no such event: ${name} (occurrence ${occurrence})` : `no such event: ${name}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
const filter = event.prefixTopics().map((topic) => curr_generated.default.ScVal.scvSymbol(topic.toString()).toXDR("base64"));
|
|
148
|
+
topicListParams(event).forEach((param) => {
|
|
149
|
+
const paramName = param.name().toString();
|
|
150
|
+
if (topicValues && Object.prototype.hasOwnProperty.call(topicValues, paramName)) {
|
|
151
|
+
const scVal = spec.nativeToScVal(topicValues[paramName], param.type());
|
|
152
|
+
filter.push(scVal.toXDR("base64"));
|
|
153
|
+
} else {
|
|
154
|
+
filter.push("*");
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return filter;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
exports.eventTopicFilter = eventTopicFilter;
|
|
161
|
+
exports.events = events;
|
|
162
|
+
exports.findEvent = findEvent;
|
|
163
|
+
exports.parseEvent = parseEvent;
|
|
164
|
+
//# sourceMappingURL=event_spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event_spec.js","sources":["../../../../src/contract/event_spec.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nimport type { Spec } from \"./spec.js\";\n\n/**\n * The result of successfully matching an emitted contract event against one\n * of the event specs (`xdr.ScSpecEventV0`) defined in a {@link Spec}.\n *\n * @see Spec.parseEvent\n */\nexport interface ParsedEvent {\n /** The name of the matched event (the event spec's declared name). */\n name: string;\n /**\n * All decoded event params, keyed by param name — both the\n * `topicList`-located params and the data-located ones. Once an event is\n * parsed, where a param was carried (topic vs data) no longer matters;\n * the topic list is just a way to mark which fields are indexed.\n */\n data: Record<string, any>;\n}\n\n/**\n * Gets all the SEP-48 event spec entries (`xdr.ScSpecEntryKind.scSpecEntryEventV0`)\n * out of a contract's spec entries.\n *\n * @param entries - the contract's XDR spec entries\n * @returns all event entries\n * @hidden\n */\nexport function events(entries: xdr.ScSpecEntry[]): xdr.ScSpecEventV0[] {\n return entries\n .filter(\n (entry) =>\n entry.switch().value === xdr.ScSpecEntryKind.scSpecEntryEventV0().value,\n )\n .map((entry) => entry.eventV0());\n}\n\n/**\n * Finds the event spec with the given name among a contract's event entries.\n * A contract may declare several events with the same name (e.g. composed\n * modules each emitting their own `transfer`); `occurrence` selects among\n * them, in declaration order.\n *\n * @param entries - the contract's XDR spec entries\n * @param name - the name of the event to find\n * @param occurrence - 0-based index among the events with that name\n * @returns the event spec, or `undefined` if the contract declares no event\n * with that name (at that occurrence)\n * @throws if `occurrence` is not a non-negative integer\n * @hidden\n */\nexport function findEvent(\n entries: xdr.ScSpecEntry[],\n name: string,\n occurrence: number = 0,\n): xdr.ScSpecEventV0 | undefined {\n if (!Number.isInteger(occurrence) || occurrence < 0) {\n throw new Error(\n `invalid occurrence for event ${name}: ${occurrence} (expected a non-negative integer)`,\n );\n }\n return events(entries).filter((e) => e.name().toString() === name)[\n occurrence\n ];\n}\n\n/**\n * Returns the topic-list-located params of an event, in declaration order.\n * @hidden\n */\nfunction topicListParams(event: xdr.ScSpecEventV0): xdr.ScSpecEventParamV0[] {\n return event\n .params()\n .filter(\n (p) =>\n p.location().value ===\n xdr.ScSpecEventParamLocationV0.scSpecEventParamLocationTopicList()\n .value,\n );\n}\n\n/**\n * Returns the data-located params of an event, in declaration order.\n * @hidden\n */\nfunction dataParams(event: xdr.ScSpecEventV0): xdr.ScSpecEventParamV0[] {\n return event\n .params()\n .filter(\n (p) =>\n p.location().value ===\n xdr.ScSpecEventParamLocationV0.scSpecEventParamLocationData().value,\n );\n}\n\n/**\n * Reads the text of a prefix topic ScVal. Prefix topics are declared as\n * symbols, but SEP-48 says parsers should also tolerate contracts that emit\n * them as strings, so we accept both `scvSymbol` and `scvString`.\n * @hidden\n */\nfunction prefixTopicText(topic: xdr.ScVal): string | undefined {\n switch (topic.switch().value) {\n case xdr.ScValType.scvSymbol().value:\n return topic.sym().toString();\n case xdr.ScValType.scvString().value:\n return topic.str().toString();\n default:\n return undefined;\n }\n}\n\n/**\n * Checks whether the given topics ScVals match an event's prefix topics +\n * topic-list params (matching against the prefix text and a minimum topic\n * count, not the topic-list values).\n *\n * The topic count must be at least `prefixTopics + topicListParams`, not an\n * exact match: some contracts emit trailing topics that the spec deliberately\n * leaves undeclared — e.g. SAC events carry a trailing SEP-11 asset topic.\n * @hidden\n */\nfunction matchesTopics(\n event: xdr.ScSpecEventV0,\n topics: xdr.ScVal[],\n): xdr.ScSpecEventParamV0[] | undefined {\n const prefixTopics = event.prefixTopics();\n const tlParams = topicListParams(event);\n if (topics.length < prefixTopics.length + tlParams.length) {\n return undefined;\n }\n for (let i = 0; i < prefixTopics.length; i++) {\n if (prefixTopicText(topics[i]) !== prefixTopics[i].toString()) {\n return undefined;\n }\n }\n return tlParams;\n}\n\n/**\n * Attempts to parse an emitted contract event (topics + data ScVals) against\n * the event specs (SEP-48) contained in a {@link Spec}.\n *\n * @param spec - the Spec instance to decode values with (for `scValToNative`)\n * @param entries - the contract's XDR spec entries\n * @param topics - the event's topics, as `xdr.ScVal[]` or base64 XDR strings\n * @param data - the event's data, as an `xdr.ScVal` or a base64 XDR string\n * @returns the parsed event, or `undefined` if no event spec matches\n *\n * Matching compares only the prefix topics and a minimum topic count, so if\n * two event specs share both (in particular, events with no prefix topics\n * match on arity alone), the first declared spec whose values decode\n * successfully wins.\n * @hidden\n */\nexport function parseEvent(\n spec: Spec,\n entries: xdr.ScSpecEntry[],\n topics: xdr.ScVal[] | string[],\n data: xdr.ScVal | string,\n): ParsedEvent | undefined {\n let topicVals: xdr.ScVal[];\n let dataVal: xdr.ScVal;\n try {\n topicVals = topics.map((t) =>\n typeof t === \"string\" ? xdr.ScVal.fromXDR(t, \"base64\") : t,\n );\n dataVal =\n typeof data === \"string\" ? xdr.ScVal.fromXDR(data, \"base64\") : data;\n } catch {\n return undefined;\n }\n\n const specEvents = events(entries);\n for (const event of specEvents) {\n const tlParams = matchesTopics(event, topicVals);\n if (!tlParams) {\n continue;\n }\n\n // Topic matching is fuzzy (prefix symbols + arity only), so a candidate\n // event may still turn out not to fit once its values are decoded — e.g.\n // an unrelated contract's event sharing the same prefix and topic count.\n // Treat any decode failure as a non-match and try the next candidate.\n try {\n const prefixLen = event.prefixTopics().length;\n // Param names come from an untrusted, on-chain contract spec, so a\n // param literally named \"__proto__\" must not be able to reach the\n // object's prototype via normal property assignment. A null-prototype\n // object stores it as a plain own property instead.\n const dataOut: Record<string, any> = Object.create(null);\n tlParams.forEach((param, i) => {\n const val = topicVals[prefixLen + i];\n dataOut[param.name().toString()] = spec.scValToNative(\n val,\n param.type(),\n );\n });\n\n const dParams = dataParams(event);\n const format = event.dataFormat().value;\n if (\n format ===\n xdr.ScSpecEventDataFormat.scSpecEventDataFormatSingleValue().value\n ) {\n const param = dParams[0];\n if (param) {\n dataOut[param.name().toString()] = spec.scValToNative(\n dataVal,\n param.type(),\n );\n }\n } else if (\n format === xdr.ScSpecEventDataFormat.scSpecEventDataFormatVec().value\n ) {\n const vec = dataVal.vec() ?? [];\n if (vec.length < dParams.length) {\n continue;\n }\n dParams.forEach((param, i) => {\n dataOut[param.name().toString()] = spec.scValToNative(\n vec[i],\n param.type(),\n );\n });\n } else if (\n format === xdr.ScSpecEventDataFormat.scSpecEventDataFormatMap().value\n ) {\n const map = dataVal.map() ?? [];\n dParams.forEach((param) => {\n const name = param.name().toString();\n const entry = map.find(\n (e) =>\n e.key().switch().value === xdr.ScValType.scvSymbol().value &&\n e.key().sym().toString() === name,\n );\n if (entry) {\n dataOut[name] = spec.scValToNative(entry.val(), param.type());\n }\n });\n }\n\n return {\n name: event.name().toString(),\n data: dataOut,\n };\n } catch {\n continue;\n }\n }\n\n return undefined;\n}\n\n/**\n * Builds a `getEvents` topic filter (a single row of `Api.EventFilter.topics`)\n * for the named event: the event's prefix topics (base64-encoded `scvSymbol`s)\n * followed by one entry per topic-list param — either the base64-encoded\n * ScVal for a value supplied in `topicValues`, or the wildcard `\"*\"`.\n *\n * @param spec - the Spec instance to encode values with (for `nativeToScVal`)\n * @param entries - the contract's XDR spec entries\n * @param name - the name of the event\n * @param topicValues - (optional) native values for topic-list params, keyed by param name\n * @param occurrence - (optional) 0-based index among same-named events, for\n * contracts that declare the same event name more than once\n * @returns a single topic filter row\n * @throws if no event with the given name (at the given occurrence) exists,\n * or if `occurrence` is not a non-negative integer\n * @hidden\n */\nexport function eventTopicFilter(\n spec: Spec,\n entries: xdr.ScSpecEntry[],\n name: string,\n topicValues?: Record<string, any>,\n occurrence: number = 0,\n): string[] {\n const event = findEvent(entries, name, occurrence);\n if (!event) {\n throw new Error(\n occurrence > 0\n ? `no such event: ${name} (occurrence ${occurrence})`\n : `no such event: ${name}`,\n );\n }\n const filter: string[] = event\n .prefixTopics()\n .map((topic) => xdr.ScVal.scvSymbol(topic.toString()).toXDR(\"base64\"));\n\n topicListParams(event).forEach((param) => {\n const paramName = param.name().toString();\n if (\n topicValues &&\n Object.prototype.hasOwnProperty.call(topicValues, paramName)\n ) {\n const scVal = spec.nativeToScVal(topicValues[paramName], param.type());\n filter.push(scVal.toXDR(\"base64\"));\n } else {\n filter.push(\"*\");\n }\n });\n\n return filter;\n}\n"],"names":["xdr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6BO,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
5
5
|
var client = require('./client.js');
|
|
6
6
|
var rust_result = require('./rust_result.js');
|
|
7
7
|
var sent_transaction = require('./sent_transaction.js');
|
|
8
|
+
var signer = require('./signer.js');
|
|
8
9
|
var spec = require('./spec.js');
|
|
9
10
|
var types = require('./types.js');
|
|
10
11
|
|
|
@@ -17,6 +18,7 @@ exports.Err = rust_result.Err;
|
|
|
17
18
|
exports.Ok = rust_result.Ok;
|
|
18
19
|
exports.SentTransaction = sent_transaction.SentTransaction;
|
|
19
20
|
exports.Watcher = sent_transaction.Watcher;
|
|
21
|
+
exports.KeypairSigner = signer.KeypairSigner;
|
|
20
22
|
exports.Spec = spec.Spec;
|
|
21
23
|
exports.DEFAULT_TIMEOUT = types.DEFAULT_TIMEOUT;
|
|
22
24
|
exports.NULL_ACCOUNT = types.NULL_ACCOUNT;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,26 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var api = require('../rpc/api.js');
|
|
4
4
|
var server = require('../rpc/server.js');
|
|
5
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/int.js');
|
|
6
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/hyper.js');
|
|
7
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-int.js');
|
|
8
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-hyper.js');
|
|
9
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/xdr-type.js');
|
|
10
|
-
require('buffer');
|
|
11
|
-
require('../base/generated/curr_generated.js');
|
|
12
|
-
require('@noble/hashes/sha2.js');
|
|
13
|
-
require('../base/signing.js');
|
|
14
|
-
require('../base/keypair.js');
|
|
15
|
-
require('base32.js');
|
|
16
|
-
require('../base/util/continued_fraction.js');
|
|
17
|
-
require('../base/util/bignumber.js');
|
|
18
|
-
require('../base/transaction_builder.js');
|
|
19
|
-
require('../base/muxed_account.js');
|
|
20
|
-
require('../base/scval.js');
|
|
21
|
-
require('../base/numbers/uint128.js');
|
|
22
|
-
require('../base/numbers/uint256.js');
|
|
23
|
-
require('../base/numbers/int128.js');
|
|
24
|
-
require('../base/numbers/int256.js');
|
|
25
5
|
var utils = require('./utils.js');
|
|
26
6
|
var types = require('./types.js');
|
|
27
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sent_transaction.js","sources":["../../../../src/contract/sent_transaction.ts"],"sourcesContent":["/* disable max-classes rule, because extending error shouldn't count! */\n/* eslint max-classes-per-file: 0 */\nimport type { MethodOptions } from \"./types.js\";\nimport { Server } from \"../rpc/index.js\";\nimport { Api } from \"../rpc/api.js\";\nimport { withExponentialBackoff } from \"./utils.js\";\nimport { DEFAULT_TIMEOUT } from \"./types.js\";\nimport type { AssembledTransaction } from \"./assembled_transaction.js\";\n\n/**\n * A transaction that has been sent to the Soroban network. This happens in two steps:\n *\n * 1. `sendTransaction`: initial submission of the transaction to the network.\n * If this step runs into problems, the attempt to sign and send will be\n * aborted. You can see the result of this call in the\n * `sendTransactionResponse` getter.\n * 2. `getTransaction`: once the transaction has been submitted to the network\n * successfully, you need to wait for it to finalize to get the result of the\n * transaction. This will be retried with exponential backoff for\n * {@link MethodOptions.timeoutInSeconds} seconds. See all attempts in\n * `getTransactionResponseAll` and the most recent attempt in\n * `getTransactionResponse`.\n *\n *\n * @param signTransaction - More info in {@link MethodOptions}\n * @param assembled - {@link AssembledTransaction} from which this SentTransaction was initialized\n */\nexport class SentTransaction<T> {\n public server: Server;\n\n /**\n * The result of calling `sendTransaction` to broadcast the transaction to the\n * network.\n */\n public sendTransactionResponse?: Api.SendTransactionResponse;\n\n /**\n * If `sendTransaction` completes successfully (which means it has `status: 'PENDING'`),\n * then `getTransaction` will be called in a loop for\n * {@link MethodOptions.timeoutInSeconds} seconds. This array contains all\n * the results of those calls.\n */\n public getTransactionResponseAll?: Api.GetTransactionResponse[];\n\n /**\n * The most recent result of calling `getTransaction`, from the\n * `getTransactionResponseAll` array.\n */\n public getTransactionResponse?: Api.GetTransactionResponse;\n\n static Errors = {\n SendFailed: class SendFailedError extends Error {},\n SendResultOnly: class SendResultOnlyError extends Error {},\n TransactionStillPending: class TransactionStillPendingError extends Error {},\n };\n\n constructor(public assembled: AssembledTransaction<T>) {\n const { server, allowHttp, headers, rpcUrl } = this.assembled.options;\n this.server = server ?? new Server(rpcUrl, { allowHttp, headers });\n }\n\n /**\n * Initialize a `SentTransaction` from {@link AssembledTransaction}\n * `assembled`, passing an optional {@link Watcher} `watcher`. This will also\n * send the transaction to the network.\n */\n static init = async <U>(\n /** {@link AssembledTransaction} from which this SentTransaction was initialized */\n assembled: AssembledTransaction<U>,\n watcher?: Watcher,\n ): Promise<SentTransaction<U>> => {\n const tx = new SentTransaction(assembled);\n const sent = await tx.send(watcher);\n return sent;\n };\n\n private send = async (watcher?: Watcher): Promise<this> => {\n this.sendTransactionResponse = await this.server.sendTransaction(\n this.assembled.signed!,\n );\n\n if (this.sendTransactionResponse.status !== \"PENDING\") {\n throw new SentTransaction.Errors.SendFailed(\n `Sending the transaction to the network failed!\\n${JSON.stringify(\n this.sendTransactionResponse,\n null,\n 2,\n )}`,\n );\n }\n\n if (watcher?.onSubmitted) watcher.onSubmitted(this.sendTransactionResponse);\n\n const { hash } = this.sendTransactionResponse;\n\n const timeoutInSeconds =\n this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT;\n this.getTransactionResponseAll = await withExponentialBackoff(\n async () => {\n const tx = await this.server.getTransaction(hash);\n if (watcher?.onProgress) watcher.onProgress(tx);\n return tx;\n },\n (resp) => resp.status === Api.GetTransactionStatus.NOT_FOUND,\n timeoutInSeconds,\n );\n\n this.getTransactionResponse =\n this.getTransactionResponseAll[this.getTransactionResponseAll.length - 1];\n if (\n this.getTransactionResponse.status === Api.GetTransactionStatus.NOT_FOUND\n ) {\n throw new SentTransaction.Errors.TransactionStillPending(\n `Waited ${timeoutInSeconds} seconds for transaction to complete, but it did not. ` +\n `Returning anyway. Check the transaction status manually. ` +\n `Sent transaction: ${JSON.stringify(\n this.sendTransactionResponse,\n null,\n 2,\n )}\\n` +\n `All attempts to get the result: ${JSON.stringify(\n this.getTransactionResponseAll,\n null,\n 2,\n )}`,\n );\n }\n\n return this;\n };\n\n get result(): T {\n // 1. check if transaction was submitted and awaited with `getTransaction`\n if (\"getTransactionResponse\" in this && this.getTransactionResponse) {\n // getTransactionResponse has a `returnValue` field unless it failed\n if (\"returnValue\" in this.getTransactionResponse) {\n return this.assembled.options.parseResultXdr(\n this.getTransactionResponse.returnValue!,\n );\n }\n\n // if \"returnValue\" not present, the transaction failed; return without\n // parsing the result\n throw new Error(\"Transaction failed! Cannot parse result.\");\n }\n\n // 2. otherwise, maybe it was merely sent with `sendTransaction`\n if (this.sendTransactionResponse) {\n const errorResult = this.sendTransactionResponse.errorResult?.result();\n if (errorResult) {\n throw new SentTransaction.Errors.SendFailed(\n `Transaction simulation looked correct, but attempting to send the transaction failed. Check \\`simulation\\` and \\`sendTransactionResponseAll\\` to troubleshoot. Decoded \\`sendTransactionResponse.errorResultXdr\\`: ${errorResult}`,\n );\n }\n throw new SentTransaction.Errors.SendResultOnly(\n `Transaction was sent to the network, but not yet awaited. No result to show. Await transaction completion with \\`getTransaction(sendTransactionResponse.hash)\\``,\n );\n }\n\n // 3. finally, if neither of those are present, throw an error\n throw new Error(\n `Sending transaction failed: ${JSON.stringify(this.assembled.signed)}`,\n );\n }\n}\n\nexport abstract class Watcher {\n /**\n * Function to call after transaction has been submitted successfully to\n * the network for processing\n */\n abstract onSubmitted?(response?: Api.SendTransactionResponse): void;\n\n /**\n * Function to call every time the submitted transaction's status is\n * checked while awaiting its full inclusion in the ledger\n */\n abstract onProgress?(response?: Api.GetTransactionResponse): void;\n}\n"],"names":["server","Server","DEFAULT_TIMEOUT","withExponentialBackoff","Api"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,eAAA,CAAmB;AAAA,EA6B9B,YAAmB,SAAA,EAAoC;AAApC,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACjB,IAAA,MAAM,UAAEA,QAAA,EAAQ,SAAA,EAAW,SAAS,MAAA,EAAO,GAAI,KAAK,SAAA,CAAU,OAAA;AAC9D,IAAA,IAAA,CAAK,MAAA,GAASA,YAAU,IAAIC,gBAAA,CAAO,QAAQ,EAAE,SAAA,EAAW,SAAS,CAAA;AAAA,EACnE;AAAA,EAHmB,SAAA;AAAA,EA5BZ,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,uBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,yBAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,sBAAA;AAAA,EAEP,OAAO,MAAA,GAAS;AAAA,IACd,UAAA,EAAY,MAAM,eAAA,SAAwB,KAAA,CAAM;AAAA,KAAC;AAAA,IACjD,cAAA,EAAgB,MAAM,mBAAA,SAA4B,KAAA,CAAM;AAAA,KAAC;AAAA,IACzD,uBAAA,EAAyB,MAAM,4BAAA,SAAqC,KAAA,CAAM;AAAA;AAAC,GAC7E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,OAAO,IAAA,GAAO,OAEZ,SAAA,EACA,OAAA,KACgC;AAChC,IAAA,MAAM,EAAA,GAAK,IAAI,eAAA,CAAgB,SAAS,CAAA;AACxC,IAAA,MAAM,IAAA,GAAO,MAAM,EAAA,CAAG,IAAA,CAAK,OAAO,CAAA;AAClC,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AAAA,EAEQ,IAAA,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":3,"file":"sent_transaction.js","sources":["../../../../src/contract/sent_transaction.ts"],"sourcesContent":["/* disable max-classes rule, because extending error shouldn't count! */\n/* eslint max-classes-per-file: 0 */\nimport type { MethodOptions } from \"./types.js\";\nimport { Server } from \"../rpc/index.js\";\nimport { Api } from \"../rpc/api.js\";\nimport { withExponentialBackoff } from \"./utils.js\";\nimport { DEFAULT_TIMEOUT } from \"./types.js\";\nimport type { AssembledTransaction } from \"./assembled_transaction.js\";\n\n/**\n * A transaction that has been sent to the Soroban network. This happens in two steps:\n *\n * 1. `sendTransaction`: initial submission of the transaction to the network.\n * If this step runs into problems, the attempt to sign and send will be\n * aborted. You can see the result of this call in the\n * `sendTransactionResponse` getter.\n * 2. `getTransaction`: once the transaction has been submitted to the network\n * successfully, you need to wait for it to finalize to get the result of the\n * transaction. This will be retried with exponential backoff for\n * {@link MethodOptions.timeoutInSeconds} seconds. See all attempts in\n * `getTransactionResponseAll` and the most recent attempt in\n * `getTransactionResponse`.\n *\n *\n * @param signTransaction - More info in {@link MethodOptions}\n * @param assembled - {@link AssembledTransaction} from which this SentTransaction was initialized\n */\nexport class SentTransaction<T> {\n public server: Server;\n\n /**\n * The result of calling `sendTransaction` to broadcast the transaction to the\n * network.\n */\n public sendTransactionResponse?: Api.SendTransactionResponse;\n\n /**\n * If `sendTransaction` completes successfully (which means it has `status: 'PENDING'`),\n * then `getTransaction` will be called in a loop for\n * {@link MethodOptions.timeoutInSeconds} seconds. This array contains all\n * the results of those calls.\n */\n public getTransactionResponseAll?: Api.GetTransactionResponse[];\n\n /**\n * The most recent result of calling `getTransaction`, from the\n * `getTransactionResponseAll` array.\n */\n public getTransactionResponse?: Api.GetTransactionResponse;\n\n static Errors = {\n SendFailed: class SendFailedError extends Error {},\n SendResultOnly: class SendResultOnlyError extends Error {},\n TransactionStillPending: class TransactionStillPendingError extends Error {},\n };\n\n constructor(public assembled: AssembledTransaction<T>) {\n const { server, allowHttp, headers, rpcUrl } = this.assembled.options;\n this.server = server ?? new Server(rpcUrl, { allowHttp, headers });\n }\n\n /**\n * Initialize a `SentTransaction` from {@link AssembledTransaction}\n * `assembled`, passing an optional {@link Watcher} `watcher`. This will also\n * send the transaction to the network.\n */\n static init = async <U>(\n /** {@link AssembledTransaction} from which this SentTransaction was initialized */\n assembled: AssembledTransaction<U>,\n watcher?: Watcher,\n ): Promise<SentTransaction<U>> => {\n const tx = new SentTransaction(assembled);\n const sent = await tx.send(watcher);\n return sent;\n };\n\n private send = async (watcher?: Watcher): Promise<this> => {\n this.sendTransactionResponse = await this.server.sendTransaction(\n this.assembled.signed!,\n );\n\n if (this.sendTransactionResponse.status !== \"PENDING\") {\n throw new SentTransaction.Errors.SendFailed(\n `Sending the transaction to the network failed!\\n${JSON.stringify(\n this.sendTransactionResponse,\n null,\n 2,\n )}`,\n );\n }\n\n if (watcher?.onSubmitted) watcher.onSubmitted(this.sendTransactionResponse);\n\n const { hash } = this.sendTransactionResponse;\n\n const timeoutInSeconds =\n this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT;\n this.getTransactionResponseAll = await withExponentialBackoff(\n async () => {\n const tx = await this.server.getTransaction(hash);\n if (watcher?.onProgress) watcher.onProgress(tx);\n return tx;\n },\n (resp) => resp.status === Api.GetTransactionStatus.NOT_FOUND,\n timeoutInSeconds,\n );\n\n this.getTransactionResponse =\n this.getTransactionResponseAll[this.getTransactionResponseAll.length - 1];\n if (\n this.getTransactionResponse.status === Api.GetTransactionStatus.NOT_FOUND\n ) {\n throw new SentTransaction.Errors.TransactionStillPending(\n `Waited ${timeoutInSeconds} seconds for transaction to complete, but it did not. ` +\n `Returning anyway. Check the transaction status manually. ` +\n `Sent transaction: ${JSON.stringify(\n this.sendTransactionResponse,\n null,\n 2,\n )}\\n` +\n `All attempts to get the result: ${JSON.stringify(\n this.getTransactionResponseAll,\n null,\n 2,\n )}`,\n );\n }\n\n return this;\n };\n\n get result(): T {\n // 1. check if transaction was submitted and awaited with `getTransaction`\n if (\"getTransactionResponse\" in this && this.getTransactionResponse) {\n // getTransactionResponse has a `returnValue` field unless it failed\n if (\"returnValue\" in this.getTransactionResponse) {\n return this.assembled.options.parseResultXdr(\n this.getTransactionResponse.returnValue!,\n );\n }\n\n // if \"returnValue\" not present, the transaction failed; return without\n // parsing the result\n throw new Error(\"Transaction failed! Cannot parse result.\");\n }\n\n // 2. otherwise, maybe it was merely sent with `sendTransaction`\n if (this.sendTransactionResponse) {\n const errorResult = this.sendTransactionResponse.errorResult?.result();\n if (errorResult) {\n throw new SentTransaction.Errors.SendFailed(\n `Transaction simulation looked correct, but attempting to send the transaction failed. Check \\`simulation\\` and \\`sendTransactionResponseAll\\` to troubleshoot. Decoded \\`sendTransactionResponse.errorResultXdr\\`: ${errorResult}`,\n );\n }\n throw new SentTransaction.Errors.SendResultOnly(\n `Transaction was sent to the network, but not yet awaited. No result to show. Await transaction completion with \\`getTransaction(sendTransactionResponse.hash)\\``,\n );\n }\n\n // 3. finally, if neither of those are present, throw an error\n throw new Error(\n `Sending transaction failed: ${JSON.stringify(this.assembled.signed)}`,\n );\n }\n}\n\nexport abstract class Watcher {\n /**\n * Function to call after transaction has been submitted successfully to\n * the network for processing\n */\n abstract onSubmitted?(response?: Api.SendTransactionResponse): void;\n\n /**\n * Function to call every time the submitted transaction's status is\n * checked while awaiting its full inclusion in the ledger\n */\n abstract onProgress?(response?: Api.GetTransactionResponse): void;\n}\n"],"names":["server","Server","DEFAULT_TIMEOUT","withExponentialBackoff","Api"],"mappings":";;;;;;;AA2BO,MAAM,eAAA,CAAmB;AAAA,EA6B9B,YAAmB,SAAA,EAAoC;AAApC,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACjB,IAAA,MAAM,UAAEA,QAAA,EAAQ,SAAA,EAAW,SAAS,MAAA,EAAO,GAAI,KAAK,SAAA,CAAU,OAAA;AAC9D,IAAA,IAAA,CAAK,MAAA,GAASA,YAAU,IAAIC,gBAAA,CAAO,QAAQ,EAAE,SAAA,EAAW,SAAS,CAAA;AAAA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QAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAQ,cAAA;AAAA,UAC5B,KAAK,sBAAA,CAAuB;AAAA,SAC9B;AAAA,MACF;AAIA,MAAA,MAAM,IAAI,MAAM,0CAA0C,CAAA;AAAA,IAC5D;AAGA,IAAA,IAAI,KAAK,uBAAA,EAAyB;AAChC,MAAA,MAAM,WAAA,GAAc,IAAA,CAAK,uBAAA,CAAwB,WAAA,EAAa,MAAA,EAAO;AACrE,MAAA,IAAI,WAAA,EAAa;AACf,QAAA,MAAM,IAAI,gBAAgB,MAAA,CAAO,UAAA;AAAA,UAC/B,sNAAsN,WAAW,CAAA;AAAA,SACnO;AAAA,MACF;AACA,MAAA,MAAM,IAAI,gBAAgB,MAAA,CAAO,cAAA;AAAA,QAC/B,CAAA,+JAAA;AAAA,OACF;AAAA,IACF;AAGA,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,+BAA+B,IAAA,CAAK,SAAA,CAAU,IAAA,CAAK,SAAA,CAAU,MAAM,CAAC,CAAA;AAAA,KACtE;AAAA,EACF;AACF;AAEO,MAAe,OAAA,CAAQ;AAY9B;;;;;"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var buffer = require('buffer');
|
|
4
|
+
var transaction_builder = require('../base/transaction_builder.js');
|
|
5
|
+
var hashing = require('../base/hashing.js');
|
|
6
|
+
|
|
7
|
+
class KeypairSigner {
|
|
8
|
+
/**
|
|
9
|
+
* @param keypair - the {@link Keypair} to sign with. Signing throws
|
|
10
|
+
* `cannot sign: no secret key available` if it holds only a public key.
|
|
11
|
+
* @param networkPassphrase - passphrase of the network to sign for, used
|
|
12
|
+
* whenever the caller does not pass one at signing time
|
|
13
|
+
*/
|
|
14
|
+
constructor(keypair, networkPassphrase) {
|
|
15
|
+
this.keypair = keypair;
|
|
16
|
+
this.networkPassphrase = networkPassphrase;
|
|
17
|
+
this.address = keypair.publicKey();
|
|
18
|
+
}
|
|
19
|
+
keypair;
|
|
20
|
+
networkPassphrase;
|
|
21
|
+
/**
|
|
22
|
+
* The keypair's Ed25519 account address (`G…`), always `keypair.publicKey()`.
|
|
23
|
+
*/
|
|
24
|
+
address;
|
|
25
|
+
/* Arrow instance properties rather than prototype methods because
|
|
26
|
+
`basicNodeSigner` destructures them into a plain object, which would lose
|
|
27
|
+
`this` on a prototype method. (The normalizers below tolerate either, since
|
|
28
|
+
they bind what they extract.)
|
|
29
|
+
|
|
30
|
+
They stay `async` despite having nothing to await (hence the rule
|
|
31
|
+
suppressions): that way a synchronous failure — malformed XDR, or a keypair
|
|
32
|
+
holding no secret key — rejects the returned promise instead of throwing,
|
|
33
|
+
preserving the behavior `basicNodeSigner` had before it delegated here. */
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
35
|
+
signTransaction = async (xdr, opts) => {
|
|
36
|
+
const t = transaction_builder.TransactionBuilder.fromXDR(
|
|
37
|
+
xdr,
|
|
38
|
+
opts?.networkPassphrase || this.networkPassphrase
|
|
39
|
+
);
|
|
40
|
+
t.sign(this.keypair);
|
|
41
|
+
return {
|
|
42
|
+
signedTxXdr: t.toXDR(),
|
|
43
|
+
signerAddress: this.address
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
47
|
+
signAuthEntry = async (authEntry) => {
|
|
48
|
+
const signedAuthEntry = this.keypair.sign(hashing.hash(buffer.Buffer.from(authEntry, "base64"))).toString("base64");
|
|
49
|
+
return {
|
|
50
|
+
signedAuthEntry,
|
|
51
|
+
signerAddress: this.address
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function isKeypairLike(value) {
|
|
56
|
+
return "publicKey" in value && typeof value.publicKey === "function" && "sign" in value && typeof value.sign === "function" && "signDecorated" in value && typeof value.signDecorated === "function";
|
|
57
|
+
}
|
|
58
|
+
function signerAddress(value) {
|
|
59
|
+
if (value == null || typeof value !== "object") return void 0;
|
|
60
|
+
if ("signTransaction" in value && typeof value.address === "string") {
|
|
61
|
+
return value.address;
|
|
62
|
+
}
|
|
63
|
+
return isKeypairLike(value) ? value.publicKey() : void 0;
|
|
64
|
+
}
|
|
65
|
+
function toSignTransaction(value, networkPassphrase) {
|
|
66
|
+
if (value == null) return void 0;
|
|
67
|
+
if (typeof value === "function") return value;
|
|
68
|
+
if (typeof value !== "object") return void 0;
|
|
69
|
+
if ("signTransaction" in value) {
|
|
70
|
+
const fn = value.signTransaction;
|
|
71
|
+
return typeof fn === "function" ? fn.bind(value) : void 0;
|
|
72
|
+
}
|
|
73
|
+
if (isKeypairLike(value)) {
|
|
74
|
+
return new KeypairSigner(value, networkPassphrase).signTransaction;
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
function toSignAuthEntry(value, networkPassphrase) {
|
|
79
|
+
if (value == null) return void 0;
|
|
80
|
+
if (typeof value === "function") return value;
|
|
81
|
+
if (typeof value !== "object") return void 0;
|
|
82
|
+
if ("signTransaction" in value) {
|
|
83
|
+
const fn = value.signAuthEntry;
|
|
84
|
+
return typeof fn === "function" ? fn.bind(value) : void 0;
|
|
85
|
+
}
|
|
86
|
+
if (isKeypairLike(value)) {
|
|
87
|
+
return new KeypairSigner(value, networkPassphrase).signAuthEntry;
|
|
88
|
+
}
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.KeypairSigner = KeypairSigner;
|
|
93
|
+
exports.signerAddress = signerAddress;
|
|
94
|
+
exports.toSignAuthEntry = toSignAuthEntry;
|
|
95
|
+
exports.toSignTransaction = toSignTransaction;
|
|
96
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sources":["../../../../src/contract/signer.ts"],"sourcesContent":["import { Keypair, TransactionBuilder, hash } from \"../base/index.js\";\nimport type { SignAuthEntry, SignTransaction } from \"./types.js\";\n\n/**\n * A signing identity: something that can sign, and that knows who it is.\n *\n * A bare {@link SignTransaction} callback carries no identity, so callers have\n * to pass the signer's address alongside it and keep the two in sync. A\n * `Signer` bundles them.\n *\n * `address` is deliberately a plain string rather than an Ed25519 public key:\n * it is a `G…` account address for keypair-backed signers, but may be a `C…`\n * contract address for smart accounts, whose signatures are not Ed25519 at all.\n *\n * `signTransaction` and `signAuthEntry` keep the exact shapes the SDK already\n * accepts (those of SEP-43 wallets such as Freighter), so an existing wallet\n * object becomes a `Signer` by gaining an `address`.\n *\n * `signAuthEntry` is optional because not every wallet implements it; it is\n * only needed for multi-party (non-invoker) auth entry signing.\n *\n * Accepted wherever the SDK takes a signing callback: the `signTransaction` and\n * `signAuthEntry` options on `ClientOptions` and `MethodOptions`, and the\n * per-call overrides on `AssembledTransaction`'s `sign`, `signAndSend`, and\n * `signAuthEntries`.\n */\nexport interface Signer {\n /** The address this signer signs as: `G…` for accounts, `C…` for contracts. */\n readonly address: string;\n /** Signs a transaction envelope. Matches `signTransaction` from Freighter. */\n signTransaction: SignTransaction;\n /** Signs an auth entry preimage. Matches `signAuthEntry` from Freighter. */\n signAuthEntry?: SignAuthEntry;\n}\n\n/**\n * A {@link Signer} backed by a local {@link Keypair}.\n *\n * Suitable for Node applications, scripts, and tests — anywhere the secret key\n * lives in the same process. For browser applications, use the SEP-43 wallet's\n * own `signTransaction`, or wrap it in an object satisfying {@link Signer}.\n *\n * @example\n * ```ts\n * import { Keypair } from \"@stellar/stellar-sdk\";\n * import { Client, KeypairSigner } from \"@stellar/stellar-sdk/contract\";\n *\n * const keypair = Keypair.fromSecret(secret);\n * const client = await Client.from({\n * contractId,\n * networkPassphrase,\n * rpcUrl,\n * publicKey: keypair.publicKey(),\n * signTransaction: new KeypairSigner(keypair, networkPassphrase),\n * });\n * ```\n */\nexport class KeypairSigner implements Signer {\n /**\n * The keypair's Ed25519 account address (`G…`), always `keypair.publicKey()`.\n */\n readonly address: string;\n\n /**\n * @param keypair - the {@link Keypair} to sign with. Signing throws\n * `cannot sign: no secret key available` if it holds only a public key.\n * @param networkPassphrase - passphrase of the network to sign for, used\n * whenever the caller does not pass one at signing time\n */\n constructor(\n private readonly keypair: Keypair,\n private readonly networkPassphrase: string,\n ) {\n this.address = keypair.publicKey();\n }\n\n /* Arrow instance properties rather than prototype methods because\n `basicNodeSigner` destructures them into a plain object, which would lose\n `this` on a prototype method. (The normalizers below tolerate either, since\n they bind what they extract.)\n\n They stay `async` despite having nothing to await (hence the rule\n suppressions): that way a synchronous failure — malformed XDR, or a keypair\n holding no secret key — rejects the returned promise instead of throwing,\n preserving the behavior `basicNodeSigner` had before it delegated here. */\n\n // eslint-disable-next-line @typescript-eslint/require-await\n signTransaction: SignTransaction = async (xdr, opts) => {\n const t = TransactionBuilder.fromXDR(\n xdr,\n opts?.networkPassphrase || this.networkPassphrase,\n );\n\n t.sign(this.keypair);\n\n return {\n signedTxXdr: t.toXDR(),\n signerAddress: this.address,\n };\n };\n\n // eslint-disable-next-line @typescript-eslint/require-await\n signAuthEntry: SignAuthEntry = async (authEntry) => {\n const signedAuthEntry = this.keypair\n .sign(hash(Buffer.from(authEntry, \"base64\")))\n .toString(\"base64\");\n\n return {\n signedAuthEntry,\n signerAddress: this.address,\n };\n };\n}\n\n/**\n * Anything accepted where a `signTransaction` callback is expected: the raw\n * SEP-43 callback, a {@link Signer}, or a {@link Keypair}.\n */\nexport type SignTransactionLike = SignTransaction | Signer | Keypair;\n\n/**\n * Anything accepted where a `signAuthEntry` callback is expected: the raw\n * SEP-43 callback, a {@link Signer}, or a {@link Keypair}.\n */\nexport type SignAuthEntryLike = SignAuthEntry | Signer | Keypair;\n\n/**\n * Recognizes a {@link Keypair} by the three members {@link KeypairSigner} calls:\n * `publicKey` for the address, `sign` for auth entries, and `signDecorated`,\n * which `Transaction.sign` reaches for when signing an envelope. All three are\n * required, so a partial object is refused here rather than yielding a callback\n * that throws once it is actually used.\n *\n * Structural rather than `instanceof` on purpose: this package ships a CJS and\n * an ESM build whose `Keypair` classes are distinct objects, so a keypair made\n * through one entry point fails `instanceof` against the other despite working\n * perfectly. Duplicate copies of the SDK in one dependency tree do the same.\n *\n * Only ever reached after a `Signer` has been ruled out, so an object carrying\n * `signTransaction` can never be misrouted here.\n */\nfunction isKeypairLike(value: object): value is Keypair {\n return (\n \"publicKey\" in value &&\n typeof value.publicKey === \"function\" &&\n \"sign\" in value &&\n typeof value.sign === \"function\" &&\n \"signDecorated\" in value &&\n typeof value.signDecorated === \"function\"\n );\n}\n\n/** @internal */\nexport function signerAddress(\n value: SignAuthEntryLike | undefined,\n): string | undefined {\n if (value == null || typeof value !== \"object\") return undefined;\n if (\"signTransaction\" in value && typeof value.address === \"string\") {\n return value.address;\n }\n return isKeypairLike(value) ? value.publicKey() : undefined;\n}\n\n/**\n * Reduces the accepted signing shapes down to a plain callback.\n *\n * Anything that carries no usable callback yields `undefined` — including an\n * absent value, or an object that does not match any accepted shape — so the\n * caller decides how to report a missing signer. This is deliberately lenient:\n * callers reaching the SDK from plain JavaScript are not held to the types, and\n * a clear `NoSigner` beats a `TypeError` from deep inside a normalizer.\n *\n * Internal: called at the entry points that read a caller-supplied signer, so\n * the rest of the code only ever deals with a `SignTransaction`.\n */\nexport function toSignTransaction(\n value: SignTransactionLike | undefined,\n networkPassphrase: string,\n): SignTransaction | undefined {\n // `== null` so an explicit `null` from a JS caller behaves like `undefined`.\n if (value == null) return undefined;\n\n if (typeof value === \"function\") return value;\n\n // Guards the `in` checks below, which throw on primitives.\n if (typeof value !== \"object\") return undefined;\n\n // `signTransaction` is a `Signer`'s required member, so it identifies one.\n // Bound because a `Signer` may implement it as a prototype method that relies\n // on `this`; a bare reference would lose its receiver. The `typeof` check is\n // for untyped callers: a present-but-non-function member has no `bind`.\n if (\"signTransaction\" in value) {\n const fn = value.signTransaction;\n return typeof fn === \"function\" ? fn.bind(value) : undefined;\n }\n\n if (isKeypairLike(value)) {\n return new KeypairSigner(value, networkPassphrase).signTransaction;\n }\n\n return undefined;\n}\n\n/**\n * Reduces the accepted signing shapes down to a plain callback.\n *\n * A {@link Signer} whose optional `signAuthEntry` is absent yields `undefined`,\n * so the caller reports it the same way it reports a missing option.\n *\n * Internal: see {@link toSignTransaction}.\n */\nexport function toSignAuthEntry(\n value: SignAuthEntryLike | undefined,\n networkPassphrase: string,\n): SignAuthEntry | undefined {\n if (value == null) return undefined;\n\n if (typeof value === \"function\") return value;\n\n if (typeof value !== \"object\") return undefined;\n\n // Identified and bound as in `toSignTransaction`. The `typeof` check also\n // covers the ordinary case of a `Signer` that omits the optional\n // `signAuthEntry`, which is reported as `undefined`.\n if (\"signTransaction\" in value) {\n const fn = value.signAuthEntry;\n return typeof fn === \"function\" ? fn.bind(value) : undefined;\n }\n\n if (isKeypairLike(value)) {\n return new KeypairSigner(value, networkPassphrase).signAuthEntry;\n }\n\n return undefined;\n}\n"],"names":["TransactionBuilder","hash","Buffer"],"mappings":";;;;;;AAyDO,MAAM,aAAA,CAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY3C,WAAA,CACmB,SACA,iBAAA,EACjB;AAFiB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAEjB,IAAA,IAAA,CAAK,OAAA,GAAU,QAAQ,SAAA,EAAU;AAAA,EACnC;AAAA,EAJmB,OAAA;AAAA,EACA,iBAAA;AAAA;AAAA;AAAA;AAAA,EAVV,OAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BT,eAAA,GAAmC,OAAO,GAAA,EAAK,IAAA,KAAS;AACtD,IAAA,MAAM,IAAIA,sCAAA,CAAmB,OAAA;AAAA,MAC3B,GAAA;AAAA,MACA,IAAA,EAAM,qBAAqB,IAAA,CAAK;AAAA,KAClC;AAEA,IAAA,CAAA,CAAE,IAAA,CAAK,KAAK,OAAO,CAAA;AAEnB,IAAA,OAAO;AAAA,MACL,WAAA,EAAa,EAAE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A;AACjB,IAAA,OAAO,OAAO,EAAA,KAAO,UAAA,GAAa,EAAA,CAAG,IAAA,CAAK,KAAK,CAAA,GAAI,MAAA;AAAA,EACrD;AAEA,EAAA,IAAI,aAAA,CAAc,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,IAAI,aAAA,CAAc,KAAA,EAAO,iBAAiB,CAAA,CAAE,eAAA;AAAA,EACrD;AAEA,EAAA,OAAO,MAAA;AACT;AAUO,SAAS,eAAA,CACd,OACA,iBAAA,EAC2B;AAC3B,EAAA,IAAI,KAAA,IAAS,MAAM,OAAO,MAAA;AAE1B,EAAA,IAAI,OAAO,KAAA,KAAU,UAAA,EAAY,OAAO,KAAA;AAExC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,MAAA;AAKtC,EAAA,IAAI,qBAAqB,KAAA,EAAO;AAC9B,IAAA,MAAM,KAAK,KAAA,CAAM,aAAA;AACjB,IAAA,OAAO,OAAO,EAAA,KAAO,UAAA,GAAa,EAAA,CAAG,IAAA,CAAK,KAAK,CAAA,GAAI,MAAA;AAAA,EACrD;AAEA,EAAA,IAAI,aAAA,CAAc,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,IAAI,aAAA,CAAc,KAAA,EAAO,iBAAiB,CAAA,CAAE,aAAA;AAAA,EACrD;AAEA,EAAA,OAAO,MAAA;AACT;;;;;;;"}
|
|
@@ -17,11 +17,12 @@ var address = require('../base/address.js');
|
|
|
17
17
|
require('../base/transaction_builder.js');
|
|
18
18
|
require('../base/muxed_account.js');
|
|
19
19
|
var contract = require('../base/contract.js');
|
|
20
|
-
require('../base/scval.js');
|
|
20
|
+
var scval = require('../base/scval.js');
|
|
21
21
|
var index = require('../base/numbers/index.js');
|
|
22
22
|
var rust_result = require('./rust_result.js');
|
|
23
23
|
var utils = require('./utils.js');
|
|
24
24
|
var wasm_spec_parser = require('./wasm_spec_parser.js');
|
|
25
|
+
var event_spec = require('./event_spec.js');
|
|
25
26
|
var xdr_large_int = require('../base/numbers/xdr_large_int.js');
|
|
26
27
|
|
|
27
28
|
function enumToJsonSchema(udt) {
|
|
@@ -616,6 +617,9 @@ class Spec {
|
|
|
616
617
|
}
|
|
617
618
|
return this.nativeToScVal(val, opt.valueType());
|
|
618
619
|
}
|
|
620
|
+
if (value === curr_generated.default.ScSpecType.scSpecTypeVal().value) {
|
|
621
|
+
return scval.nativeToScVal(val);
|
|
622
|
+
}
|
|
619
623
|
switch (typeof val) {
|
|
620
624
|
case "object": {
|
|
621
625
|
if (val === null) {
|
|
@@ -706,7 +710,7 @@ class Spec {
|
|
|
706
710
|
);
|
|
707
711
|
}
|
|
708
712
|
}
|
|
709
|
-
if (val
|
|
713
|
+
if (val instanceof Map) {
|
|
710
714
|
if (value !== curr_generated.default.ScSpecType.scSpecTypeMap().value) {
|
|
711
715
|
throw new TypeError(`Type ${ty} was not map, but value was Map`);
|
|
712
716
|
}
|
|
@@ -724,7 +728,8 @@ class Spec {
|
|
|
724
728
|
}
|
|
725
729
|
return curr_generated.default.ScVal.scvMap(entries);
|
|
726
730
|
}
|
|
727
|
-
|
|
731
|
+
const proto = Object.getPrototypeOf(val);
|
|
732
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
728
733
|
throw new TypeError(
|
|
729
734
|
`cannot interpret ${val.constructor?.name} value as ScVal (${JSON.stringify(val)})`
|
|
730
735
|
);
|
|
@@ -907,6 +912,9 @@ class Spec {
|
|
|
907
912
|
if (value === curr_generated.default.ScSpecType.scSpecTypeUdt().value) {
|
|
908
913
|
return this.scValUdtToNative(scv, typeDef.udt());
|
|
909
914
|
}
|
|
915
|
+
if (value === curr_generated.default.ScSpecType.scSpecTypeVal().value) {
|
|
916
|
+
return scval.scValToNative(scv);
|
|
917
|
+
}
|
|
910
918
|
switch (scv.switch().value) {
|
|
911
919
|
case curr_generated.default.ScValType.scvVoid().value:
|
|
912
920
|
return null;
|
|
@@ -1065,6 +1073,102 @@ class Spec {
|
|
|
1065
1073
|
(entry) => entry.switch().value === curr_generated.default.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0().value
|
|
1066
1074
|
).flatMap((entry) => entry.value().cases());
|
|
1067
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Gets the SEP-48 event spec entries from the spec.
|
|
1078
|
+
*
|
|
1079
|
+
* @returns all contract events
|
|
1080
|
+
*/
|
|
1081
|
+
events() {
|
|
1082
|
+
return event_spec.events(this.entries);
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Finds the XDR event spec for the given event name.
|
|
1086
|
+
*
|
|
1087
|
+
* Unlike {@link Spec.findEntry}, a missing event is not an error: this
|
|
1088
|
+
* returns `undefined` so callers can probe a contract for an event without
|
|
1089
|
+
* wrapping the call in a `try`.
|
|
1090
|
+
*
|
|
1091
|
+
* @param name - the name of the event
|
|
1092
|
+
* @param occurrence - (optional) 0-based index among same-named events, in
|
|
1093
|
+
* declaration order, for contracts that declare the same event name
|
|
1094
|
+
* more than once (defaults to the first)
|
|
1095
|
+
* @returns the event spec, or `undefined` if the contract declares no event
|
|
1096
|
+
* with that name (at that occurrence)
|
|
1097
|
+
*
|
|
1098
|
+
* @throws if `occurrence` is not a non-negative integer
|
|
1099
|
+
*
|
|
1100
|
+
* @example
|
|
1101
|
+
* ```ts
|
|
1102
|
+
* if (contractSpec.findEvent("transfer")) {
|
|
1103
|
+
* // the contract declares a "transfer" event
|
|
1104
|
+
* }
|
|
1105
|
+
* ```
|
|
1106
|
+
*/
|
|
1107
|
+
findEvent(name, occurrence) {
|
|
1108
|
+
return event_spec.findEvent(this.entries, name, occurrence);
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Attempts to parse an emitted contract event (its topics and data) using
|
|
1112
|
+
* the event specs (SEP-48) declared in this contract's spec.
|
|
1113
|
+
*
|
|
1114
|
+
* An event's topics are `[...prefixTopics, ...topicListParamValues]` (in
|
|
1115
|
+
* that order), and its data is decoded according to the event's
|
|
1116
|
+
* `dataFormat` (`singleValue`, `vec`, or `map`).
|
|
1117
|
+
*
|
|
1118
|
+
* @param topics - the event's topics, as `xdr.ScVal[]` or base64 XDR strings
|
|
1119
|
+
* @param data - the event's data, as an `xdr.ScVal` or a base64 XDR string
|
|
1120
|
+
* @returns the parsed event (its name plus all decoded params — topic-list
|
|
1121
|
+
* and data-located alike — merged into `data`), or `undefined` if
|
|
1122
|
+
* no event spec matches (e.g. when filtering a mixed stream of
|
|
1123
|
+
* events from multiple contracts/specs)
|
|
1124
|
+
*
|
|
1125
|
+
* Note that matching compares only the prefix topics and the topic count;
|
|
1126
|
+
* if two event specs share both (in particular, events with no prefix
|
|
1127
|
+
* topics match on arity alone), the first declared spec whose values
|
|
1128
|
+
* decode successfully wins.
|
|
1129
|
+
*
|
|
1130
|
+
* @example
|
|
1131
|
+
* ```ts
|
|
1132
|
+
* const parsed = contractSpec.parseEvent(response.topic, response.value);
|
|
1133
|
+
* if (parsed) {
|
|
1134
|
+
* console.log(parsed.name, parsed.data);
|
|
1135
|
+
* }
|
|
1136
|
+
* ```
|
|
1137
|
+
*/
|
|
1138
|
+
parseEvent(topics, data) {
|
|
1139
|
+
return event_spec.parseEvent(this, this.entries, topics, data);
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Builds a `getEvents` topic filter (a single row of `Api.EventFilter.topics`)
|
|
1143
|
+
* for the named event: base64-encoded `scvSymbol`s for the event's prefix
|
|
1144
|
+
* topics, followed by one entry per topic-list param — either the
|
|
1145
|
+
* base64-encoded ScVal for a value supplied in `topicValues`, or the
|
|
1146
|
+
* wildcard `"*"`.
|
|
1147
|
+
*
|
|
1148
|
+
* @param name - the name of the event
|
|
1149
|
+
* @param topicValues - (optional) native values for topic-list params, keyed by param name
|
|
1150
|
+
* @param occurrence - (optional) 0-based index among same-named events, in
|
|
1151
|
+
* declaration order, for contracts that declare the same event name
|
|
1152
|
+
* more than once (defaults to the first)
|
|
1153
|
+
* @returns a single topic filter row
|
|
1154
|
+
*
|
|
1155
|
+
* @throws if no event with the given name (at the given occurrence) exists,
|
|
1156
|
+
* or if `occurrence` is not a non-negative integer
|
|
1157
|
+
*
|
|
1158
|
+
* @example
|
|
1159
|
+
* ```ts
|
|
1160
|
+
* const topics = contractSpec.eventTopicFilter('transfer', { to: someAddress });
|
|
1161
|
+
* ```
|
|
1162
|
+
*/
|
|
1163
|
+
eventTopicFilter(name, topicValues, occurrence) {
|
|
1164
|
+
return event_spec.eventTopicFilter(
|
|
1165
|
+
this,
|
|
1166
|
+
this.entries,
|
|
1167
|
+
name,
|
|
1168
|
+
topicValues,
|
|
1169
|
+
occurrence
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1068
1172
|
/**
|
|
1069
1173
|
* Converts the contract spec to a JSON schema.
|
|
1070
1174
|
*
|