@thruputchain/client 0.0.0-stage → 0.25.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/LICENSE +201 -0
- package/README.md +935 -2
- package/dist/actions-CdFSUTO2.js +298 -0
- package/dist/actions-CdFSUTO2.js.map +1 -0
- package/dist/actions-DxJZ3yIv.cjs +357 -0
- package/dist/actions-DxJZ3yIv.cjs.map +1 -0
- package/dist/actions.cjs +19 -0
- package/dist/actions.d.cts +4 -0
- package/dist/actions.d.ts +4 -0
- package/dist/actions.js +3 -0
- package/dist/client-BxB6ktQd.d.cts +690 -0
- package/dist/client-BxB6ktQd.d.cts.map +1 -0
- package/dist/client-BxB6ktQd.d.ts +690 -0
- package/dist/client-BxB6ktQd.d.ts.map +1 -0
- package/dist/codec-B7HJjMzI.cjs +8190 -0
- package/dist/codec-B7HJjMzI.cjs.map +1 -0
- package/dist/codec-CX-19jac.js +8130 -0
- package/dist/codec-CX-19jac.js.map +1 -0
- package/dist/contract-BpxjDMHw.js +1105 -0
- package/dist/contract-BpxjDMHw.js.map +1 -0
- package/dist/contract-D0wCFcAN.cjs +1219 -0
- package/dist/contract-D0wCFcAN.cjs.map +1 -0
- package/dist/contract.cjs +58 -0
- package/dist/contract.d.cts +3 -0
- package/dist/contract.d.ts +3 -0
- package/dist/contract.js +2 -0
- package/dist/contracts.cjs +1050 -0
- package/dist/contracts.cjs.map +1 -0
- package/dist/contracts.d.cts +397 -0
- package/dist/contracts.d.cts.map +1 -0
- package/dist/contracts.d.ts +397 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +1030 -0
- package/dist/contracts.js.map +1 -0
- package/dist/dev_wallet-BXWK5KR6.cjs +530 -0
- package/dist/dev_wallet-BXWK5KR6.cjs.map +1 -0
- package/dist/dev_wallet-C9eMQROk.js +497 -0
- package/dist/dev_wallet-C9eMQROk.js.map +1 -0
- package/dist/domainSeparator-B_vU_zUD.cjs +102 -0
- package/dist/domainSeparator-B_vU_zUD.cjs.map +1 -0
- package/dist/domainSeparator-CBCvxIj-.js +79 -0
- package/dist/domainSeparator-CBCvxIj-.js.map +1 -0
- package/dist/execution-CRDyKu45.d.ts +227 -0
- package/dist/execution-CRDyKu45.d.ts.map +1 -0
- package/dist/execution-DyxaIG4v.d.cts +227 -0
- package/dist/execution-DyxaIG4v.d.cts.map +1 -0
- package/dist/hex-DIcaALXL.js +112 -0
- package/dist/hex-DIcaALXL.js.map +1 -0
- package/dist/hex-DkGpiZ5e.cjs +189 -0
- package/dist/hex-DkGpiZ5e.cjs.map +1 -0
- package/dist/index--5LsCotr.d.ts +192 -0
- package/dist/index--5LsCotr.d.ts.map +1 -0
- package/dist/index-B5KqSHeL.d.cts +192 -0
- package/dist/index-B5KqSHeL.d.cts.map +1 -0
- package/dist/index-BZ0O5jZG.d.cts +163 -0
- package/dist/index-BZ0O5jZG.d.cts.map +1 -0
- package/dist/index-BuPQcAK2.d.ts +23 -0
- package/dist/index-BuPQcAK2.d.ts.map +1 -0
- package/dist/index-ByNNqY7S.d.cts +83 -0
- package/dist/index-ByNNqY7S.d.cts.map +1 -0
- package/dist/index-C-M-4jMR.d.cts +263 -0
- package/dist/index-C-M-4jMR.d.cts.map +1 -0
- package/dist/index-C97zw2rk.d.ts +137 -0
- package/dist/index-C97zw2rk.d.ts.map +1 -0
- package/dist/index-CIHK7Ew9.d.cts +303 -0
- package/dist/index-CIHK7Ew9.d.cts.map +1 -0
- package/dist/index-CIHK7Ew9.d.ts +303 -0
- package/dist/index-CIHK7Ew9.d.ts.map +1 -0
- package/dist/index-CXuO2Zjx.d.ts +263 -0
- package/dist/index-CXuO2Zjx.d.ts.map +1 -0
- package/dist/index-DOEBWXY2.d.cts +137 -0
- package/dist/index-DOEBWXY2.d.cts.map +1 -0
- package/dist/index-DzrLv3EA.d.cts +82 -0
- package/dist/index-DzrLv3EA.d.cts.map +1 -0
- package/dist/index-DzrLv3EA.d.ts +82 -0
- package/dist/index-DzrLv3EA.d.ts.map +1 -0
- package/dist/index-fdTURpBk.d.ts +83 -0
- package/dist/index-fdTURpBk.d.ts.map +1 -0
- package/dist/index-sAzHHayu.d.ts +163 -0
- package/dist/index-sAzHHayu.d.ts.map +1 -0
- package/dist/index-uQqRk9Ww.d.cts +23 -0
- package/dist/index-uQqRk9Ww.d.cts.map +1 -0
- package/dist/index.cjs +478 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +173 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +231 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.cjs +101 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +2 -0
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +76 -0
- package/dist/provider.js.map +1 -0
- package/dist/readError-BVbfTMLv.cjs +604 -0
- package/dist/readError-BVbfTMLv.cjs.map +1 -0
- package/dist/readError-Dn_XN98x.js +551 -0
- package/dist/readError-Dn_XN98x.js.map +1 -0
- package/dist/readViews-BKJtE5J3.d.cts +594 -0
- package/dist/readViews-BKJtE5J3.d.cts.map +1 -0
- package/dist/readViews-C_FX8wby.d.ts +594 -0
- package/dist/readViews-C_FX8wby.d.ts.map +1 -0
- package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
- package/dist/sendInvocation-2EZanZZr.cjs +661 -0
- package/dist/sendInvocation-2EZanZZr.cjs.map +1 -0
- package/dist/sendInvocation-C4ruTC-9.js +505 -0
- package/dist/sendInvocation-C4ruTC-9.js.map +1 -0
- package/dist/sign-BewmV_EL.cjs +139 -0
- package/dist/sign-BewmV_EL.cjs.map +1 -0
- package/dist/sign-DVIRyW8Y.js +122 -0
- package/dist/sign-DVIRyW8Y.js.map +1 -0
- package/dist/sign-Ve0eetRO.d.ts +48 -0
- package/dist/sign-Ve0eetRO.d.ts.map +1 -0
- package/dist/sign-eUT0iGQG.d.cts +48 -0
- package/dist/sign-eUT0iGQG.d.cts.map +1 -0
- package/dist/signed-op.cjs +9 -0
- package/dist/signed-op.d.cts +3 -0
- package/dist/signed-op.d.ts +3 -0
- package/dist/signed-op.js +3 -0
- package/dist/signedOp-Bluo0OAd.cjs +183 -0
- package/dist/signedOp-Bluo0OAd.cjs.map +1 -0
- package/dist/signedOp-x4fakrr4.js +166 -0
- package/dist/signedOp-x4fakrr4.js.map +1 -0
- package/dist/signed_op-BzVbBgv4.js +154 -0
- package/dist/signed_op-BzVbBgv4.js.map +1 -0
- package/dist/signed_op-DFgQ2yFj.d.ts +58 -0
- package/dist/signed_op-DFgQ2yFj.d.ts.map +1 -0
- package/dist/signed_op-LwxrDud8.d.cts +58 -0
- package/dist/signed_op-LwxrDud8.d.cts.map +1 -0
- package/dist/signed_op-z_8fqAi1.cjs +175 -0
- package/dist/signed_op-z_8fqAi1.cjs.map +1 -0
- package/dist/signers-BFP84wJP.cjs +137 -0
- package/dist/signers-BFP84wJP.cjs.map +1 -0
- package/dist/signers-CzOSedwJ.js +120 -0
- package/dist/signers-CzOSedwJ.js.map +1 -0
- package/dist/signers.cjs +5 -0
- package/dist/signers.d.cts +3 -0
- package/dist/signers.d.ts +3 -0
- package/dist/signers.js +2 -0
- package/dist/size-506oTE28.js +91 -0
- package/dist/size-506oTE28.js.map +1 -0
- package/dist/size-OAFfOthl.cjs +108 -0
- package/dist/size-OAFfOthl.cjs.map +1 -0
- package/dist/transaction-CwkQxQOx.js +24 -0
- package/dist/transaction-CwkQxQOx.js.map +1 -0
- package/dist/transaction-DrSrCJ5y.cjs +47 -0
- package/dist/transaction-DrSrCJ5y.cjs.map +1 -0
- package/dist/transaction.cjs +13 -0
- package/dist/transaction.d.cts +3 -0
- package/dist/transaction.d.ts +3 -0
- package/dist/transaction.js +4 -0
- package/dist/transactionHash-CO9ajbvU.js +24 -0
- package/dist/transactionHash-CO9ajbvU.js.map +1 -0
- package/dist/transactionHash-D5yf4KoL.cjs +29 -0
- package/dist/transactionHash-D5yf4KoL.cjs.map +1 -0
- package/dist/transport-B-P16rs6.cjs +252 -0
- package/dist/transport-B-P16rs6.cjs.map +1 -0
- package/dist/transport-DqyoNtUy.js +234 -0
- package/dist/transport-DqyoNtUy.js.map +1 -0
- package/dist/transport.cjs +19 -0
- package/dist/transport.d.cts +3 -0
- package/dist/transport.d.ts +3 -0
- package/dist/transport.js +4 -0
- package/dist/types-BE40oD_Q.d.cts +18 -0
- package/dist/types-BE40oD_Q.d.cts.map +1 -0
- package/dist/types-BE40oD_Q.d.ts +18 -0
- package/dist/types-BE40oD_Q.d.ts.map +1 -0
- package/dist/validation-4w-vDGAi.cjs +543 -0
- package/dist/validation-4w-vDGAi.cjs.map +1 -0
- package/dist/validation-eXATmgO0.js +411 -0
- package/dist/validation-eXATmgO0.js.map +1 -0
- package/dist/wallet-Bthapk8i.cjs +709 -0
- package/dist/wallet-Bthapk8i.cjs.map +1 -0
- package/dist/wallet-CwWPYoHF.js +667 -0
- package/dist/wallet-CwWPYoHF.js.map +1 -0
- package/dist/wallet.cjs +27 -0
- package/dist/wallet.d.cts +3 -0
- package/dist/wallet.d.ts +3 -0
- package/dist/wallet.js +3 -0
- package/package.json +122 -4
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
const require_contract = require("./contract-D0wCFcAN.cjs");
|
|
2
|
+
const require_hex = require("./hex-DkGpiZ5e.cjs");
|
|
3
|
+
const require_sendInvocation = require("./sendInvocation-2EZanZZr.cjs");
|
|
4
|
+
const require_validation = require("./validation-4w-vDGAi.cjs");
|
|
5
|
+
require("./provider.cjs");
|
|
6
|
+
let _thruputchain_protocol = require("@thruputchain/protocol");
|
|
7
|
+
let _thruputchain_xdr = require("@thruputchain/xdr");
|
|
8
|
+
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
9
|
+
let _thruputchain_protocol_utils = require("@thruputchain/protocol/utils");
|
|
10
|
+
//#region src/wallet/account.ts
|
|
11
|
+
const uint32Max = 4294967295n;
|
|
12
|
+
const uint64Max = 18446744073709551615n;
|
|
13
|
+
const sourceAddressKeyMask = (1n << _thruputchain_protocol.kMaxSigners) - 1n;
|
|
14
|
+
/** Create a protocol `kPubkeySignature` account. */
|
|
15
|
+
function createPubkeyAccount(options) {
|
|
16
|
+
validateSigner(options.signer);
|
|
17
|
+
const nonce = options.nonce ?? 0n;
|
|
18
|
+
validateUnsigned(nonce, uint64Max, "nonce");
|
|
19
|
+
const scheme = options.signer.publicKey.scheme;
|
|
20
|
+
if (scheme !== _thruputchain_protocol.CryptographicScheme.Ed25519 && scheme !== _thruputchain_protocol.CryptographicScheme.MlDsa65) throw new Error("Pubkey accounts require an Ed25519 or ML-DSA-65 signer");
|
|
21
|
+
let publicKey;
|
|
22
|
+
try {
|
|
23
|
+
publicKey = (0, _thruputchain_protocol.deserialize)((0, _thruputchain_protocol.serialize)(options.signer.publicKey, _thruputchain_protocol.codec.PublicKey), _thruputchain_protocol.codec.PublicKey);
|
|
24
|
+
} catch {
|
|
25
|
+
throw new Error("Invalid signer public key");
|
|
26
|
+
}
|
|
27
|
+
const preimage = require_validation.pubkeyAccountPreimage(publicKey, nonce);
|
|
28
|
+
return {
|
|
29
|
+
kind: "pubkey",
|
|
30
|
+
address: require_validation.derivePubkeyAccountAddress(preimage),
|
|
31
|
+
nonce,
|
|
32
|
+
publicKey,
|
|
33
|
+
authClaim: {
|
|
34
|
+
claim_type: _thruputchain_protocol.AuthClaimType.kPubkeySignature,
|
|
35
|
+
pubkey_preimage: preimage
|
|
36
|
+
},
|
|
37
|
+
signers: Object.freeze([Object.freeze({
|
|
38
|
+
signer: options.signer,
|
|
39
|
+
publicKeyId: 0n
|
|
40
|
+
})])
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Create an account using the protocol's `kSourceAddressAuthData` mode. */
|
|
44
|
+
function createSourceAddressAccount(options) {
|
|
45
|
+
if (options.address.length !== 32) throw new RangeError("address must be 32 bytes");
|
|
46
|
+
validateUnsigned(options.allowedKeys, sourceAddressKeyMask, "allowedKeys");
|
|
47
|
+
if (options.allowedKeys === 0n) throw new RangeError("allowedKeys must select at least one key");
|
|
48
|
+
validateUnsigned(options.requiredWeight, uint32Max, "requiredWeight");
|
|
49
|
+
if (options.signers.length === 0 || options.signers.length > _thruputchain_protocol.kMaxSigners) throw new RangeError(`signers must contain between 1 and ${_thruputchain_protocol.kMaxSigners} entries`);
|
|
50
|
+
const ids = /* @__PURE__ */ new Set();
|
|
51
|
+
const signers = options.signers.map((entry) => {
|
|
52
|
+
validateSigner(entry.signer);
|
|
53
|
+
validateUnsigned(entry.publicKeyId, _thruputchain_protocol.kMaxSigners - 1n, "publicKeyId");
|
|
54
|
+
if (ids.has(entry.publicKeyId)) throw new Error(`Duplicate publicKeyId: ${entry.publicKeyId}`);
|
|
55
|
+
if ((options.allowedKeys & 1n << entry.publicKeyId) === 0n) throw new Error(`publicKeyId ${entry.publicKeyId} is not selected by allowedKeys`);
|
|
56
|
+
ids.add(entry.publicKeyId);
|
|
57
|
+
return {
|
|
58
|
+
signer: entry.signer,
|
|
59
|
+
publicKeyId: entry.publicKeyId
|
|
60
|
+
};
|
|
61
|
+
}).sort((left, right) => left.publicKeyId < right.publicKeyId ? -1 : 1);
|
|
62
|
+
return {
|
|
63
|
+
kind: "sourceAddress",
|
|
64
|
+
address: (0, _thruputchain_protocol.contractAddress)(new Uint8Array(options.address)),
|
|
65
|
+
authClaim: {
|
|
66
|
+
claim_type: _thruputchain_protocol.AuthClaimType.kSourceAddressAuthData,
|
|
67
|
+
source_address_claim: {
|
|
68
|
+
allowed_keys: (0, _thruputchain_protocol.bitMap)(options.allowedKeys),
|
|
69
|
+
required_weight: (0, _thruputchain_protocol.weight)(options.requiredWeight)
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
signers: Object.freeze(signers.map((entry) => Object.freeze(entry)))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function validateSigner(signer) {
|
|
76
|
+
if (!signer || typeof signer.sign !== "function" || !signer.publicKey || typeof signer.publicKey !== "object") throw new Error("Invalid signer");
|
|
77
|
+
}
|
|
78
|
+
function validateUnsigned(value, max, name) {
|
|
79
|
+
if (typeof value !== "bigint" || value < 0n || value > max) throw new RangeError(`${name} must be between 0 and ${max}`);
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/wallet/deployment.ts
|
|
83
|
+
/** Wrap raw RV32 artifact bytes in the canonical protocol Contract. */
|
|
84
|
+
function rv32Contract(artifact) {
|
|
85
|
+
if (artifact.length === 0) throw new RangeError("RV32 artifact must not be empty");
|
|
86
|
+
return {
|
|
87
|
+
contract_type: _thruputchain_protocol.ContractType.kRv32,
|
|
88
|
+
rv32_contract: { data: new Uint8Array(artifact) }
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Hash canonical contract encoding and predict the address without creating an
|
|
93
|
+
* expiring transaction. Funding and initialization are explicit deployment options;
|
|
94
|
+
* this helper performs neither. The deployment nonce differs from the transaction
|
|
95
|
+
* nonce. Factory-created contracts remain factory calls with attached code.
|
|
96
|
+
*/
|
|
97
|
+
function prepareContractDeployment(input) {
|
|
98
|
+
const contract = input.contract instanceof Uint8Array ? rv32Contract(input.contract) : (0, _thruputchain_protocol.deserialize)((0, _thruputchain_protocol.serialize)(input.contract, _thruputchain_protocol.codec.Contract), _thruputchain_protocol.codec.Contract);
|
|
99
|
+
const deployer = (0, _thruputchain_protocol.contractAddress)(new Uint8Array(input.deployer));
|
|
100
|
+
const deploymentNonce = (0, _thruputchain_protocol.sha256Hash)(new Uint8Array((0, _thruputchain_xdr.fixedBytes)(input.deploymentNonce ?? crypto.getRandomValues(new Uint8Array(32)), 32)));
|
|
101
|
+
const contractHash = require_contract.hashContract(contract);
|
|
102
|
+
return {
|
|
103
|
+
contract,
|
|
104
|
+
deployer,
|
|
105
|
+
deploymentNonce,
|
|
106
|
+
contractHash,
|
|
107
|
+
address: require_contract.deriveContractAddress(deployer, deploymentNonce, contractHash)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Build a wallet-specific root deployment and attach its canonical code bytes. */
|
|
111
|
+
function deploymentRequest(deployment, account, options, adapter) {
|
|
112
|
+
if (!adapter.createDeploymentInvocation) throw new Error("Wallet adapter does not support deployment");
|
|
113
|
+
const snapshot = prepareContractDeployment(deployment);
|
|
114
|
+
if (!require_contract.bytesEqual(account, snapshot.deployer) || !require_contract.bytesEqual(snapshot.address, deployment.address) || !require_contract.bytesEqual(snapshot.contractHash, deployment.contractHash)) throw new Error("Deployment inputs no longer match the predicted address or wallet account");
|
|
115
|
+
return {
|
|
116
|
+
invocation: adapter.createDeploymentInvocation(account, snapshot, options),
|
|
117
|
+
contractsToDeploy: [snapshot.contract]
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Verify committed deployment evidence against the predicted address. */
|
|
121
|
+
function decodeDeployment(receipt, deployment, adapter, submission) {
|
|
122
|
+
require_sendInvocation.assertTransactionSuccess(receipt, submission);
|
|
123
|
+
try {
|
|
124
|
+
if (!adapter.decodeDeploymentReceipt) throw new Error("Wallet adapter does not support deployment decoding");
|
|
125
|
+
const address = adapter.decodeDeploymentReceipt(receipt);
|
|
126
|
+
if (!require_contract.bytesEqual(address, deployment.address)) throw new Error(`Deployment ${(0, _thruputchain_protocol_utils.toBase58)(receipt.transactionHash)} returned ${(0, _thruputchain_protocol_utils.toBase58)(address)}, expected ${(0, _thruputchain_protocol_utils.toBase58)(deployment.address)}`);
|
|
127
|
+
return address;
|
|
128
|
+
} catch (cause) {
|
|
129
|
+
throw new require_sendInvocation.ExecutionDecodeError(receipt, cause, submission);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/wallet/client.ts
|
|
134
|
+
const walletClientMarker = Symbol("ThruputWalletClient");
|
|
135
|
+
const reservedWalletClientProperties = [
|
|
136
|
+
"account",
|
|
137
|
+
"prepareTransaction",
|
|
138
|
+
"signTransaction",
|
|
139
|
+
"sendInvocation",
|
|
140
|
+
"prepareExecution",
|
|
141
|
+
"execute",
|
|
142
|
+
"executeAndWait",
|
|
143
|
+
"executeCallsAndWait",
|
|
144
|
+
"prepareDeployment",
|
|
145
|
+
"deployContract",
|
|
146
|
+
"deployContractAndWait"
|
|
147
|
+
];
|
|
148
|
+
function createWalletClient(options) {
|
|
149
|
+
const { client, account, onSigned } = options;
|
|
150
|
+
const sourceNetworkHash = options.networkHash ?? client.discovery.network.networkHash;
|
|
151
|
+
if (sourceNetworkHash.length !== 32 || sourceNetworkHash.some((v, i) => v !== client.discovery.network.networkHash[i])) throw new Error("Wallet signing network does not match endpoint discovery");
|
|
152
|
+
const signingNetworkHash = (0, _thruputchain_protocol.networkHash)((0, _thruputchain_protocol.sha256Hash)(new Uint8Array(sourceNetworkHash)));
|
|
153
|
+
if (walletClientMarker in client) throw new Error("A client can only be bound to one wallet account");
|
|
154
|
+
const collision = reservedWalletClientProperties.find((property) => property in client);
|
|
155
|
+
if (collision) throw new Error(`Client property ${collision} conflicts with a wallet client property`);
|
|
156
|
+
const getBalance = client.getBalance.bind(client);
|
|
157
|
+
const requestAirdrop = "requestAirdrop" in client ? client.requestAirdrop.bind(client) : void 0;
|
|
158
|
+
const walletActions = {
|
|
159
|
+
account,
|
|
160
|
+
getBalance: (request = {}, options) => getBalance({
|
|
161
|
+
...request,
|
|
162
|
+
address: request.address ?? account.address
|
|
163
|
+
}, options),
|
|
164
|
+
prepareTransaction: (request) => require_sendInvocation.prepareTransaction(client, account, request),
|
|
165
|
+
signTransaction: (transaction) => require_sendInvocation.signWalletTransaction(account, transaction, signingNetworkHash),
|
|
166
|
+
sendInvocation: (request) => require_sendInvocation.sendInvocation(client, account, signingNetworkHash, request, { onSigned }),
|
|
167
|
+
prepareDeployment: (deployment, options) => require_sendInvocation.prepareTransaction(client, account, deploymentRequest(deployment, account.address, options, requireDeploymentAdapter())),
|
|
168
|
+
deployContract: async (deployment, options) => {
|
|
169
|
+
const request = deploymentRequest(deployment, account.address, options, requireDeploymentAdapter());
|
|
170
|
+
const address = deployment.address.slice();
|
|
171
|
+
return {
|
|
172
|
+
transactionHash: await require_sendInvocation.sendInvocation(client, account, signingNetworkHash, request, { onSigned }),
|
|
173
|
+
address
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
deployContractAndWait: async (deployment, options, wait) => {
|
|
177
|
+
const adapter = requireDeploymentAdapter();
|
|
178
|
+
if (!adapter.decodeDeploymentReceipt) throw new Error("Wallet adapter does not support deployment decoding");
|
|
179
|
+
const address = deployment.address.slice();
|
|
180
|
+
const result = await sendAndObserve(deploymentRequest(deployment, account.address, options, adapter), wait);
|
|
181
|
+
decodeDeployment(result.receipt, {
|
|
182
|
+
...deployment,
|
|
183
|
+
address
|
|
184
|
+
}, adapter, result.submission);
|
|
185
|
+
return {
|
|
186
|
+
...result,
|
|
187
|
+
address
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const airdrop = requestAirdrop ? { requestAirdrop: (request = {}) => requestAirdrop({
|
|
192
|
+
...request,
|
|
193
|
+
recipient: request.recipient ?? account.address
|
|
194
|
+
}) } : {};
|
|
195
|
+
const invocationAdapter = options.invocationAdapter ?? (account.kind === "pubkey" ? require_sendInvocation.defaultWalletAdapter : void 0);
|
|
196
|
+
function requireDeploymentAdapter() {
|
|
197
|
+
if (!invocationAdapter) throw new Error("Wallet requires an adapter for deployment");
|
|
198
|
+
return invocationAdapter;
|
|
199
|
+
}
|
|
200
|
+
async function sendAndObserve(request, wait) {
|
|
201
|
+
wait?.signal?.throwIfAborted();
|
|
202
|
+
client.requireMethods([
|
|
203
|
+
"getChainTip",
|
|
204
|
+
"sendTransaction",
|
|
205
|
+
"getTransactionReceipt",
|
|
206
|
+
"getTransactionStatus",
|
|
207
|
+
"getNetworkInfo"
|
|
208
|
+
]);
|
|
209
|
+
const evidence = require_sendInvocation.createSubmissionEvidence((0, _thruputchain_protocol.serialize)(await require_sendInvocation.signWalletTransaction(account, await require_sendInvocation.prepareTransaction(client, account, request), signingNetworkHash), _thruputchain_protocol.codec.SignedTransaction), signingNetworkHash);
|
|
210
|
+
try {
|
|
211
|
+
await onSigned?.(evidence);
|
|
212
|
+
wait?.signal?.throwIfAborted();
|
|
213
|
+
} catch (cause) {
|
|
214
|
+
throw new require_sendInvocation.TransactionObservationError(evidence, cause, void 0, void 0, "beforeSubmission");
|
|
215
|
+
}
|
|
216
|
+
return require_sendInvocation.submitAndObserve(client, evidence, async (signal) => {
|
|
217
|
+
require_sendInvocation.assertTransactionAdmission(await client.sendTransaction({ signedTransaction: evidence.signedTransaction }, { signal }));
|
|
218
|
+
}, {
|
|
219
|
+
...wait,
|
|
220
|
+
expectedNetworkHash: signingNetworkHash
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const execution = invocationAdapter ? {
|
|
224
|
+
async executeCallsAndWait(request, wait) {
|
|
225
|
+
const calls = [...request.calls];
|
|
226
|
+
if (calls.length === 0) throw new RangeError("Execution requires at least one call");
|
|
227
|
+
const invocations = calls.map((call) => call.invocation);
|
|
228
|
+
const invocation = calls.length === 1 ? invocationAdapter.createRootInvocation(account.address, {
|
|
229
|
+
...request,
|
|
230
|
+
invocation: invocations[0]
|
|
231
|
+
}) : invocationAdapter.createBatchRootInvocation?.(account.address, {
|
|
232
|
+
...request,
|
|
233
|
+
invocations
|
|
234
|
+
});
|
|
235
|
+
if (!invocation) throw new Error("Wallet adapter does not support atomic batches");
|
|
236
|
+
const result = await sendAndObserve({
|
|
237
|
+
...request,
|
|
238
|
+
invocation
|
|
239
|
+
}, wait);
|
|
240
|
+
return {
|
|
241
|
+
...result,
|
|
242
|
+
values: require_sendInvocation.decodeExecution(result.receipt, calls, requireDeploymentAdapter(), result.submission)
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
prepareExecution: (request) => require_sendInvocation.prepareTransaction(client, account, {
|
|
246
|
+
...request,
|
|
247
|
+
invocation: invocationAdapter.createRootInvocation(account.address, request)
|
|
248
|
+
}),
|
|
249
|
+
execute: (request) => require_sendInvocation.sendInvocation(client, account, signingNetworkHash, {
|
|
250
|
+
...request,
|
|
251
|
+
invocation: invocationAdapter.createRootInvocation(account.address, request)
|
|
252
|
+
}, { onSigned }),
|
|
253
|
+
executeAndWait: async (request, wait) => {
|
|
254
|
+
const result = await sendAndObserve({
|
|
255
|
+
...request,
|
|
256
|
+
invocation: invocationAdapter.createRootInvocation(account.address, request)
|
|
257
|
+
}, wait);
|
|
258
|
+
require_sendInvocation.assertTransactionSuccess(result.receipt, result.submission);
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
} : {};
|
|
262
|
+
const wallet = Object.assign(Object.defineProperties({}, Object.getOwnPropertyDescriptors(client)), walletActions, airdrop, execution);
|
|
263
|
+
Object.defineProperty(wallet, walletClientMarker, { value: true });
|
|
264
|
+
return wallet;
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/wallet/providerClient.ts
|
|
268
|
+
/**
|
|
269
|
+
* Synchronously bind a pubkey provider account without modifying the RPC client.
|
|
270
|
+
* Does not connect or request permission: first await provider `connect` and
|
|
271
|
+
* validate its session. Snapshots account/network configuration, validates account
|
|
272
|
+
* derivation and any validated client network identity, and subscribes to changes.
|
|
273
|
+
* Supply the application's trusted expected network hash, not a value adopted from
|
|
274
|
+
* the wallet. The RPC client must be connected to and verified against that same
|
|
275
|
+
* network. Every native client carries a discovered network identity, checked here.
|
|
276
|
+
* See {@link ProviderWalletClient} for invalidation and concurrency rules.
|
|
277
|
+
* Providers own signing UI deadlines. Execution controls bound submission and
|
|
278
|
+
* observation after signing; they cannot cancel a broadcast already sent.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* Await an application-owned `onSigned` callback to durably save the signed result
|
|
282
|
+
* and its original account/network before broadcasting. If saving fails, submission
|
|
283
|
+
* is never requested.
|
|
284
|
+
* `expectedNetworkHash` comes from trusted application configuration, and `client`
|
|
285
|
+
* must already be connected to and verified against that network.
|
|
286
|
+
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* import type { CoreThruputClient } from "@thruputchain/client";
|
|
289
|
+
* import {
|
|
290
|
+
* parseWalletSession,
|
|
291
|
+
* parseWalletNetworkHash,
|
|
292
|
+
* type SignTransactionResult,
|
|
293
|
+
* type WalletAccount,
|
|
294
|
+
* type WalletProvider,
|
|
295
|
+
* } from "@thruputchain/client/provider";
|
|
296
|
+
* import {
|
|
297
|
+
* createProviderWalletClient,
|
|
298
|
+
* type PrepareExecutionRequest,
|
|
299
|
+
* } from "@thruputchain/client/wallet";
|
|
300
|
+
*
|
|
301
|
+
* async function sendWithWallet(
|
|
302
|
+
* client: CoreThruputClient,
|
|
303
|
+
* provider: WalletProvider,
|
|
304
|
+
* expectedNetworkHash: string,
|
|
305
|
+
* request: PrepareExecutionRequest,
|
|
306
|
+
* onSigned: (pending: SignTransactionResult & {
|
|
307
|
+
* account: WalletAccount;
|
|
308
|
+
* networkHash: string;
|
|
309
|
+
* }) => Promise<void>,
|
|
310
|
+
* ) {
|
|
311
|
+
* const networkHash = parseWalletNetworkHash(expectedNetworkHash);
|
|
312
|
+
* const session = parseWalletSession(await provider.request({ method: "connect" }));
|
|
313
|
+
* if (session.networkHash !== networkHash) {
|
|
314
|
+
* throw new Error("Wallet network does not match the application network");
|
|
315
|
+
* }
|
|
316
|
+
* const account = session.accounts[0];
|
|
317
|
+
* if (!account) throw new Error("No authorized account");
|
|
318
|
+
* const wallet = createProviderWalletClient({
|
|
319
|
+
* client, provider, account, networkHash,
|
|
320
|
+
* });
|
|
321
|
+
* try {
|
|
322
|
+
* const transaction = await wallet.prepareExecution(request);
|
|
323
|
+
* const signed = await wallet.signTransaction(transaction);
|
|
324
|
+
* await onSigned({ ...signed, account, networkHash });
|
|
325
|
+
* // On submit failure, recover using the saved hash and original network.
|
|
326
|
+
* return await wallet.submitTransaction(signed);
|
|
327
|
+
* } finally {
|
|
328
|
+
* wallet.dispose();
|
|
329
|
+
* }
|
|
330
|
+
* }
|
|
331
|
+
* ```
|
|
332
|
+
*
|
|
333
|
+
* @see https://docs.thruput.network/tools/wallet-integration/
|
|
334
|
+
* @see https://docs.thruput.network/tools/wallet-provider/
|
|
335
|
+
*/
|
|
336
|
+
function createProviderWalletClient(options) {
|
|
337
|
+
const { client } = options;
|
|
338
|
+
const provider = require_validation.parseWalletProvider(options.provider);
|
|
339
|
+
const account = require_validation.parseWalletAccount(options.account);
|
|
340
|
+
const networkHash = require_validation.parseWalletNetworkHash(options.networkHash);
|
|
341
|
+
if ((0, _thruputchain_protocol_utils.toBase58)(client.discovery.network.networkHash) !== networkHash) throw new require_validation.WalletProviderError(4901, "Client and provider network hashes differ");
|
|
342
|
+
if ("network" in client) {
|
|
343
|
+
const network = client.network;
|
|
344
|
+
if (!network || typeof network !== "object" || !("networkHash" in network) || !(0, _noble_hashes_utils_js.isBytes)(network.networkHash) || (0, _thruputchain_protocol_utils.toBase58)(network.networkHash) !== networkHash) throw new require_validation.WalletProviderError(4901, "Client and provider network hashes differ");
|
|
345
|
+
}
|
|
346
|
+
const preparationAccount = {
|
|
347
|
+
address: (0, _thruputchain_protocol.contractAddress)(require_hex.fixedFromBase58(account.address, 32)),
|
|
348
|
+
authClaim: {
|
|
349
|
+
claim_type: _thruputchain_protocol.AuthClaimType.kPubkeySignature,
|
|
350
|
+
pubkey_preimage: require_validation.pubkeyAccountPreimage({
|
|
351
|
+
scheme: _thruputchain_protocol.CryptographicScheme.Ed25519,
|
|
352
|
+
ed25519: (0, _thruputchain_protocol.ed25519PublicKey)(require_hex.fixedFromBase58(account.publicKey, 32))
|
|
353
|
+
}, BigInt(account.nonce))
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const providerRequest = provider.request.bind(provider);
|
|
357
|
+
const supportsCapabilities = provider.supportedMethods?.includes("getCapabilities") ?? false;
|
|
358
|
+
let invalidated = false;
|
|
359
|
+
let busy = false;
|
|
360
|
+
let sessionSnapshot;
|
|
361
|
+
let approved;
|
|
362
|
+
const invalidate = () => {
|
|
363
|
+
invalidated = true;
|
|
364
|
+
approved = void 0;
|
|
365
|
+
};
|
|
366
|
+
const unsubscribe = provider.on("change", invalidate);
|
|
367
|
+
if (typeof unsubscribe !== "function") throw new require_validation.WalletProviderError(-32603, "Provider did not return an unsubscribe function");
|
|
368
|
+
let disposed = false;
|
|
369
|
+
function assertActive() {
|
|
370
|
+
if (invalidated) throw new require_validation.WalletProviderError(4100, "Wallet session changed or adapter was disposed");
|
|
371
|
+
}
|
|
372
|
+
async function request(value, onDispatch, signal) {
|
|
373
|
+
signal?.throwIfAborted();
|
|
374
|
+
assertActive();
|
|
375
|
+
try {
|
|
376
|
+
onDispatch?.();
|
|
377
|
+
return await providerRequest(value);
|
|
378
|
+
} catch (error) {
|
|
379
|
+
let failure;
|
|
380
|
+
try {
|
|
381
|
+
failure = require_validation.parseWalletProviderError(error);
|
|
382
|
+
} catch {
|
|
383
|
+
failure = new require_validation.WalletProviderError(4900, "Wallet provider request failed");
|
|
384
|
+
}
|
|
385
|
+
if ([
|
|
386
|
+
4100,
|
|
387
|
+
4900,
|
|
388
|
+
4901
|
|
389
|
+
].includes(failure.code)) invalidate();
|
|
390
|
+
throw failure;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async function checkSession() {
|
|
394
|
+
try {
|
|
395
|
+
const value = await request({ method: "getSession" });
|
|
396
|
+
assertActive();
|
|
397
|
+
let session;
|
|
398
|
+
try {
|
|
399
|
+
session = require_validation.parseWalletSession(value);
|
|
400
|
+
} catch {
|
|
401
|
+
throw new require_validation.WalletProviderError(-32603, "Invalid provider session");
|
|
402
|
+
}
|
|
403
|
+
if (session.networkHash !== networkHash) throw new require_validation.WalletProviderError(4901, "Wallet network changed");
|
|
404
|
+
if (!session.accounts.some((entry) => entry.address === account.address && entry.publicKey === account.publicKey && entry.nonce === account.nonce)) throw new require_validation.WalletProviderError(4100, "Wallet account is not authorized");
|
|
405
|
+
const snapshot = JSON.stringify(session);
|
|
406
|
+
if (sessionSnapshot !== void 0 && sessionSnapshot !== snapshot) throw new require_validation.WalletProviderError(4100, "Wallet session changed");
|
|
407
|
+
sessionSnapshot = snapshot;
|
|
408
|
+
} catch (error) {
|
|
409
|
+
invalidate();
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
async function run(operation) {
|
|
414
|
+
assertActive();
|
|
415
|
+
if (busy) throw new require_validation.WalletProviderError(-32002, "Another wallet operation is pending");
|
|
416
|
+
busy = true;
|
|
417
|
+
try {
|
|
418
|
+
const result = await operation();
|
|
419
|
+
assertActive();
|
|
420
|
+
return result;
|
|
421
|
+
} finally {
|
|
422
|
+
busy = false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async function readCapabilities() {
|
|
426
|
+
await checkSession();
|
|
427
|
+
if (!supportsCapabilities) return Object.freeze({
|
|
428
|
+
account: account.address,
|
|
429
|
+
networkHash,
|
|
430
|
+
atomicBatch: null
|
|
431
|
+
});
|
|
432
|
+
let value;
|
|
433
|
+
try {
|
|
434
|
+
value = await request({
|
|
435
|
+
method: "getCapabilities",
|
|
436
|
+
params: {
|
|
437
|
+
account: account.address,
|
|
438
|
+
networkHash
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
} catch (error) {
|
|
442
|
+
if (!(error instanceof require_validation.WalletProviderError) || error.code !== 4200) throw error;
|
|
443
|
+
value = {
|
|
444
|
+
account: account.address,
|
|
445
|
+
networkHash,
|
|
446
|
+
atomicBatch: null
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
assertActive();
|
|
450
|
+
let capabilities;
|
|
451
|
+
try {
|
|
452
|
+
capabilities = require_validation.parseWalletCapabilities(value);
|
|
453
|
+
if (capabilities.account !== account.address || capabilities.networkHash !== networkHash) throw new Error("Capability scope mismatch");
|
|
454
|
+
} catch {
|
|
455
|
+
invalidate();
|
|
456
|
+
throw new require_validation.WalletProviderError(-32603, "Invalid provider capabilities");
|
|
457
|
+
}
|
|
458
|
+
await checkSession();
|
|
459
|
+
assertActive();
|
|
460
|
+
if (capabilities.atomicBatch) Object.freeze(capabilities.atomicBatch);
|
|
461
|
+
return Object.freeze(capabilities);
|
|
462
|
+
}
|
|
463
|
+
function submitTransaction(input, onDispatch, signal) {
|
|
464
|
+
const checkCancellation = () => {
|
|
465
|
+
if (signal?.aborted) {
|
|
466
|
+
approved = void 0;
|
|
467
|
+
signal.throwIfAborted();
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
return run(async () => {
|
|
471
|
+
checkCancellation();
|
|
472
|
+
const signed = require_validation.parseSignTransactionResult(input);
|
|
473
|
+
if (!approved || approved.signedTransaction !== signed.signedTransaction || approved.hash !== signed.hash) throw new require_validation.WalletProviderError(4100, "Signed bytes were not approved by this adapter");
|
|
474
|
+
await checkSession();
|
|
475
|
+
checkCancellation();
|
|
476
|
+
approved = void 0;
|
|
477
|
+
const value = await request({
|
|
478
|
+
method: "submitTransaction",
|
|
479
|
+
params: {
|
|
480
|
+
account: account.address,
|
|
481
|
+
networkHash,
|
|
482
|
+
signedTransaction: signed.signedTransaction
|
|
483
|
+
}
|
|
484
|
+
}, onDispatch, signal);
|
|
485
|
+
assertActive();
|
|
486
|
+
let result;
|
|
487
|
+
try {
|
|
488
|
+
result = require_validation.parseSubmitTransactionResult(value);
|
|
489
|
+
if (result.hash !== signed.hash) throw new Error("Hash mismatch");
|
|
490
|
+
} catch {
|
|
491
|
+
invalidate();
|
|
492
|
+
throw new require_validation.WalletProviderError(-32603, "Provider submission hash mismatch; broadcast may have occurred");
|
|
493
|
+
}
|
|
494
|
+
checkCancellation();
|
|
495
|
+
await checkSession();
|
|
496
|
+
return Object.freeze(result);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
const base = {
|
|
500
|
+
prepareDeployment: (deployment, options) => run(async () => {
|
|
501
|
+
const preparation = deploymentRequest(deployment, preparationAccount.address, options, require_sendInvocation.defaultWalletAdapter);
|
|
502
|
+
await checkSession();
|
|
503
|
+
const tx = await require_sendInvocation.prepareTransaction(client, preparationAccount, preparation);
|
|
504
|
+
assertActive();
|
|
505
|
+
return require_validation.parseTransactionHex(require_hex.toHex0x((0, _thruputchain_protocol.serialize)(tx, _thruputchain_protocol.codec.Transaction)));
|
|
506
|
+
}),
|
|
507
|
+
getCapabilities: () => run(readCapabilities),
|
|
508
|
+
prepareBatchExecution: (input) => run(async () => {
|
|
509
|
+
const count = input.invocations.length;
|
|
510
|
+
const preparation = {
|
|
511
|
+
...input,
|
|
512
|
+
invocation: require_sendInvocation.createDefaultWalletBatchInvocation(preparationAccount.address, input),
|
|
513
|
+
contractsToDeploy: input.contractsToDeploy?.map((contract) => (0, _thruputchain_protocol.deserialize)((0, _thruputchain_protocol.serialize)(contract, _thruputchain_protocol.codec.Contract), _thruputchain_protocol.codec.Contract))
|
|
514
|
+
};
|
|
515
|
+
const capabilities = await readCapabilities();
|
|
516
|
+
if (!capabilities.atomicBatch || count > capabilities.atomicBatch.maxCalls) throw new require_validation.WalletProviderError(4200, "Atomic batch execution is not supported for these calls");
|
|
517
|
+
const tx = await require_sendInvocation.prepareTransaction(client, preparationAccount, preparation);
|
|
518
|
+
assertActive();
|
|
519
|
+
return require_validation.parseTransactionHex(require_hex.toHex0x((0, _thruputchain_protocol.serialize)(tx, _thruputchain_protocol.codec.Transaction)));
|
|
520
|
+
}),
|
|
521
|
+
prepareExecution: (input) => run(async () => {
|
|
522
|
+
const preparation = {
|
|
523
|
+
...input,
|
|
524
|
+
invocation: require_sendInvocation.defaultWalletAdapter.createRootInvocation(preparationAccount.address, input),
|
|
525
|
+
contractsToDeploy: input.contractsToDeploy?.map((contract) => (0, _thruputchain_protocol.deserialize)((0, _thruputchain_protocol.serialize)(contract, _thruputchain_protocol.codec.Contract), _thruputchain_protocol.codec.Contract))
|
|
526
|
+
};
|
|
527
|
+
await checkSession();
|
|
528
|
+
const tx = await require_sendInvocation.prepareTransaction(client, preparationAccount, preparation);
|
|
529
|
+
assertActive();
|
|
530
|
+
return require_validation.parseTransactionHex(require_hex.toHex0x((0, _thruputchain_protocol.serialize)(tx, _thruputchain_protocol.codec.Transaction)));
|
|
531
|
+
}),
|
|
532
|
+
signTransaction: (input) => run(async () => {
|
|
533
|
+
const transaction = require_hex.toHex0x((0, _thruputchain_protocol.serialize)(input, _thruputchain_protocol.codec.Transaction));
|
|
534
|
+
require_validation.assertWalletTransaction(require_validation.parseTransactionHex(transaction), account);
|
|
535
|
+
approved = void 0;
|
|
536
|
+
await checkSession();
|
|
537
|
+
const value = await request({
|
|
538
|
+
method: "signTransaction",
|
|
539
|
+
params: {
|
|
540
|
+
account: account.address,
|
|
541
|
+
networkHash,
|
|
542
|
+
transaction
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
assertActive();
|
|
546
|
+
let signed;
|
|
547
|
+
try {
|
|
548
|
+
signed = await require_validation.verifySignTransactionResult(value, transaction, account, networkHash);
|
|
549
|
+
} catch (error) {
|
|
550
|
+
invalidate();
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
await checkSession();
|
|
554
|
+
assertActive();
|
|
555
|
+
approved = signed;
|
|
556
|
+
return signed;
|
|
557
|
+
}),
|
|
558
|
+
submitTransaction: (input) => submitTransaction(input),
|
|
559
|
+
dispose() {
|
|
560
|
+
invalidate();
|
|
561
|
+
if (!disposed) {
|
|
562
|
+
disposed = true;
|
|
563
|
+
unsubscribe();
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
let executing = false;
|
|
568
|
+
function assertIdle() {
|
|
569
|
+
if (executing) throw new require_validation.WalletProviderError(-32002, "Another wallet execution is pending");
|
|
570
|
+
}
|
|
571
|
+
async function execute(prepare, options, requireSuccess = true) {
|
|
572
|
+
assertIdle();
|
|
573
|
+
executing = true;
|
|
574
|
+
try {
|
|
575
|
+
options.wait?.signal?.throwIfAborted();
|
|
576
|
+
client.requireMethods([
|
|
577
|
+
"getChainTip",
|
|
578
|
+
"getNetworkInfo",
|
|
579
|
+
"getTransactionReceipt",
|
|
580
|
+
"getTransactionStatus"
|
|
581
|
+
]);
|
|
582
|
+
const signed = await base.signTransaction(await prepare());
|
|
583
|
+
const evidence = require_sendInvocation.createSubmissionEvidence((0, _thruputchain_protocol.serialize)(require_validation.parseSignedTransactionHex(signed.signedTransaction), _thruputchain_protocol.codec.SignedTransaction), require_hex.hashFromBase58(networkHash));
|
|
584
|
+
try {
|
|
585
|
+
await options.onSigned(Object.freeze({
|
|
586
|
+
...signed,
|
|
587
|
+
account: Object.freeze({ ...account }),
|
|
588
|
+
networkHash
|
|
589
|
+
}));
|
|
590
|
+
options.wait?.signal?.throwIfAborted();
|
|
591
|
+
} catch (cause) {
|
|
592
|
+
approved = void 0;
|
|
593
|
+
throw new require_sendInvocation.TransactionObservationError(evidence, cause, void 0, void 0, "beforeSubmission");
|
|
594
|
+
}
|
|
595
|
+
let submissionDispatched = false;
|
|
596
|
+
const result = await require_sendInvocation.submitAndObserve(client, evidence, async (signal) => {
|
|
597
|
+
await submitTransaction(signed, () => {
|
|
598
|
+
submissionDispatched = true;
|
|
599
|
+
}, signal);
|
|
600
|
+
}, {
|
|
601
|
+
...options.wait,
|
|
602
|
+
expectedNetworkHash: require_hex.hashFromBase58(networkHash)
|
|
603
|
+
}, () => submissionDispatched);
|
|
604
|
+
if (requireSuccess) require_sendInvocation.assertTransactionSuccess(result.receipt, result.submission);
|
|
605
|
+
return result;
|
|
606
|
+
} finally {
|
|
607
|
+
executing = false;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return {
|
|
611
|
+
...base,
|
|
612
|
+
prepareDeployment: async (deployment, options) => {
|
|
613
|
+
assertIdle();
|
|
614
|
+
return base.prepareDeployment(deployment, options);
|
|
615
|
+
},
|
|
616
|
+
async deployContractAndWait(deployment, options, controls) {
|
|
617
|
+
const address = deployment.address.slice();
|
|
618
|
+
const result = await execute(() => base.prepareDeployment(deployment, options), controls, false);
|
|
619
|
+
decodeDeployment(result.receipt, {
|
|
620
|
+
...deployment,
|
|
621
|
+
address
|
|
622
|
+
}, require_sendInvocation.defaultWalletAdapter, result.submission);
|
|
623
|
+
return {
|
|
624
|
+
...result,
|
|
625
|
+
address
|
|
626
|
+
};
|
|
627
|
+
},
|
|
628
|
+
getCapabilities: async () => {
|
|
629
|
+
assertIdle();
|
|
630
|
+
return base.getCapabilities();
|
|
631
|
+
},
|
|
632
|
+
prepareExecution: async (input) => {
|
|
633
|
+
assertIdle();
|
|
634
|
+
return base.prepareExecution(input);
|
|
635
|
+
},
|
|
636
|
+
prepareBatchExecution: async (input) => {
|
|
637
|
+
assertIdle();
|
|
638
|
+
return base.prepareBatchExecution(input);
|
|
639
|
+
},
|
|
640
|
+
signTransaction: async (input) => {
|
|
641
|
+
assertIdle();
|
|
642
|
+
return base.signTransaction(input);
|
|
643
|
+
},
|
|
644
|
+
submitTransaction: async (input) => {
|
|
645
|
+
assertIdle();
|
|
646
|
+
return base.submitTransaction(input);
|
|
647
|
+
},
|
|
648
|
+
executeAndWait: (input, controls) => execute(() => base.prepareExecution(input), controls),
|
|
649
|
+
async executeCallsAndWait(input, controls) {
|
|
650
|
+
const calls = [...input.calls];
|
|
651
|
+
const result = await execute(() => calls.length === 1 ? base.prepareExecution({
|
|
652
|
+
...input,
|
|
653
|
+
invocation: calls[0].invocation
|
|
654
|
+
}) : base.prepareBatchExecution({
|
|
655
|
+
...input,
|
|
656
|
+
invocations: calls.map((call) => call.invocation)
|
|
657
|
+
}), controls, false);
|
|
658
|
+
return {
|
|
659
|
+
...result,
|
|
660
|
+
values: require_sendInvocation.decodeExecution(result.receipt, calls, require_sendInvocation.defaultWalletAdapter, result.submission)
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
//#endregion
|
|
666
|
+
Object.defineProperty(exports, "createProviderWalletClient", {
|
|
667
|
+
enumerable: true,
|
|
668
|
+
get: function() {
|
|
669
|
+
return createProviderWalletClient;
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
Object.defineProperty(exports, "createPubkeyAccount", {
|
|
673
|
+
enumerable: true,
|
|
674
|
+
get: function() {
|
|
675
|
+
return createPubkeyAccount;
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
Object.defineProperty(exports, "createSourceAddressAccount", {
|
|
679
|
+
enumerable: true,
|
|
680
|
+
get: function() {
|
|
681
|
+
return createSourceAddressAccount;
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
Object.defineProperty(exports, "createWalletClient", {
|
|
685
|
+
enumerable: true,
|
|
686
|
+
get: function() {
|
|
687
|
+
return createWalletClient;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
Object.defineProperty(exports, "decodeDeployment", {
|
|
691
|
+
enumerable: true,
|
|
692
|
+
get: function() {
|
|
693
|
+
return decodeDeployment;
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
Object.defineProperty(exports, "prepareContractDeployment", {
|
|
697
|
+
enumerable: true,
|
|
698
|
+
get: function() {
|
|
699
|
+
return prepareContractDeployment;
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
Object.defineProperty(exports, "rv32Contract", {
|
|
703
|
+
enumerable: true,
|
|
704
|
+
get: function() {
|
|
705
|
+
return rv32Contract;
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
//# sourceMappingURL=wallet-Bthapk8i.cjs.map
|