@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,78 @@
|
|
|
1
|
+
import { xdr } from "../base/index.js";
|
|
2
|
+
import type { Spec } from "./spec.js";
|
|
3
|
+
/**
|
|
4
|
+
* The result of successfully matching an emitted contract event against one
|
|
5
|
+
* of the event specs (`xdr.ScSpecEventV0`) defined in a {@link Spec}.
|
|
6
|
+
*
|
|
7
|
+
* @see Spec.parseEvent
|
|
8
|
+
*/
|
|
9
|
+
export interface ParsedEvent {
|
|
10
|
+
/** The name of the matched event (the event spec's declared name). */
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* All decoded event params, keyed by param name — both the
|
|
14
|
+
* `topicList`-located params and the data-located ones. Once an event is
|
|
15
|
+
* parsed, where a param was carried (topic vs data) no longer matters;
|
|
16
|
+
* the topic list is just a way to mark which fields are indexed.
|
|
17
|
+
*/
|
|
18
|
+
data: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets all the SEP-48 event spec entries (`xdr.ScSpecEntryKind.scSpecEntryEventV0`)
|
|
22
|
+
* out of a contract's spec entries.
|
|
23
|
+
*
|
|
24
|
+
* @param entries - the contract's XDR spec entries
|
|
25
|
+
* @returns all event entries
|
|
26
|
+
* @hidden
|
|
27
|
+
*/
|
|
28
|
+
export declare function events(entries: xdr.ScSpecEntry[]): xdr.ScSpecEventV0[];
|
|
29
|
+
/**
|
|
30
|
+
* Finds the event spec with the given name among a contract's event entries.
|
|
31
|
+
* A contract may declare several events with the same name (e.g. composed
|
|
32
|
+
* modules each emitting their own `transfer`); `occurrence` selects among
|
|
33
|
+
* them, in declaration order.
|
|
34
|
+
*
|
|
35
|
+
* @param entries - the contract's XDR spec entries
|
|
36
|
+
* @param name - the name of the event to find
|
|
37
|
+
* @param occurrence - 0-based index among the events with that name
|
|
38
|
+
* @returns the event spec, or `undefined` if the contract declares no event
|
|
39
|
+
* with that name (at that occurrence)
|
|
40
|
+
* @throws if `occurrence` is not a non-negative integer
|
|
41
|
+
* @hidden
|
|
42
|
+
*/
|
|
43
|
+
export declare function findEvent(entries: xdr.ScSpecEntry[], name: string, occurrence?: number): xdr.ScSpecEventV0 | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Attempts to parse an emitted contract event (topics + data ScVals) against
|
|
46
|
+
* the event specs (SEP-48) contained in a {@link Spec}.
|
|
47
|
+
*
|
|
48
|
+
* @param spec - the Spec instance to decode values with (for `scValToNative`)
|
|
49
|
+
* @param entries - the contract's XDR spec entries
|
|
50
|
+
* @param topics - the event's topics, as `xdr.ScVal[]` or base64 XDR strings
|
|
51
|
+
* @param data - the event's data, as an `xdr.ScVal` or a base64 XDR string
|
|
52
|
+
* @returns the parsed event, or `undefined` if no event spec matches
|
|
53
|
+
*
|
|
54
|
+
* Matching compares only the prefix topics and a minimum topic count, so if
|
|
55
|
+
* two event specs share both (in particular, events with no prefix topics
|
|
56
|
+
* match on arity alone), the first declared spec whose values decode
|
|
57
|
+
* successfully wins.
|
|
58
|
+
* @hidden
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseEvent(spec: Spec, entries: xdr.ScSpecEntry[], topics: xdr.ScVal[] | string[], data: xdr.ScVal | string): ParsedEvent | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Builds a `getEvents` topic filter (a single row of `Api.EventFilter.topics`)
|
|
63
|
+
* for the named event: the event's prefix topics (base64-encoded `scvSymbol`s)
|
|
64
|
+
* followed by one entry per topic-list param — either the base64-encoded
|
|
65
|
+
* ScVal for a value supplied in `topicValues`, or the wildcard `"*"`.
|
|
66
|
+
*
|
|
67
|
+
* @param spec - the Spec instance to encode values with (for `nativeToScVal`)
|
|
68
|
+
* @param entries - the contract's XDR spec entries
|
|
69
|
+
* @param name - the name of the event
|
|
70
|
+
* @param topicValues - (optional) native values for topic-list params, keyed by param name
|
|
71
|
+
* @param occurrence - (optional) 0-based index among same-named events, for
|
|
72
|
+
* contracts that declare the same event name more than once
|
|
73
|
+
* @returns a single topic filter row
|
|
74
|
+
* @throws if no event with the given name (at the given occurrence) exists,
|
|
75
|
+
* or if `occurrence` is not a non-negative integer
|
|
76
|
+
* @hidden
|
|
77
|
+
*/
|
|
78
|
+
export declare function eventTopicFilter(spec: Spec, entries: xdr.ScSpecEntry[], name: string, topicValues?: Record<string, any>, occurrence?: number): string[];
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/int.js';
|
|
2
|
+
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/hyper.js';
|
|
3
|
+
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-int.js';
|
|
4
|
+
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-hyper.js';
|
|
5
|
+
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/xdr-type.js';
|
|
6
|
+
import 'buffer';
|
|
7
|
+
import types from '../base/generated/curr_generated.js';
|
|
8
|
+
import '@noble/hashes/sha2.js';
|
|
9
|
+
import '../base/signing.js';
|
|
10
|
+
import '../base/keypair.js';
|
|
11
|
+
import 'base32.js';
|
|
12
|
+
import '../base/util/continued_fraction.js';
|
|
13
|
+
import '../base/util/bignumber.js';
|
|
14
|
+
import '../base/transaction_builder.js';
|
|
15
|
+
import '../base/muxed_account.js';
|
|
16
|
+
import '../base/scval.js';
|
|
17
|
+
import '../base/numbers/uint128.js';
|
|
18
|
+
import '../base/numbers/uint256.js';
|
|
19
|
+
import '../base/numbers/int128.js';
|
|
20
|
+
import '../base/numbers/int256.js';
|
|
21
|
+
|
|
22
|
+
function events(entries) {
|
|
23
|
+
return entries.filter(
|
|
24
|
+
(entry) => entry.switch().value === types.ScSpecEntryKind.scSpecEntryEventV0().value
|
|
25
|
+
).map((entry) => entry.eventV0());
|
|
26
|
+
}
|
|
27
|
+
function findEvent(entries, name, occurrence = 0) {
|
|
28
|
+
if (!Number.isInteger(occurrence) || occurrence < 0) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`invalid occurrence for event ${name}: ${occurrence} (expected a non-negative integer)`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return events(entries).filter((e) => e.name().toString() === name)[occurrence];
|
|
34
|
+
}
|
|
35
|
+
function topicListParams(event) {
|
|
36
|
+
return event.params().filter(
|
|
37
|
+
(p) => p.location().value === types.ScSpecEventParamLocationV0.scSpecEventParamLocationTopicList().value
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function dataParams(event) {
|
|
41
|
+
return event.params().filter(
|
|
42
|
+
(p) => p.location().value === types.ScSpecEventParamLocationV0.scSpecEventParamLocationData().value
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function prefixTopicText(topic) {
|
|
46
|
+
switch (topic.switch().value) {
|
|
47
|
+
case types.ScValType.scvSymbol().value:
|
|
48
|
+
return topic.sym().toString();
|
|
49
|
+
case types.ScValType.scvString().value:
|
|
50
|
+
return topic.str().toString();
|
|
51
|
+
default:
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function matchesTopics(event, topics) {
|
|
56
|
+
const prefixTopics = event.prefixTopics();
|
|
57
|
+
const tlParams = topicListParams(event);
|
|
58
|
+
if (topics.length < prefixTopics.length + tlParams.length) {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i < prefixTopics.length; i++) {
|
|
62
|
+
if (prefixTopicText(topics[i]) !== prefixTopics[i].toString()) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return tlParams;
|
|
67
|
+
}
|
|
68
|
+
function parseEvent(spec, entries, topics, data) {
|
|
69
|
+
let topicVals;
|
|
70
|
+
let dataVal;
|
|
71
|
+
try {
|
|
72
|
+
topicVals = topics.map(
|
|
73
|
+
(t) => typeof t === "string" ? types.ScVal.fromXDR(t, "base64") : t
|
|
74
|
+
);
|
|
75
|
+
dataVal = typeof data === "string" ? types.ScVal.fromXDR(data, "base64") : data;
|
|
76
|
+
} catch {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
const specEvents = events(entries);
|
|
80
|
+
for (const event of specEvents) {
|
|
81
|
+
const tlParams = matchesTopics(event, topicVals);
|
|
82
|
+
if (!tlParams) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const prefixLen = event.prefixTopics().length;
|
|
87
|
+
const dataOut = /* @__PURE__ */ Object.create(null);
|
|
88
|
+
tlParams.forEach((param, i) => {
|
|
89
|
+
const val = topicVals[prefixLen + i];
|
|
90
|
+
dataOut[param.name().toString()] = spec.scValToNative(
|
|
91
|
+
val,
|
|
92
|
+
param.type()
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
const dParams = dataParams(event);
|
|
96
|
+
const format = event.dataFormat().value;
|
|
97
|
+
if (format === types.ScSpecEventDataFormat.scSpecEventDataFormatSingleValue().value) {
|
|
98
|
+
const param = dParams[0];
|
|
99
|
+
if (param) {
|
|
100
|
+
dataOut[param.name().toString()] = spec.scValToNative(
|
|
101
|
+
dataVal,
|
|
102
|
+
param.type()
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
} else if (format === types.ScSpecEventDataFormat.scSpecEventDataFormatVec().value) {
|
|
106
|
+
const vec = dataVal.vec() ?? [];
|
|
107
|
+
if (vec.length < dParams.length) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
dParams.forEach((param, i) => {
|
|
111
|
+
dataOut[param.name().toString()] = spec.scValToNative(
|
|
112
|
+
vec[i],
|
|
113
|
+
param.type()
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
} else if (format === types.ScSpecEventDataFormat.scSpecEventDataFormatMap().value) {
|
|
117
|
+
const map = dataVal.map() ?? [];
|
|
118
|
+
dParams.forEach((param) => {
|
|
119
|
+
const name = param.name().toString();
|
|
120
|
+
const entry = map.find(
|
|
121
|
+
(e) => e.key().switch().value === types.ScValType.scvSymbol().value && e.key().sym().toString() === name
|
|
122
|
+
);
|
|
123
|
+
if (entry) {
|
|
124
|
+
dataOut[name] = spec.scValToNative(entry.val(), param.type());
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
name: event.name().toString(),
|
|
130
|
+
data: dataOut
|
|
131
|
+
};
|
|
132
|
+
} catch {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return void 0;
|
|
137
|
+
}
|
|
138
|
+
function eventTopicFilter(spec, entries, name, topicValues, occurrence = 0) {
|
|
139
|
+
const event = findEvent(entries, name, occurrence);
|
|
140
|
+
if (!event) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
occurrence > 0 ? `no such event: ${name} (occurrence ${occurrence})` : `no such event: ${name}`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const filter = event.prefixTopics().map((topic) => types.ScVal.scvSymbol(topic.toString()).toXDR("base64"));
|
|
146
|
+
topicListParams(event).forEach((param) => {
|
|
147
|
+
const paramName = param.name().toString();
|
|
148
|
+
if (topicValues && Object.prototype.hasOwnProperty.call(topicValues, paramName)) {
|
|
149
|
+
const scVal = spec.nativeToScVal(topicValues[paramName], param.type());
|
|
150
|
+
filter.push(scVal.toXDR("base64"));
|
|
151
|
+
} else {
|
|
152
|
+
filter.push("*");
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return filter;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { eventTopicFilter, events, findEvent, parseEvent };
|
|
159
|
+
//# 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,SAAS,OAAO,OAAA,EAAiD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
export * from "./client.js";
|
|
4
|
+
export type { ParsedEvent } from "./event_spec.js";
|
|
4
5
|
export * from "./rust_result.js";
|
|
5
6
|
export * from "./sent_transaction.js";
|
|
7
|
+
export { KeypairSigner } from "./signer.js";
|
|
8
|
+
export type { Signer, SignTransactionLike, SignAuthEntryLike, } from "./signer.js";
|
|
6
9
|
export * from "./spec.js";
|
|
7
10
|
export * from "./types.js";
|
|
@@ -3,6 +3,7 @@ export { basicNodeSigner } from './basic_node_signer.js';
|
|
|
3
3
|
export { Client } from './client.js';
|
|
4
4
|
export { Err, Ok } from './rust_result.js';
|
|
5
5
|
export { SentTransaction, Watcher } from './sent_transaction.js';
|
|
6
|
+
export { KeypairSigner } from './signer.js';
|
|
6
7
|
export { Spec } from './spec.js';
|
|
7
8
|
export { DEFAULT_TIMEOUT, NULL_ACCOUNT } from './types.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
import { Api } from '../rpc/api.js';
|
|
2
2
|
import { RpcServer } from '../rpc/server.js';
|
|
3
|
-
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/int.js';
|
|
4
|
-
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/hyper.js';
|
|
5
|
-
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-int.js';
|
|
6
|
-
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-hyper.js';
|
|
7
|
-
import '../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/xdr-type.js';
|
|
8
|
-
import 'buffer';
|
|
9
|
-
import '../base/generated/curr_generated.js';
|
|
10
|
-
import '@noble/hashes/sha2.js';
|
|
11
|
-
import '../base/signing.js';
|
|
12
|
-
import '../base/keypair.js';
|
|
13
|
-
import 'base32.js';
|
|
14
|
-
import '../base/util/continued_fraction.js';
|
|
15
|
-
import '../base/util/bignumber.js';
|
|
16
|
-
import '../base/transaction_builder.js';
|
|
17
|
-
import '../base/muxed_account.js';
|
|
18
|
-
import '../base/scval.js';
|
|
19
|
-
import '../base/numbers/uint128.js';
|
|
20
|
-
import '../base/numbers/uint256.js';
|
|
21
|
-
import '../base/numbers/int128.js';
|
|
22
|
-
import '../base/numbers/int256.js';
|
|
23
3
|
import { withExponentialBackoff } from './utils.js';
|
|
24
4
|
import { DEFAULT_TIMEOUT } from './types.js';
|
|
25
5
|
|
|
@@ -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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,eAAA,CAAmB;AAAA,EA6B9B,YAAmB,SAAA,EAAoC;AAApC,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACjB,IAAA,MAAM,EAAE,MAAA,EAAQ,SAAA,EAAW,SAAS,MAAA,EAAO,GAAI,KAAK,SAAA,CAAU,OAAA;AAC9D,IAAA,IAAA,CAAK,MAAA,GAAS,UAAU,IAAIA,SAAA,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,EAE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"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"],"mappings":";;;;;AA2BO,MAAM,eAAA,CAAmB;AAAA,EA6B9B,YAAmB,SAAA,EAAoC;AAApC,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACjB,IAAA,MAAM,EAAE,MAAA,EAAQ,SAAA,EAAW,SAAS,MAAA,EAAO,GAAI,KAAK,SAAA,CAAU,OAAA;AAC9D,IAAA,IAAA,CAAK,MAAA,GAAS,UAAU,IAAIA,SAAA,CAAO,QAAQ,EAAE,SAAA,EAAW,SAAS,CAAA;AAAA,EACnE;AAAA,EAHmB,SAAA;AAAA,EA5BZ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AAA;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,104 @@
|
|
|
1
|
+
import { Keypair } from "../base/index.js";
|
|
2
|
+
import type { SignAuthEntry, SignTransaction } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A signing identity: something that can sign, and that knows who it is.
|
|
5
|
+
*
|
|
6
|
+
* A bare {@link SignTransaction} callback carries no identity, so callers have
|
|
7
|
+
* to pass the signer's address alongside it and keep the two in sync. A
|
|
8
|
+
* `Signer` bundles them.
|
|
9
|
+
*
|
|
10
|
+
* `address` is deliberately a plain string rather than an Ed25519 public key:
|
|
11
|
+
* it is a `G…` account address for keypair-backed signers, but may be a `C…`
|
|
12
|
+
* contract address for smart accounts, whose signatures are not Ed25519 at all.
|
|
13
|
+
*
|
|
14
|
+
* `signTransaction` and `signAuthEntry` keep the exact shapes the SDK already
|
|
15
|
+
* accepts (those of SEP-43 wallets such as Freighter), so an existing wallet
|
|
16
|
+
* object becomes a `Signer` by gaining an `address`.
|
|
17
|
+
*
|
|
18
|
+
* `signAuthEntry` is optional because not every wallet implements it; it is
|
|
19
|
+
* only needed for multi-party (non-invoker) auth entry signing.
|
|
20
|
+
*
|
|
21
|
+
* Accepted wherever the SDK takes a signing callback: the `signTransaction` and
|
|
22
|
+
* `signAuthEntry` options on `ClientOptions` and `MethodOptions`, and the
|
|
23
|
+
* per-call overrides on `AssembledTransaction`'s `sign`, `signAndSend`, and
|
|
24
|
+
* `signAuthEntries`.
|
|
25
|
+
*/
|
|
26
|
+
export interface Signer {
|
|
27
|
+
/** The address this signer signs as: `G…` for accounts, `C…` for contracts. */
|
|
28
|
+
readonly address: string;
|
|
29
|
+
/** Signs a transaction envelope. Matches `signTransaction` from Freighter. */
|
|
30
|
+
signTransaction: SignTransaction;
|
|
31
|
+
/** Signs an auth entry preimage. Matches `signAuthEntry` from Freighter. */
|
|
32
|
+
signAuthEntry?: SignAuthEntry;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A {@link Signer} backed by a local {@link Keypair}.
|
|
36
|
+
*
|
|
37
|
+
* Suitable for Node applications, scripts, and tests — anywhere the secret key
|
|
38
|
+
* lives in the same process. For browser applications, use the SEP-43 wallet's
|
|
39
|
+
* own `signTransaction`, or wrap it in an object satisfying {@link Signer}.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { Keypair } from "@stellar/stellar-sdk";
|
|
44
|
+
* import { Client, KeypairSigner } from "@stellar/stellar-sdk/contract";
|
|
45
|
+
*
|
|
46
|
+
* const keypair = Keypair.fromSecret(secret);
|
|
47
|
+
* const client = await Client.from({
|
|
48
|
+
* contractId,
|
|
49
|
+
* networkPassphrase,
|
|
50
|
+
* rpcUrl,
|
|
51
|
+
* publicKey: keypair.publicKey(),
|
|
52
|
+
* signTransaction: new KeypairSigner(keypair, networkPassphrase),
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare class KeypairSigner implements Signer {
|
|
57
|
+
private readonly keypair;
|
|
58
|
+
private readonly networkPassphrase;
|
|
59
|
+
/**
|
|
60
|
+
* The keypair's Ed25519 account address (`G…`), always `keypair.publicKey()`.
|
|
61
|
+
*/
|
|
62
|
+
readonly address: string;
|
|
63
|
+
/**
|
|
64
|
+
* @param keypair - the {@link Keypair} to sign with. Signing throws
|
|
65
|
+
* `cannot sign: no secret key available` if it holds only a public key.
|
|
66
|
+
* @param networkPassphrase - passphrase of the network to sign for, used
|
|
67
|
+
* whenever the caller does not pass one at signing time
|
|
68
|
+
*/
|
|
69
|
+
constructor(keypair: Keypair, networkPassphrase: string);
|
|
70
|
+
signTransaction: SignTransaction;
|
|
71
|
+
signAuthEntry: SignAuthEntry;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Anything accepted where a `signTransaction` callback is expected: the raw
|
|
75
|
+
* SEP-43 callback, a {@link Signer}, or a {@link Keypair}.
|
|
76
|
+
*/
|
|
77
|
+
export type SignTransactionLike = SignTransaction | Signer | Keypair;
|
|
78
|
+
/**
|
|
79
|
+
* Anything accepted where a `signAuthEntry` callback is expected: the raw
|
|
80
|
+
* SEP-43 callback, a {@link Signer}, or a {@link Keypair}.
|
|
81
|
+
*/
|
|
82
|
+
export type SignAuthEntryLike = SignAuthEntry | Signer | Keypair;
|
|
83
|
+
/**
|
|
84
|
+
* Reduces the accepted signing shapes down to a plain callback.
|
|
85
|
+
*
|
|
86
|
+
* Anything that carries no usable callback yields `undefined` — including an
|
|
87
|
+
* absent value, or an object that does not match any accepted shape — so the
|
|
88
|
+
* caller decides how to report a missing signer. This is deliberately lenient:
|
|
89
|
+
* callers reaching the SDK from plain JavaScript are not held to the types, and
|
|
90
|
+
* a clear `NoSigner` beats a `TypeError` from deep inside a normalizer.
|
|
91
|
+
*
|
|
92
|
+
* Internal: called at the entry points that read a caller-supplied signer, so
|
|
93
|
+
* the rest of the code only ever deals with a `SignTransaction`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function toSignTransaction(value: SignTransactionLike | undefined, networkPassphrase: string): SignTransaction | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Reduces the accepted signing shapes down to a plain callback.
|
|
98
|
+
*
|
|
99
|
+
* A {@link Signer} whose optional `signAuthEntry` is absent yields `undefined`,
|
|
100
|
+
* so the caller reports it the same way it reports a missing option.
|
|
101
|
+
*
|
|
102
|
+
* Internal: see {@link toSignTransaction}.
|
|
103
|
+
*/
|
|
104
|
+
export declare function toSignAuthEntry(value: SignAuthEntryLike | undefined, networkPassphrase: string): SignAuthEntry | undefined;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { TransactionBuilder } from '../base/transaction_builder.js';
|
|
3
|
+
import { hash } from '../base/hashing.js';
|
|
4
|
+
|
|
5
|
+
class KeypairSigner {
|
|
6
|
+
/**
|
|
7
|
+
* @param keypair - the {@link Keypair} to sign with. Signing throws
|
|
8
|
+
* `cannot sign: no secret key available` if it holds only a public key.
|
|
9
|
+
* @param networkPassphrase - passphrase of the network to sign for, used
|
|
10
|
+
* whenever the caller does not pass one at signing time
|
|
11
|
+
*/
|
|
12
|
+
constructor(keypair, networkPassphrase) {
|
|
13
|
+
this.keypair = keypair;
|
|
14
|
+
this.networkPassphrase = networkPassphrase;
|
|
15
|
+
this.address = keypair.publicKey();
|
|
16
|
+
}
|
|
17
|
+
keypair;
|
|
18
|
+
networkPassphrase;
|
|
19
|
+
/**
|
|
20
|
+
* The keypair's Ed25519 account address (`G…`), always `keypair.publicKey()`.
|
|
21
|
+
*/
|
|
22
|
+
address;
|
|
23
|
+
/* Arrow instance properties rather than prototype methods because
|
|
24
|
+
`basicNodeSigner` destructures them into a plain object, which would lose
|
|
25
|
+
`this` on a prototype method. (The normalizers below tolerate either, since
|
|
26
|
+
they bind what they extract.)
|
|
27
|
+
|
|
28
|
+
They stay `async` despite having nothing to await (hence the rule
|
|
29
|
+
suppressions): that way a synchronous failure — malformed XDR, or a keypair
|
|
30
|
+
holding no secret key — rejects the returned promise instead of throwing,
|
|
31
|
+
preserving the behavior `basicNodeSigner` had before it delegated here. */
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
33
|
+
signTransaction = async (xdr, opts) => {
|
|
34
|
+
const t = TransactionBuilder.fromXDR(
|
|
35
|
+
xdr,
|
|
36
|
+
opts?.networkPassphrase || this.networkPassphrase
|
|
37
|
+
);
|
|
38
|
+
t.sign(this.keypair);
|
|
39
|
+
return {
|
|
40
|
+
signedTxXdr: t.toXDR(),
|
|
41
|
+
signerAddress: this.address
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
45
|
+
signAuthEntry = async (authEntry) => {
|
|
46
|
+
const signedAuthEntry = this.keypair.sign(hash(Buffer.from(authEntry, "base64"))).toString("base64");
|
|
47
|
+
return {
|
|
48
|
+
signedAuthEntry,
|
|
49
|
+
signerAddress: this.address
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function isKeypairLike(value) {
|
|
54
|
+
return "publicKey" in value && typeof value.publicKey === "function" && "sign" in value && typeof value.sign === "function" && "signDecorated" in value && typeof value.signDecorated === "function";
|
|
55
|
+
}
|
|
56
|
+
function signerAddress(value) {
|
|
57
|
+
if (value == null || typeof value !== "object") return void 0;
|
|
58
|
+
if ("signTransaction" in value && typeof value.address === "string") {
|
|
59
|
+
return value.address;
|
|
60
|
+
}
|
|
61
|
+
return isKeypairLike(value) ? value.publicKey() : void 0;
|
|
62
|
+
}
|
|
63
|
+
function toSignTransaction(value, networkPassphrase) {
|
|
64
|
+
if (value == null) return void 0;
|
|
65
|
+
if (typeof value === "function") return value;
|
|
66
|
+
if (typeof value !== "object") return void 0;
|
|
67
|
+
if ("signTransaction" in value) {
|
|
68
|
+
const fn = value.signTransaction;
|
|
69
|
+
return typeof fn === "function" ? fn.bind(value) : void 0;
|
|
70
|
+
}
|
|
71
|
+
if (isKeypairLike(value)) {
|
|
72
|
+
return new KeypairSigner(value, networkPassphrase).signTransaction;
|
|
73
|
+
}
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
function toSignAuthEntry(value, networkPassphrase) {
|
|
77
|
+
if (value == null) return void 0;
|
|
78
|
+
if (typeof value === "function") return value;
|
|
79
|
+
if (typeof value !== "object") return void 0;
|
|
80
|
+
if ("signTransaction" in value) {
|
|
81
|
+
const fn = value.signAuthEntry;
|
|
82
|
+
return typeof fn === "function" ? fn.bind(value) : void 0;
|
|
83
|
+
}
|
|
84
|
+
if (isKeypairLike(value)) {
|
|
85
|
+
return new KeypairSigner(value, networkPassphrase).signAuthEntry;
|
|
86
|
+
}
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { KeypairSigner, signerAddress, toSignAuthEntry, toSignTransaction };
|
|
91
|
+
//# 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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