@thru/thru-sdk 0.1.29 → 0.1.30
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 +27 -0
- package/dist/{VersionInfo-BLq6Evyp.d.ts → VersionInfo-CNh_p-_y.d.ts} +110 -88
- package/dist/{chunk-QJACP7VX.js → chunk-NXEQLBXB.js} +368 -373
- package/dist/chunk-NXEQLBXB.js.map +1 -0
- package/dist/client.d.ts +3 -13
- package/dist/client.js +3 -13
- package/dist/client.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/sdk.d.ts +23 -4
- package/dist/sdk.js +18 -18
- package/dist/sdk.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-QJACP7VX.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { messageDesc, fileDesc, serviceDesc } from '@bufbuild/protobuf/codegenv2';
|
|
2
2
|
import { file_google_protobuf_timestamp, file_google_protobuf_descriptor, file_google_protobuf_duration } from '@bufbuild/protobuf/wkt';
|
|
3
|
+
import { signAsync, verifyAsync, getPublicKeyAsync } from '@noble/ed25519';
|
|
3
4
|
import { create } from '@bufbuild/protobuf';
|
|
4
|
-
import {
|
|
5
|
-
import { decodeAddress, isHexString, decodeSignature, ensureBytes, encodeAddress, hexToBytes, encodeSignature, decodeBase64 } from '@thru/helpers';
|
|
5
|
+
import { encodeAddress, decodeAddress, isHexString, hexToBytes, encodeSignature, decodeSignature, ensureBytes } from '@thru/helpers';
|
|
6
6
|
import { createClient } from '@connectrpc/connect';
|
|
7
7
|
import { createGrpcWebTransport } from '@connectrpc/connect-web';
|
|
8
8
|
import { sha256 } from '@noble/hashes/sha2';
|
|
@@ -28,6 +28,46 @@ var ConsensusStatus = /* @__PURE__ */ ((ConsensusStatus2) => {
|
|
|
28
28
|
ConsensusStatus2[ConsensusStatus2["CLUSTER_EXECUTED"] = 5] = "CLUSTER_EXECUTED";
|
|
29
29
|
return ConsensusStatus2;
|
|
30
30
|
})(ConsensusStatus || {});
|
|
31
|
+
var SignatureDomain = /* @__PURE__ */ ((SignatureDomain2) => {
|
|
32
|
+
SignatureDomain2[SignatureDomain2["TXN"] = 0] = "TXN";
|
|
33
|
+
SignatureDomain2[SignatureDomain2["BLOCK_HEADER"] = 1] = "BLOCK_HEADER";
|
|
34
|
+
SignatureDomain2[SignatureDomain2["BLOCK"] = 2] = "BLOCK";
|
|
35
|
+
SignatureDomain2[SignatureDomain2["GOSSIP"] = 3] = "GOSSIP";
|
|
36
|
+
return SignatureDomain2;
|
|
37
|
+
})(SignatureDomain || {});
|
|
38
|
+
var DOMAIN_TAGS = {
|
|
39
|
+
[0 /* TXN */]: 1n,
|
|
40
|
+
[1 /* BLOCK_HEADER */]: 2n,
|
|
41
|
+
[2 /* BLOCK */]: 3n,
|
|
42
|
+
[3 /* GOSSIP */]: 4n
|
|
43
|
+
};
|
|
44
|
+
var DOMAIN_BLOCK_SIZE = 128;
|
|
45
|
+
function createDomainBlock(domain) {
|
|
46
|
+
const block = new Uint8Array(DOMAIN_BLOCK_SIZE);
|
|
47
|
+
block.fill(0);
|
|
48
|
+
const tag = DOMAIN_TAGS[domain];
|
|
49
|
+
if (tag === void 0) {
|
|
50
|
+
throw new Error(`Invalid signature domain: ${domain}`);
|
|
51
|
+
}
|
|
52
|
+
const view = new DataView(block.buffer, block.byteOffset, block.byteLength);
|
|
53
|
+
view.setBigUint64(0, tag, false);
|
|
54
|
+
return block;
|
|
55
|
+
}
|
|
56
|
+
function prependDomainBlock(message, domain) {
|
|
57
|
+
const domainBlock = createDomainBlock(domain);
|
|
58
|
+
const result = new Uint8Array(domainBlock.length + message.length);
|
|
59
|
+
result.set(domainBlock, 0);
|
|
60
|
+
result.set(message, domainBlock.length);
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
async function signWithDomain(message, privateKey, publicKey, domain = 0 /* TXN */) {
|
|
64
|
+
const messageWithDomain = prependDomainBlock(message, domain);
|
|
65
|
+
return signAsync(messageWithDomain, privateKey);
|
|
66
|
+
}
|
|
67
|
+
async function verifyWithDomain(signature, message, publicKey, domain = 0 /* TXN */) {
|
|
68
|
+
const messageWithDomain = prependDomainBlock(message, domain);
|
|
69
|
+
return verifyAsync(signature, messageWithDomain, publicKey);
|
|
70
|
+
}
|
|
31
71
|
var file_thru_common_v1_primitives = /* @__PURE__ */ fileDesc("Ch90aHJ1L2NvbW1vbi92MS9wcmltaXRpdmVzLnByb3RvEg50aHJ1LmNvbW1vbi52MSIjCgZQdWJrZXkSGQoFdmFsdWUYASABKAxCCuBBArpIBHoCaCAiJgoJU2lnbmF0dXJlEhkKBXZhbHVlGAEgASgMQgrgQQK6SAR6AmhAIiYKCFRhUHVia2V5EhoKBXZhbHVlGAEgASgJQgvgQQK6SAVyA5gBLiIpCgtUc1NpZ25hdHVyZRIaCgV2YWx1ZRgBIAEoCUIL4EECukgFcgOYAVpCywEKEmNvbS50aHJ1LmNvbW1vbi52MUIPUHJpbWl0aXZlc1Byb3RvUAFaRGdpdGh1Yi5jb20vVW50by1MYWJzL3RocnUtbmV0L2dycGMvcGtnL3Byb3RvL3RocnUvY29tbW9uL3YxO2NvbW1vbnYxogIDVENYqgIOVGhydS5Db21tb24uVjG6AgNUSFXKAg5UaHJ1XENvbW1vblxWMeICGlRocnVcQ29tbW9uXFYxXEdQQk1ldGFkYXRh6gIQVGhydTo6Q29tbW9uOjpWMWIGcHJvdG8z", [file_buf_validate_validate, file_google_api_field_behavior]);
|
|
32
72
|
var PubkeySchema = /* @__PURE__ */ messageDesc(file_thru_common_v1_primitives, 0);
|
|
33
73
|
var SignatureSchema = /* @__PURE__ */ messageDesc(file_thru_common_v1_primitives, 1);
|
|
@@ -40,8 +80,6 @@ var BlockHashSchema = /* @__PURE__ */ messageDesc(file_thru_core_v1_types, 1);
|
|
|
40
80
|
|
|
41
81
|
// thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts
|
|
42
82
|
var file_thru_core_v1_transaction = /* @__PURE__ */ fileDesc("Ch50aHJ1L2NvcmUvdjEvdHJhbnNhY3Rpb24ucHJvdG8SDHRocnUuY29yZS52MSKgBAoRVHJhbnNhY3Rpb25IZWFkZXISOwoTZmVlX3BheWVyX3NpZ25hdHVyZRgBIAEoCzIZLnRocnUuY29tbW9uLnYxLlNpZ25hdHVyZUID4EECEhQKB3ZlcnNpb24YAiABKA1CA+BBAhISCgVmbGFncxgDIAEoDUID4EECEiUKGHJlYWR3cml0ZV9hY2NvdW50c19jb3VudBgEIAEoDUID4EECEiQKF3JlYWRvbmx5X2FjY291bnRzX2NvdW50GAUgASgNQgPgQQISIgoVaW5zdHJ1Y3Rpb25fZGF0YV9zaXplGAYgASgNQgPgQQISJAoXcmVxdWVzdGVkX2NvbXB1dGVfdW5pdHMYByABKA1CA+BBAhIiChVyZXF1ZXN0ZWRfc3RhdGVfdW5pdHMYCCABKA1CA+BBAhIjChZyZXF1ZXN0ZWRfbWVtb3J5X3VuaXRzGAkgASgNQgPgQQISGQoMZXhwaXJ5X2FmdGVyGAogASgNQgPgQQISEAoDZmVlGAsgASgEQgPgQQISEgoFbm9uY2UYDCABKARCA+BBAhIXCgpzdGFydF9zbG90GA0gASgEQgPgQQISNQoQZmVlX3BheWVyX3B1YmtleRgOIAEoCzIWLnRocnUuY29tbW9uLnYxLlB1YmtleUID4EECEjMKDnByb2dyYW1fcHVia2V5GA8gASgLMhYudGhydS5jb21tb24udjEuUHVia2V5QgPgQQIi8gMKGlRyYW5zYWN0aW9uRXhlY3V0aW9uUmVzdWx0EiMKFmNvbnN1bWVkX2NvbXB1dGVfdW5pdHMYASABKA1CA+BBAhIiChVjb25zdW1lZF9tZW1vcnlfdW5pdHMYAiABKA1CA+BBAhIhChRjb25zdW1lZF9zdGF0ZV91bml0cxgDIAEoDUID4EECEhwKD3VzZXJfZXJyb3JfY29kZRgEIAEoBEID4EECEjcKCHZtX2Vycm9yGAUgASgOMiAudGhydS5jb3JlLnYxLlRyYW5zYWN0aW9uVm1FcnJvckID4EECEh0KEGV4ZWN1dGlvbl9yZXN1bHQYBiABKARCA+BBAhIXCgpwYWdlc191c2VkGAcgASgNQgPgQQISGQoMZXZlbnRzX2NvdW50GAggASgNQgPgQQISGAoLZXZlbnRzX3NpemUYCSABKA1CA+BBAhI3ChJyZWFkd3JpdGVfYWNjb3VudHMYCiADKAsyFi50aHJ1LmNvbW1vbi52MS5QdWJrZXlCA+BBARI2ChFyZWFkb25seV9hY2NvdW50cxgLIAMoCzIWLnRocnUuY29tbW9uLnYxLlB1YmtleUID4EEBEjMKBmV2ZW50cxgMIAMoCzIeLnRocnUuY29yZS52MS5UcmFuc2FjdGlvbkV2ZW50QgPgQQEingEKEFRyYW5zYWN0aW9uRXZlbnQSFQoIZXZlbnRfaWQYASABKAlCA+BBAhIVCghjYWxsX2lkeBgCIAEoDUID4EECEhgKC3Byb2dyYW1faWR4GAMgASgNQgPgQQISLAoHcHJvZ3JhbRgEIAEoCzIWLnRocnUuY29tbW9uLnYxLlB1YmtleUID4EECEhQKB3BheWxvYWQYBSABKAxCA+BBAiLWAgoLVHJhbnNhY3Rpb24SMQoJc2lnbmF0dXJlGAEgASgLMhkudGhydS5jb21tb24udjEuU2lnbmF0dXJlQgPgQQISNAoGaGVhZGVyGAIgASgLMh8udGhydS5jb3JlLnYxLlRyYW5zYWN0aW9uSGVhZGVyQgPgQQISIAoEYm9keRgDIAEoDEIN4EEBukgHegUYgICACEgAiAEBEkwKEGV4ZWN1dGlvbl9yZXN1bHQYBCABKAsyKC50aHJ1LmNvcmUudjEuVHJhbnNhY3Rpb25FeGVjdXRpb25SZXN1bHRCA+BBAUgBiAEBEhYKBHNsb3QYBSABKARCA+BBAUgCiAEBEh4KDGJsb2NrX29mZnNldBgGIAEoDUID4EEBSAOIAQFCBwoFX2JvZHlCEwoRX2V4ZWN1dGlvbl9yZXN1bHRCBwoFX3Nsb3RCDwoNX2Jsb2NrX29mZnNldCJrCg5SYXdUcmFuc2FjdGlvbhIxCglzaWduYXR1cmUYASABKAsyGS50aHJ1LmNvbW1vbi52MS5TaWduYXR1cmVCA+BBAhImCg9yYXdfdHJhbnNhY3Rpb24YAiABKAxCDeBBArpIB3oFGICAgAgquwEKD1RyYW5zYWN0aW9uVmlldxIgChxUUkFOU0FDVElPTl9WSUVXX1VOU1BFQ0lGSUVEEAASIwofVFJBTlNBQ1RJT05fVklFV19TSUdOQVRVUkVfT05MWRABEiAKHFRSQU5TQUNUSU9OX1ZJRVdfSEVBREVSX09OTFkQAhIkCiBUUkFOU0FDVElPTl9WSUVXX0hFQURFUl9BTkRfQk9EWRADEhkKFVRSQU5TQUNUSU9OX1ZJRVdfRlVMTBAEKpgMChJUcmFuc2FjdGlvblZtRXJyb3ISIgoeVFJBTlNBQ1RJT05fVk1fRVhFQ1VURV9TVUNDRVNTEAASMAojVFJBTlNBQ1RJT05fVk1fRVJST1JfSU5WQUxJRF9GT1JNQVQQgf7/////////ARIxCiRUUkFOU0FDVElPTl9WTV9FUlJPUl9JTlZBTElEX1ZFUlNJT04Qgv7/////////ARIvCiJUUkFOU0FDVElPTl9WTV9FUlJPUl9JTlZBTElEX0ZMQUdTEIP+/////////wESMwomVFJBTlNBQ1RJT05fVk1fRVJST1JfSU5WQUxJRF9TSUdOQVRVUkUQhP7/////////ARIzCiZUUkFOU0FDVElPTl9WTV9FUlJPUl9EVVBMSUNBVEVfQUNDT1VOVBCF/v////////8BEjMKJlRSQU5TQUNUSU9OX1ZNX0VSUk9SX1VOU09SVEVEX0FDQ09VTlRTEIb+/////////wESPQowVFJBTlNBQ1RJT05fVk1fRVJST1JfVU5TT1JURURfUkVBRFdSSVRFX0FDQ09VTlRTEIf+/////////wESPAovVFJBTlNBQ1RJT05fVk1fRVJST1JfVU5TT1JURURfUkVBRE9OTFlfQUNDT1VOVFMQiP7/////////ARI+CjFUUkFOU0FDVElPTl9WTV9FUlJPUl9BQ0NPVU5UX0NPVU5UX0xJTUlUX0VYQ0VFREVEEIn+/////////wESLwoiVFJBTlNBQ1RJT05fVk1fRVJST1JfTk9OQ0VfVE9PX0xPVxCB/P////////8BEjAKI1RSQU5TQUNUSU9OX1ZNX0VSUk9SX05PTkNFX1RPT19ISUdIEIL8/////////wESQAozVFJBTlNBQ1RJT05fVk1fRVJST1JfSU5TVUZGSUNJRU5UX0ZFRV9QQVlFUl9CQUxBTkNFEIP8/////////wESQgo1VFJBTlNBQ1RJT05fVk1fRVJST1JfRkVFX1BBWUVSX0FDQ09VTlRfRE9FU19OT1RfRVhJU1QQhPz/////////ARIuCiFUUkFOU0FDVElPTl9WTV9FUlJPUl9OT1RfTElWRV9ZRVQQhfz/////////ARIpChxUUkFOU0FDVElPTl9WTV9FUlJPUl9FWFBJUkVEEIb8/////////wESPwoyVFJBTlNBQ1RJT05fVk1fRVJST1JfSU5WQUxJRF9GRUVfUEFZRVJfU1RBVEVfUFJPT0YQh/z/////////ARJECjdUUkFOU0FDVElPTl9WTV9FUlJPUl9JTlZBTElEX0ZFRV9QQVlFUl9TVEFURV9QUk9PRl9UWVBFEIj8/////////wESRAo3VFJBTlNBQ1RJT05fVk1fRVJST1JfSU5WQUxJRF9GRUVfUEFZRVJfU1RBVEVfUFJPT0ZfU0xPVBCJ/P////////8BEkEKNFRSQU5TQUNUSU9OX1ZNX0VSUk9SX0lOVkFMSURfRkVFX1BBWUVSX0FDQ09VTlRfT1dORVIQivz/////////ARJNCkBUUkFOU0FDVElPTl9WTV9FUlJPUl9JTlZBTElEX0ZFRV9QQVlFUl9TVEFURV9QUk9PRl9BQ0NPVU5UX09XTkVSEIv8/////////wESVApHVFJBTlNBQ1RJT05fVk1fRVJST1JfSU5WQUxJRF9GRUVfUEFZRVJfU1RBVEVfUFJPT0ZfQUNDT1VOVF9NRVRBX0RBVEFfU1oQjPz/////////ARIrCh5UUkFOU0FDVElPTl9WTV9FUlJPUl9WTV9GQUlMRUQQgfr/////////ARI5CixUUkFOU0FDVElPTl9WTV9FUlJPUl9JTlZBTElEX1BST0dSQU1fQUNDT1VOVBCC+v////////8BEisKHlRSQU5TQUNUSU9OX1ZNX0VSUk9SX1ZNX1JFVkVSVBCD+v////////8BEi4KIVRSQU5TQUNUSU9OX1ZNX0VSUk9SX0NVX0VYSEFVU1RFRBCE+v////////8BEi4KIVRSQU5TQUNUSU9OX1ZNX0VSUk9SX1NVX0VYSEFVU1RFRBCF+v////////8BQr8BChBjb20udGhydS5jb3JlLnYxQhBUcmFuc2FjdGlvblByb3RvUAFaQGdpdGh1Yi5jb20vVW50by1MYWJzL3RocnUtbmV0L2dycGMvcGtnL3Byb3RvL3RocnUvY29yZS92MTtjb3JldjGiAgNUQ1iqAgxUaHJ1LkNvcmUuVjG6AgRUSFVDygIMVGhydVxDb3JlXFYx4gIYVGhydVxDb3JlXFYxXEdQQk1ldGFkYXRh6gIOVGhydTo6Q29yZTo6VjFiBnByb3RvMw", [file_buf_validate_validate, file_google_api_field_behavior, file_thru_core_v1_types, file_thru_common_v1_primitives]);
|
|
43
|
-
var TransactionExecutionResultSchema = /* @__PURE__ */ messageDesc(file_thru_core_v1_transaction, 1);
|
|
44
|
-
var TransactionEventSchema = /* @__PURE__ */ messageDesc(file_thru_core_v1_transaction, 2);
|
|
45
83
|
var TransactionView = /* @__PURE__ */ ((TransactionView2) => {
|
|
46
84
|
TransactionView2[TransactionView2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
47
85
|
TransactionView2[TransactionView2["SIGNATURE_ONLY"] = 1] = "SIGNATURE_ONLY";
|
|
@@ -81,228 +119,197 @@ var TransactionVmError = /* @__PURE__ */ ((TransactionVmError2) => {
|
|
|
81
119
|
return TransactionVmError2;
|
|
82
120
|
})(TransactionVmError || {});
|
|
83
121
|
|
|
84
|
-
// thru-ts-client-sdk/
|
|
85
|
-
var SIGNATURE_SIZE = 64;
|
|
86
|
-
var PUBKEY_SIZE = 32;
|
|
87
|
-
var HASH_SIZE = 32;
|
|
88
|
-
var BLOCK_HEADER_SIZE = 160;
|
|
89
|
-
var BLOCK_FOOTER_SIZE = 136;
|
|
90
|
-
var BLOCK_VERSION_V1 = 1;
|
|
91
|
-
var TXN_HEADER_SIZE = 176;
|
|
92
|
-
var TXN_VERSION_V1 = 1;
|
|
93
|
-
var TXN_MAX_ACCOUNTS = 1024;
|
|
94
|
-
var STATE_PROOF_HEADER_SIZE = 40;
|
|
95
|
-
var ACCOUNT_META_FOOTPRINT = 64;
|
|
96
|
-
var TXN_FLAG_HAS_FEE_PAYER_PROOF = 1 << 0;
|
|
97
|
-
var STATE_PROOF_TYPE_EXISTING = 0;
|
|
98
|
-
var STATE_PROOF_TYPE_UPDATING = 1;
|
|
99
|
-
var STATE_PROOF_TYPE_CREATION = 2;
|
|
100
|
-
var PUBKEY_LENGTH = 32;
|
|
101
|
-
var SIGNATURE_LENGTH = 64;
|
|
102
|
-
var TA_ADDRESS_LENGTH = 46;
|
|
103
|
-
var TS_SIGNATURE_LENGTH = 90;
|
|
122
|
+
// thru-ts-client-sdk/domain/primitives/byte-utils.ts
|
|
104
123
|
function copyBytes(source) {
|
|
105
124
|
const bytes = new Uint8Array(source.length);
|
|
106
125
|
bytes.set(source);
|
|
107
126
|
return bytes;
|
|
108
127
|
}
|
|
109
|
-
function
|
|
110
|
-
return value.startsWith("ta") && value.length === TA_ADDRESS_LENGTH;
|
|
111
|
-
}
|
|
112
|
-
function isTsSignature(value) {
|
|
113
|
-
return value.startsWith("ts") && value.length === TS_SIGNATURE_LENGTH;
|
|
114
|
-
}
|
|
115
|
-
function ensureExactLength(bytes, expected, field) {
|
|
128
|
+
function ensureExactLength(bytes, expected) {
|
|
116
129
|
if (bytes.length !== expected) {
|
|
117
|
-
throw new Error(
|
|
130
|
+
throw new Error(`Must contain ${expected} bytes`);
|
|
118
131
|
}
|
|
119
132
|
return copyBytes(bytes);
|
|
120
133
|
}
|
|
121
|
-
function
|
|
122
|
-
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
|
|
134
|
+
function bytesEqual(a, b) {
|
|
135
|
+
if (a.length !== b.length) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
for (let i = 0; i < a.length; i++) {
|
|
139
|
+
if (a[i] !== b[i]) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
126
142
|
}
|
|
143
|
+
return true;
|
|
127
144
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
throw new Error(message);
|
|
145
|
+
function bytesToHex(bytes) {
|
|
146
|
+
const hex = new Array(bytes.length);
|
|
147
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
148
|
+
hex[i] = bytes[i].toString(16).padStart(2, "0");
|
|
133
149
|
}
|
|
150
|
+
return hex.join("");
|
|
134
151
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
152
|
+
|
|
153
|
+
// thru-ts-client-sdk/domain/primitives/constants.ts
|
|
154
|
+
var PUBKEY_LENGTH = 32;
|
|
155
|
+
var SIGNATURE_LENGTH = 64;
|
|
156
|
+
var TA_ADDRESS_LENGTH = 46;
|
|
157
|
+
var TS_SIGNATURE_LENGTH = 90;
|
|
158
|
+
|
|
159
|
+
// thru-ts-client-sdk/domain/primitives/Pubkey.ts
|
|
160
|
+
var Pubkey = class _Pubkey {
|
|
161
|
+
constructor(bytes) {
|
|
162
|
+
this.bytes = bytes;
|
|
138
163
|
}
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
return
|
|
164
|
+
static from(value) {
|
|
165
|
+
if (value instanceof _Pubkey) {
|
|
166
|
+
return value;
|
|
142
167
|
}
|
|
143
|
-
if (
|
|
144
|
-
return ensureExactLength(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
);
|
|
168
|
+
if (value instanceof Uint8Array) {
|
|
169
|
+
return new _Pubkey(ensureExactLength(value, PUBKEY_LENGTH));
|
|
170
|
+
}
|
|
171
|
+
if (typeof value === "string") {
|
|
172
|
+
return new _Pubkey(_Pubkey.bytesFromString(value));
|
|
149
173
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
PUBKEY_LENGTH,
|
|
153
|
-
field
|
|
174
|
+
throw new Error(
|
|
175
|
+
`Must be provided as Uint8Array, hex string, or ta-address`
|
|
154
176
|
);
|
|
155
177
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
function signatureBytesFromInput(value, field = "signature") {
|
|
159
|
-
if (value instanceof Uint8Array) {
|
|
160
|
-
return ensureExactLength(value, SIGNATURE_LENGTH, field);
|
|
178
|
+
static isThruFmt(value) {
|
|
179
|
+
return value.startsWith("ta") && value.length === TA_ADDRESS_LENGTH;
|
|
161
180
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
toBytes() {
|
|
182
|
+
return copyBytes(this.bytes);
|
|
183
|
+
}
|
|
184
|
+
toBytesUnsafe() {
|
|
185
|
+
return this.bytes;
|
|
186
|
+
}
|
|
187
|
+
toThruFmt() {
|
|
188
|
+
return encodeAddress(this.bytes);
|
|
189
|
+
}
|
|
190
|
+
toHex() {
|
|
191
|
+
return bytesToHex(this.bytes);
|
|
192
|
+
}
|
|
193
|
+
equals(other) {
|
|
194
|
+
const candidate = _Pubkey.from(other);
|
|
195
|
+
return bytesEqual(this.bytes, candidate.bytes);
|
|
196
|
+
}
|
|
197
|
+
toProtoPubkey() {
|
|
198
|
+
return create(PubkeySchema, { value: this.toBytes() });
|
|
199
|
+
}
|
|
200
|
+
toProtoTaPubkey() {
|
|
201
|
+
return create(TaPubkeySchema, { value: this.toThruFmt() });
|
|
202
|
+
}
|
|
203
|
+
static fromProtoPubkey(proto) {
|
|
204
|
+
if (!proto?.value) {
|
|
205
|
+
throw new Error(`Proto is missing value`);
|
|
165
206
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
);
|
|
207
|
+
return new _Pubkey(ensureExactLength(proto.value, PUBKEY_LENGTH));
|
|
208
|
+
}
|
|
209
|
+
static fromProtoTaPubkey(proto) {
|
|
210
|
+
if (!proto?.value) {
|
|
211
|
+
throw new Error(`Proto is missing value`);
|
|
172
212
|
}
|
|
173
|
-
return ensureExactLength(
|
|
174
|
-
decodeBase64String(
|
|
175
|
-
value,
|
|
176
|
-
`${field} must be provided as Uint8Array, ts-encoded string, hex string, or base64 string`
|
|
177
|
-
),
|
|
178
|
-
SIGNATURE_LENGTH,
|
|
179
|
-
field
|
|
180
|
-
);
|
|
213
|
+
return new _Pubkey(ensureExactLength(decodeAddress(proto.value), PUBKEY_LENGTH));
|
|
181
214
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (typeof value === "string") {
|
|
186
|
-
if (!isTaAddress(value)) {
|
|
187
|
-
throw new Error(`${field} must be a ta-encoded address`);
|
|
215
|
+
static bytesFromString(value) {
|
|
216
|
+
if (_Pubkey.isThruFmt(value)) {
|
|
217
|
+
return ensureExactLength(decodeAddress(value), PUBKEY_LENGTH);
|
|
188
218
|
}
|
|
189
|
-
|
|
219
|
+
if (isHexString(value)) {
|
|
220
|
+
return ensureExactLength(hexToBytes(value), PUBKEY_LENGTH);
|
|
221
|
+
}
|
|
222
|
+
throw new Error(`Must be provided as hex string or ta-address`);
|
|
190
223
|
}
|
|
191
|
-
|
|
192
|
-
|
|
224
|
+
};
|
|
225
|
+
var Signature = class _Signature {
|
|
226
|
+
constructor(bytes) {
|
|
227
|
+
this.bytes = bytes;
|
|
193
228
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (typeof value === "string") {
|
|
198
|
-
if (!isTsSignature(value)) {
|
|
199
|
-
throw new Error(`${field} must be a ts-encoded signature`);
|
|
229
|
+
static from(value) {
|
|
230
|
+
if (value instanceof _Signature) {
|
|
231
|
+
return value;
|
|
200
232
|
}
|
|
201
|
-
|
|
233
|
+
if (value instanceof Uint8Array) {
|
|
234
|
+
return new _Signature(ensureExactLength(value, SIGNATURE_LENGTH));
|
|
235
|
+
}
|
|
236
|
+
if (typeof value === "string") {
|
|
237
|
+
return new _Signature(_Signature.bytesFromString(value));
|
|
238
|
+
}
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Must be provided as Uint8Array, ts-encoded string, hex string, or base64 string`
|
|
241
|
+
);
|
|
202
242
|
}
|
|
203
|
-
|
|
204
|
-
|
|
243
|
+
static fromProto(proto) {
|
|
244
|
+
if (!proto?.value) {
|
|
245
|
+
throw new Error(`Proto is missing value`);
|
|
246
|
+
}
|
|
247
|
+
return new _Signature(ensureExactLength(proto.value, SIGNATURE_LENGTH));
|
|
205
248
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
function toPubkeyProto(value, field = "pubkey") {
|
|
209
|
-
return create(PubkeySchema, { value: pubkeyBytesFromInput(value, field) });
|
|
210
|
-
}
|
|
211
|
-
function toSignatureProto(value, field = "signature") {
|
|
212
|
-
return create(SignatureSchema, { value: signatureBytesFromInput(value, field) });
|
|
213
|
-
}
|
|
214
|
-
function toTaPubkeyProto(value, field = "taPubkey") {
|
|
215
|
-
return create(TaPubkeySchema, { value: taAddressStringFromInput(value, field) });
|
|
216
|
-
}
|
|
217
|
-
function toTsSignatureProto(value, field = "tsSignature") {
|
|
218
|
-
return create(TsSignatureSchema, { value: tsSignatureStringFromInput(value, field) });
|
|
219
|
-
}
|
|
220
|
-
function protoPubkeyToBytes(pubkey) {
|
|
221
|
-
if (!pubkey?.value || pubkey.value.length !== PUBKEY_LENGTH) {
|
|
222
|
-
return new Uint8Array(PUBKEY_LENGTH);
|
|
249
|
+
static isThruFmt(value) {
|
|
250
|
+
return value.startsWith("ts") && value.length === TS_SIGNATURE_LENGTH;
|
|
223
251
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
function protoSignatureToBytes(signature) {
|
|
227
|
-
if (!signature?.value || signature.value.length !== SIGNATURE_LENGTH) {
|
|
228
|
-
return void 0;
|
|
252
|
+
toBytes() {
|
|
253
|
+
return copyBytes(this.bytes);
|
|
229
254
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
function protoTaPubkeyToString(value) {
|
|
233
|
-
return value?.value;
|
|
234
|
-
}
|
|
235
|
-
function protoTsSignatureToString(value) {
|
|
236
|
-
return value?.value;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// thru-ts-client-sdk/domain/transactions/utils.ts
|
|
240
|
-
var ACCOUNT_LIMIT = 1024;
|
|
241
|
-
function normalizeAccountList(accounts) {
|
|
242
|
-
if (accounts.length === 0) {
|
|
243
|
-
return [];
|
|
255
|
+
toBytesUnsafe() {
|
|
256
|
+
return this.bytes;
|
|
244
257
|
}
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
toThruFmt() {
|
|
259
|
+
return encodeSignature(this.bytes);
|
|
247
260
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
function dedupeAccountList(accounts) {
|
|
252
|
-
const seen = /* @__PURE__ */ new Map();
|
|
253
|
-
for (const account of accounts) {
|
|
254
|
-
if (account.length !== 32) {
|
|
255
|
-
throw new Error("Account addresses must contain 32 bytes");
|
|
256
|
-
}
|
|
257
|
-
const key = toHex(account);
|
|
258
|
-
if (!seen.has(key)) {
|
|
259
|
-
seen.set(key, new Uint8Array(account));
|
|
260
|
-
}
|
|
261
|
+
toHex() {
|
|
262
|
+
return bytesToHex(this.bytes);
|
|
261
263
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
for (let i = 0; i < 32; i++) {
|
|
266
|
-
if (a[i] !== b[i]) {
|
|
267
|
-
return a[i] - b[i];
|
|
268
|
-
}
|
|
264
|
+
equals(other) {
|
|
265
|
+
const candidate = _Signature.from(other);
|
|
266
|
+
return bytesEqual(this.bytes, candidate.bytes);
|
|
269
267
|
}
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
function toHex(bytes) {
|
|
273
|
-
let result = "";
|
|
274
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
275
|
-
const hex = bytes[i].toString(16).padStart(2, "0");
|
|
276
|
-
result += hex;
|
|
268
|
+
toProtoSignature() {
|
|
269
|
+
return create(SignatureSchema, { value: this.toBytes() });
|
|
277
270
|
}
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
function resolveProgramIdentifier(identifier) {
|
|
281
|
-
return pubkeyBytesFromInput(identifier, "program");
|
|
282
|
-
}
|
|
283
|
-
function parseAccountIdentifier(value, field) {
|
|
284
|
-
return pubkeyBytesFromInput(value, field);
|
|
285
|
-
}
|
|
286
|
-
function parseInstructionData(value) {
|
|
287
|
-
if (value === void 0) {
|
|
288
|
-
return void 0;
|
|
271
|
+
toProtoTsSignature() {
|
|
272
|
+
return create(TsSignatureSchema, { value: this.toThruFmt() });
|
|
289
273
|
}
|
|
290
|
-
|
|
291
|
-
|
|
274
|
+
static fromProtoTsSignature(proto) {
|
|
275
|
+
if (!proto?.value) {
|
|
276
|
+
throw new Error(`Proto is missing value`);
|
|
277
|
+
}
|
|
278
|
+
return new _Signature(ensureExactLength(decodeSignature(proto.value), SIGNATURE_LENGTH));
|
|
292
279
|
}
|
|
293
|
-
|
|
294
|
-
if (value
|
|
295
|
-
|
|
280
|
+
static fromProtoSignature(proto) {
|
|
281
|
+
if (!proto?.value) {
|
|
282
|
+
throw new Error(`Proto is missing value`);
|
|
283
|
+
}
|
|
284
|
+
return new _Signature(ensureExactLength(proto.value, SIGNATURE_LENGTH));
|
|
285
|
+
}
|
|
286
|
+
static bytesFromString(value) {
|
|
287
|
+
if (_Signature.isThruFmt(value)) {
|
|
288
|
+
return ensureExactLength(decodeSignature(value), SIGNATURE_LENGTH);
|
|
296
289
|
}
|
|
297
290
|
if (isHexString(value)) {
|
|
298
|
-
return hexToBytes(value);
|
|
291
|
+
return ensureExactLength(hexToBytes(value), SIGNATURE_LENGTH);
|
|
299
292
|
}
|
|
293
|
+
throw new Error(`Must be provided as ts-encoded string or hex string`);
|
|
300
294
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// thru-ts-client-sdk/wire-format.ts
|
|
298
|
+
var SIGNATURE_SIZE = 64;
|
|
299
|
+
var PUBKEY_SIZE = 32;
|
|
300
|
+
var HASH_SIZE = 32;
|
|
301
|
+
var BLOCK_HEADER_SIZE = 160;
|
|
302
|
+
var BLOCK_FOOTER_SIZE = 136;
|
|
303
|
+
var BLOCK_VERSION_V1 = 1;
|
|
304
|
+
var TXN_HEADER_SIZE = 176;
|
|
305
|
+
var TXN_VERSION_V1 = 1;
|
|
306
|
+
var TXN_MAX_ACCOUNTS = 1024;
|
|
307
|
+
var STATE_PROOF_HEADER_SIZE = 40;
|
|
308
|
+
var ACCOUNT_META_FOOTPRINT = 64;
|
|
309
|
+
var TXN_FLAG_HAS_FEE_PAYER_PROOF = 1 << 0;
|
|
310
|
+
var STATE_PROOF_TYPE_EXISTING = 0;
|
|
311
|
+
var STATE_PROOF_TYPE_UPDATING = 1;
|
|
312
|
+
var STATE_PROOF_TYPE_CREATION = 2;
|
|
306
313
|
|
|
307
314
|
// thru-ts-client-sdk/domain/transactions/Transaction.ts
|
|
308
315
|
var DEFAULT_FLAGS = 0;
|
|
@@ -320,8 +327,8 @@ var BYTE_POPCOUNT = new Uint8Array(256).map((_value, index) => {
|
|
|
320
327
|
var Transaction = class _Transaction {
|
|
321
328
|
constructor(params) {
|
|
322
329
|
this.version = params.version ?? TXN_VERSION_V1;
|
|
323
|
-
this.feePayer =
|
|
324
|
-
this.program =
|
|
330
|
+
this.feePayer = Pubkey.from(params.feePayer);
|
|
331
|
+
this.program = Pubkey.from(params.program);
|
|
325
332
|
this.fee = params.header.fee;
|
|
326
333
|
this.nonce = params.header.nonce;
|
|
327
334
|
this.startSlot = params.header.startSlot;
|
|
@@ -330,8 +337,8 @@ var Transaction = class _Transaction {
|
|
|
330
337
|
this.requestedStateUnits = params.header.stateUnits ?? 0;
|
|
331
338
|
this.requestedMemoryUnits = params.header.memoryUnits ?? 0;
|
|
332
339
|
this.flags = params.header.flags ?? DEFAULT_FLAGS;
|
|
333
|
-
this.readWriteAccounts = params.accounts?.readWriteAccounts ? params.accounts.readWriteAccounts.map(
|
|
334
|
-
this.readOnlyAccounts = params.accounts?.readOnlyAccounts ? params.accounts.readOnlyAccounts.map(
|
|
340
|
+
this.readWriteAccounts = params.accounts?.readWriteAccounts ? params.accounts.readWriteAccounts.map(Pubkey.from) : [];
|
|
341
|
+
this.readOnlyAccounts = params.accounts?.readOnlyAccounts ? params.accounts.readOnlyAccounts.map(Pubkey.from) : [];
|
|
335
342
|
this.instructionData = params.instructionData ? new Uint8Array(params.instructionData) : void 0;
|
|
336
343
|
if (this.instructionData && this.instructionData.length > MAX_INSTRUCTION_DATA_LENGTH) {
|
|
337
344
|
throw new Error(`Instruction data exceeds maximum length (${MAX_INSTRUCTION_DATA_LENGTH} bytes)`);
|
|
@@ -438,8 +445,8 @@ var Transaction = class _Transaction {
|
|
|
438
445
|
}
|
|
439
446
|
const transaction = new _Transaction({
|
|
440
447
|
version,
|
|
441
|
-
feePayer,
|
|
442
|
-
program,
|
|
448
|
+
feePayer: Pubkey.from(feePayer),
|
|
449
|
+
program: Pubkey.from(program),
|
|
443
450
|
header: {
|
|
444
451
|
fee,
|
|
445
452
|
nonce,
|
|
@@ -462,7 +469,7 @@ var Transaction = class _Transaction {
|
|
|
462
469
|
} : void 0
|
|
463
470
|
});
|
|
464
471
|
if (hasSignature) {
|
|
465
|
-
transaction.setSignature(signatureBytes);
|
|
472
|
+
transaction.setSignature(Signature.from(signatureBytes));
|
|
466
473
|
}
|
|
467
474
|
return { transaction, size: offset };
|
|
468
475
|
}
|
|
@@ -517,8 +524,8 @@ var Transaction = class _Transaction {
|
|
|
517
524
|
}
|
|
518
525
|
transaction = new _Transaction({
|
|
519
526
|
version: header.version ?? TXN_VERSION_V1,
|
|
520
|
-
feePayer:
|
|
521
|
-
program:
|
|
527
|
+
feePayer: Pubkey.fromProtoPubkey(header.feePayerPubkey),
|
|
528
|
+
program: Pubkey.fromProtoPubkey(header.programPubkey),
|
|
522
529
|
header: {
|
|
523
530
|
fee: header.fee ?? 0n,
|
|
524
531
|
nonce: header.nonce ?? 0n,
|
|
@@ -543,7 +550,7 @@ var Transaction = class _Transaction {
|
|
|
543
550
|
}
|
|
544
551
|
const signatureBytes = proto.signature?.value ?? header.feePayerSignature?.value ?? void 0;
|
|
545
552
|
if (signatureBytes && signatureBytes.length === SIGNATURE_SIZE && hasNonZeroBytes(signatureBytes)) {
|
|
546
|
-
transaction.setSignature(signatureBytes);
|
|
553
|
+
transaction.setSignature(Signature.from(signatureBytes));
|
|
547
554
|
}
|
|
548
555
|
if (proto.executionResult) {
|
|
549
556
|
transaction.executionResult = _Transaction.executionResultFromProto(proto.executionResult);
|
|
@@ -557,25 +564,28 @@ var Transaction = class _Transaction {
|
|
|
557
564
|
return transaction;
|
|
558
565
|
}
|
|
559
566
|
getSignature() {
|
|
560
|
-
return this.signature
|
|
567
|
+
return this.signature;
|
|
561
568
|
}
|
|
562
569
|
setSignature(signature) {
|
|
563
|
-
|
|
564
|
-
throw new Error(`Signature must contain ${SIGNATURE_SIZE} bytes`);
|
|
565
|
-
}
|
|
566
|
-
this.signature = new Uint8Array(signature);
|
|
570
|
+
this.signature = signature;
|
|
567
571
|
}
|
|
568
572
|
async sign(privateKey) {
|
|
569
573
|
if (privateKey.length !== 32) {
|
|
570
574
|
throw new Error("Fee payer private key must contain 32 bytes");
|
|
571
575
|
}
|
|
572
576
|
const payload = this.toWireForSigning();
|
|
573
|
-
const
|
|
577
|
+
const publicKey = new Uint8Array(32);
|
|
578
|
+
const signature = await signWithDomain(
|
|
579
|
+
payload,
|
|
580
|
+
privateKey,
|
|
581
|
+
publicKey,
|
|
582
|
+
0 /* TXN */
|
|
583
|
+
);
|
|
574
584
|
if (signature.length !== SIGNATURE_SIZE) {
|
|
575
585
|
throw new Error("ed25519 signing produced an invalid signature");
|
|
576
586
|
}
|
|
577
|
-
this.signature = signature;
|
|
578
|
-
return
|
|
587
|
+
this.signature = Signature.from(signature);
|
|
588
|
+
return this.signature;
|
|
579
589
|
}
|
|
580
590
|
toWireForSigning() {
|
|
581
591
|
const header = this.createHeader(void 0);
|
|
@@ -583,7 +593,7 @@ var Transaction = class _Transaction {
|
|
|
583
593
|
return this.buildWirePayload(view.subarray(SIGNATURE_PREFIX_SIZE));
|
|
584
594
|
}
|
|
585
595
|
toWire() {
|
|
586
|
-
const header = this.createHeader(this.signature);
|
|
596
|
+
const header = this.createHeader(this.signature?.toBytes());
|
|
587
597
|
return this.buildWirePayload(new Uint8Array(header));
|
|
588
598
|
}
|
|
589
599
|
createHeader(signature) {
|
|
@@ -628,9 +638,9 @@ var Transaction = class _Transaction {
|
|
|
628
638
|
view.setUint32(offset, ensureUint32(this.expiryAfter), true);
|
|
629
639
|
offset += 4;
|
|
630
640
|
offset += 4;
|
|
631
|
-
headerBytes.set(this.feePayer, offset);
|
|
641
|
+
headerBytes.set(this.feePayer.toBytes(), offset);
|
|
632
642
|
offset += PUBKEY_SIZE;
|
|
633
|
-
headerBytes.set(this.program, offset);
|
|
643
|
+
headerBytes.set(this.program.toBytes(), offset);
|
|
634
644
|
return buffer;
|
|
635
645
|
}
|
|
636
646
|
buildWirePayload(headerPrefix) {
|
|
@@ -638,8 +648,8 @@ var Transaction = class _Transaction {
|
|
|
638
648
|
const result = new Uint8Array(headerPrefix.length + dynamicLength);
|
|
639
649
|
result.set(headerPrefix, 0);
|
|
640
650
|
let offset = headerPrefix.length;
|
|
641
|
-
offset = appendAccountList(result, offset, this.readWriteAccounts);
|
|
642
|
-
offset = appendAccountList(result, offset, this.readOnlyAccounts);
|
|
651
|
+
offset = appendAccountList(result, offset, this.readWriteAccounts.map((account) => account.toBytes()));
|
|
652
|
+
offset = appendAccountList(result, offset, this.readOnlyAccounts.map((account) => account.toBytes()));
|
|
643
653
|
if (this.instructionData) {
|
|
644
654
|
result.set(this.instructionData, offset);
|
|
645
655
|
offset += this.instructionData.length;
|
|
@@ -744,45 +754,17 @@ var Transaction = class _Transaction {
|
|
|
744
754
|
pagesUsed: proto.pagesUsed ?? 0,
|
|
745
755
|
eventsCount: proto.eventsCount ?? 0,
|
|
746
756
|
eventsSize: proto.eventsSize ?? 0,
|
|
747
|
-
readwriteAccounts: proto.readwriteAccounts.map((account) =>
|
|
748
|
-
readonlyAccounts: proto.readonlyAccounts.map((account) =>
|
|
757
|
+
readwriteAccounts: proto.readwriteAccounts.map((account) => Pubkey.fromProtoPubkey(account)),
|
|
758
|
+
readonlyAccounts: proto.readonlyAccounts.map((account) => Pubkey.fromProtoPubkey(account)),
|
|
749
759
|
events: proto.events.length ? proto.events.map((event) => ({
|
|
750
760
|
eventId: event.eventId,
|
|
751
761
|
callIdx: event.callIdx,
|
|
752
762
|
programIdx: event.programIdx,
|
|
753
|
-
program: event.program ?
|
|
763
|
+
program: event.program ? Pubkey.fromProtoPubkey(event.program) : void 0,
|
|
754
764
|
payload: new Uint8Array(event.payload ?? new Uint8Array(0))
|
|
755
765
|
})) : void 0
|
|
756
766
|
};
|
|
757
767
|
}
|
|
758
|
-
static convertExecutionResultToProto(result) {
|
|
759
|
-
return create(TransactionExecutionResultSchema, {
|
|
760
|
-
consumedComputeUnits: result.consumedComputeUnits,
|
|
761
|
-
consumedMemoryUnits: result.consumedMemoryUnits,
|
|
762
|
-
consumedStateUnits: result.consumedStateUnits,
|
|
763
|
-
userErrorCode: result.userErrorCode,
|
|
764
|
-
vmError: result.vmError,
|
|
765
|
-
executionResult: result.executionResult,
|
|
766
|
-
pagesUsed: result.pagesUsed,
|
|
767
|
-
eventsCount: result.eventsCount,
|
|
768
|
-
eventsSize: result.eventsSize,
|
|
769
|
-
readwriteAccounts: result.readwriteAccounts.map(
|
|
770
|
-
(account) => create(PubkeySchema, { value: new Uint8Array(account) })
|
|
771
|
-
),
|
|
772
|
-
readonlyAccounts: result.readonlyAccounts.map(
|
|
773
|
-
(account) => create(PubkeySchema, { value: new Uint8Array(account) })
|
|
774
|
-
),
|
|
775
|
-
events: result.events?.map(
|
|
776
|
-
(event) => create(TransactionEventSchema, {
|
|
777
|
-
eventId: event.eventId,
|
|
778
|
-
callIdx: event.callIdx,
|
|
779
|
-
programIdx: event.programIdx,
|
|
780
|
-
program: event.program ? create(PubkeySchema, { value: new Uint8Array(event.program) }) : void 0,
|
|
781
|
-
payload: new Uint8Array(event.payload)
|
|
782
|
-
})
|
|
783
|
-
) ?? []
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
768
|
};
|
|
787
769
|
function appendAccountList(target, start, accounts) {
|
|
788
770
|
let offset = start;
|
|
@@ -810,12 +792,6 @@ function ensureBigUint64(value) {
|
|
|
810
792
|
}
|
|
811
793
|
return value;
|
|
812
794
|
}
|
|
813
|
-
function copyKey(source) {
|
|
814
|
-
if (source.length !== PUBKEY_SIZE) {
|
|
815
|
-
throw new Error("Public keys must contain 32 bytes");
|
|
816
|
-
}
|
|
817
|
-
return new Uint8Array(source);
|
|
818
|
-
}
|
|
819
795
|
function countSetBits(bytes) {
|
|
820
796
|
let total = 0;
|
|
821
797
|
for (let i = 0; i < bytes.length; i++) {
|
|
@@ -831,19 +807,76 @@ function hasNonZeroBytes(value) {
|
|
|
831
807
|
}
|
|
832
808
|
return false;
|
|
833
809
|
}
|
|
810
|
+
var ACCOUNT_LIMIT = 1024;
|
|
811
|
+
function normalizeAccountList(accounts) {
|
|
812
|
+
if (accounts.length === 0) {
|
|
813
|
+
return [];
|
|
814
|
+
}
|
|
815
|
+
if (accounts.length > ACCOUNT_LIMIT) {
|
|
816
|
+
throw new Error(`Too many accounts provided: ${accounts.length} (max ${ACCOUNT_LIMIT})`);
|
|
817
|
+
}
|
|
818
|
+
const deduped = dedupeAccountList(accounts);
|
|
819
|
+
return deduped;
|
|
820
|
+
}
|
|
821
|
+
function dedupeAccountList(accounts) {
|
|
822
|
+
const pubkeys = accounts.map(Pubkey.from).map((pubkey) => pubkey.toBytes());
|
|
823
|
+
const seen = /* @__PURE__ */ new Map();
|
|
824
|
+
for (const pubkey of pubkeys) {
|
|
825
|
+
if (pubkey.length !== 32) {
|
|
826
|
+
throw new Error("Account addresses must contain 32 bytes");
|
|
827
|
+
}
|
|
828
|
+
const key = toHex(pubkey);
|
|
829
|
+
if (!seen.has(key)) {
|
|
830
|
+
seen.set(key, pubkey);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return Array.from(seen.values()).sort(compareAccounts);
|
|
834
|
+
}
|
|
835
|
+
function compareAccounts(a, b) {
|
|
836
|
+
for (let i = 0; i < 32; i++) {
|
|
837
|
+
if (a[i] !== b[i]) {
|
|
838
|
+
return a[i] - b[i];
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return 0;
|
|
842
|
+
}
|
|
843
|
+
function toHex(bytes) {
|
|
844
|
+
let result = "";
|
|
845
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
846
|
+
const hex = bytes[i].toString(16).padStart(2, "0");
|
|
847
|
+
result += hex;
|
|
848
|
+
}
|
|
849
|
+
return result;
|
|
850
|
+
}
|
|
851
|
+
function parseInstructionData(value) {
|
|
852
|
+
if (value === void 0) {
|
|
853
|
+
return void 0;
|
|
854
|
+
}
|
|
855
|
+
if (value instanceof Uint8Array) {
|
|
856
|
+
return new Uint8Array(value);
|
|
857
|
+
}
|
|
858
|
+
if (typeof value === "string") {
|
|
859
|
+
if (value.length === 0) {
|
|
860
|
+
return new Uint8Array();
|
|
861
|
+
}
|
|
862
|
+
if (isHexString(value)) {
|
|
863
|
+
return hexToBytes(value);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
throw new Error("Instruction data must be provided as hex string or Uint8Array");
|
|
867
|
+
}
|
|
834
868
|
|
|
835
869
|
// thru-ts-client-sdk/domain/transactions/TransactionBuilder.ts
|
|
836
870
|
var FLAG_HAS_FEE_PAYER_PROOF = 1 << 0;
|
|
837
871
|
var TransactionBuilder = class {
|
|
838
872
|
build(params) {
|
|
839
|
-
const program = resolveProgramIdentifier(params.program);
|
|
840
873
|
const accounts = this.normalizeAccounts(params.accounts);
|
|
841
874
|
const baseFlags = params.header.flags ?? 0;
|
|
842
875
|
const flags = params.proofs?.feePayerStateProof ? baseFlags | FLAG_HAS_FEE_PAYER_PROOF : baseFlags;
|
|
843
876
|
const instructionData = parseInstructionData(params.instructionData);
|
|
844
877
|
return new Transaction({
|
|
845
|
-
feePayer: params.feePayer.publicKey,
|
|
846
|
-
program,
|
|
878
|
+
feePayer: Pubkey.from(params.feePayer.publicKey),
|
|
879
|
+
program: Pubkey.from(params.program),
|
|
847
880
|
header: {
|
|
848
881
|
...params.header,
|
|
849
882
|
flags
|
|
@@ -1120,7 +1153,7 @@ var AccountMeta = class _AccountMeta {
|
|
|
1120
1153
|
this.flags = params.flags ?? new AccountFlags();
|
|
1121
1154
|
this.dataSize = params.dataSize;
|
|
1122
1155
|
this.seq = params.seq;
|
|
1123
|
-
this.owner = params.owner
|
|
1156
|
+
this.owner = params.owner;
|
|
1124
1157
|
this.balance = params.balance;
|
|
1125
1158
|
this.nonce = params.nonce;
|
|
1126
1159
|
}
|
|
@@ -1133,7 +1166,7 @@ var AccountMeta = class _AccountMeta {
|
|
|
1133
1166
|
flags: AccountFlags.fromProto(meta.flags),
|
|
1134
1167
|
dataSize: meta.dataSize,
|
|
1135
1168
|
seq: meta.seq ?? 0n,
|
|
1136
|
-
owner:
|
|
1169
|
+
owner: meta.owner ? Pubkey.fromProtoPubkey(meta.owner) : void 0,
|
|
1137
1170
|
balance: meta.balance ?? 0n,
|
|
1138
1171
|
nonce: meta.nonce
|
|
1139
1172
|
});
|
|
@@ -1158,7 +1191,7 @@ var AccountData = class _AccountData {
|
|
|
1158
1191
|
};
|
|
1159
1192
|
var Account = class _Account {
|
|
1160
1193
|
constructor(params) {
|
|
1161
|
-
this.address =
|
|
1194
|
+
this.address = params.address;
|
|
1162
1195
|
this.meta = params.meta;
|
|
1163
1196
|
this.data = params.data;
|
|
1164
1197
|
this.versionContext = params.versionContext;
|
|
@@ -1169,7 +1202,7 @@ var Account = class _Account {
|
|
|
1169
1202
|
throw new Error("Account proto missing address");
|
|
1170
1203
|
}
|
|
1171
1204
|
return new _Account({
|
|
1172
|
-
address:
|
|
1205
|
+
address: Pubkey.fromProtoPubkey(proto.address),
|
|
1173
1206
|
meta: AccountMeta.fromProto(proto.meta),
|
|
1174
1207
|
data: AccountData.fromProto(proto.data ?? void 0),
|
|
1175
1208
|
versionContext: convertVersionContext(proto.versionContext),
|
|
@@ -1186,11 +1219,6 @@ function convertVersionContext(meta) {
|
|
|
1186
1219
|
blockTimestampNs: timestampToNanoseconds(meta.blockTimestamp)
|
|
1187
1220
|
};
|
|
1188
1221
|
}
|
|
1189
|
-
function copyKey2(source) {
|
|
1190
|
-
const bytes = new Uint8Array(source.length);
|
|
1191
|
-
bytes.set(source);
|
|
1192
|
-
return bytes;
|
|
1193
|
-
}
|
|
1194
1222
|
|
|
1195
1223
|
// thru-ts-client-sdk/domain/accounts/streaming.ts
|
|
1196
1224
|
function toStreamAccountUpdate(response) {
|
|
@@ -1321,85 +1349,6 @@ function getBlockHeight(ctx) {
|
|
|
1321
1349
|
const request = create(GetHeightRequestSchema);
|
|
1322
1350
|
return ctx.query.getHeight(request, withCallOptions(ctx)).then((proto) => HeightSnapshot.fromProto(proto));
|
|
1323
1351
|
}
|
|
1324
|
-
function toSignature(value) {
|
|
1325
|
-
return toSignatureProto(value);
|
|
1326
|
-
}
|
|
1327
|
-
function toSignatureBytes(value) {
|
|
1328
|
-
return signatureBytesFromInput(value);
|
|
1329
|
-
}
|
|
1330
|
-
function toTsSignature(value, field = "tsSignature") {
|
|
1331
|
-
if (typeof value === "string" && value.startsWith("ts")) {
|
|
1332
|
-
return toTsSignatureProto(value, field);
|
|
1333
|
-
}
|
|
1334
|
-
return toTsSignatureProto(signatureBytesFromInput(value, field), field);
|
|
1335
|
-
}
|
|
1336
|
-
function toPubkey(value, field) {
|
|
1337
|
-
return toPubkeyProto(value, field);
|
|
1338
|
-
}
|
|
1339
|
-
function toPubkeyBytes(value, field) {
|
|
1340
|
-
return pubkeyBytesFromInput(value, field);
|
|
1341
|
-
}
|
|
1342
|
-
function toTaPubkey(value, field = "taPubkey") {
|
|
1343
|
-
if (typeof value === "string" && value.startsWith("ta")) {
|
|
1344
|
-
return toTaPubkeyProto(value, field);
|
|
1345
|
-
}
|
|
1346
|
-
return toTaPubkeyProto(pubkeyBytesFromInput(value, field), field);
|
|
1347
|
-
}
|
|
1348
|
-
function toBlockHash(value) {
|
|
1349
|
-
return create(BlockHashSchema, { value: ensureBytes(value, "blockHash") });
|
|
1350
|
-
}
|
|
1351
|
-
function deriveProgramAddress(options) {
|
|
1352
|
-
const programAddress = normalizeProgramAddress(options.programAddress);
|
|
1353
|
-
const seed = normalizeSeed(options.seed);
|
|
1354
|
-
const ephemeral = options.ephemeral === true;
|
|
1355
|
-
const derivationInput = new Uint8Array(programAddress.length + 1 + seed.length);
|
|
1356
|
-
derivationInput.set(programAddress, 0);
|
|
1357
|
-
derivationInput[programAddress.length] = ephemeral ? 1 : 0;
|
|
1358
|
-
derivationInput.set(seed, programAddress.length + 1);
|
|
1359
|
-
const hash = sha256(derivationInput);
|
|
1360
|
-
const derivedBytes = new Uint8Array(hash.slice(0, 32));
|
|
1361
|
-
return {
|
|
1362
|
-
bytes: derivedBytes,
|
|
1363
|
-
address: encodeAddress(derivedBytes)
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
function normalizeProgramAddress(value) {
|
|
1367
|
-
return pubkeyBytesFromInput(value, "Program address");
|
|
1368
|
-
}
|
|
1369
|
-
function normalizeSeed(value) {
|
|
1370
|
-
if (value instanceof Uint8Array) {
|
|
1371
|
-
if (value.length === 0) {
|
|
1372
|
-
throw new Error("Seed cannot be empty");
|
|
1373
|
-
}
|
|
1374
|
-
if (value.length > 32) {
|
|
1375
|
-
throw new Error("Seed cannot exceed 32 bytes");
|
|
1376
|
-
}
|
|
1377
|
-
const seed = new Uint8Array(32);
|
|
1378
|
-
seed.set(value);
|
|
1379
|
-
return seed;
|
|
1380
|
-
}
|
|
1381
|
-
if (typeof value === "string") {
|
|
1382
|
-
if (value.length === 0) {
|
|
1383
|
-
throw new Error("Seed cannot be empty");
|
|
1384
|
-
}
|
|
1385
|
-
if (isHexString(value)) {
|
|
1386
|
-
const bytes = hexToBytes(value);
|
|
1387
|
-
if (bytes.length !== 32) {
|
|
1388
|
-
throw new Error(`Hex seed must decode to 32 bytes, got ${bytes.length}`);
|
|
1389
|
-
}
|
|
1390
|
-
return bytes;
|
|
1391
|
-
}
|
|
1392
|
-
const encoder = new TextEncoder();
|
|
1393
|
-
const utf8 = encoder.encode(value);
|
|
1394
|
-
if (utf8.length > 32) {
|
|
1395
|
-
throw new Error(`UTF-8 seed too long: ${utf8.length} bytes (max 32)`);
|
|
1396
|
-
}
|
|
1397
|
-
const seed = new Uint8Array(32);
|
|
1398
|
-
seed.set(utf8);
|
|
1399
|
-
return seed;
|
|
1400
|
-
}
|
|
1401
|
-
throw new Error("Seed must be provided as Uint8Array or string");
|
|
1402
|
-
}
|
|
1403
1352
|
|
|
1404
1353
|
// thru-ts-client-sdk/domain/proofs/StateProof.ts
|
|
1405
1354
|
var StateProof = class _StateProof {
|
|
@@ -1432,7 +1381,7 @@ async function generateStateProof(ctx, options) {
|
|
|
1432
1381
|
targetSlot = height.finalized;
|
|
1433
1382
|
}
|
|
1434
1383
|
const request = create(StateProofRequestSchema, {
|
|
1435
|
-
address: options.address ?
|
|
1384
|
+
address: options.address ? Pubkey.from(options.address).toProtoPubkey() : void 0,
|
|
1436
1385
|
proofType: options.proofType,
|
|
1437
1386
|
targetSlot
|
|
1438
1387
|
});
|
|
@@ -1457,7 +1406,7 @@ __export(accounts_exports, {
|
|
|
1457
1406
|
});
|
|
1458
1407
|
function getAccount(ctx, address, options = {}) {
|
|
1459
1408
|
const request = create(GetAccountRequestSchema, {
|
|
1460
|
-
address:
|
|
1409
|
+
address: Pubkey.from(address).toProtoPubkey(),
|
|
1461
1410
|
view: options.view ?? DEFAULT_ACCOUNT_VIEW,
|
|
1462
1411
|
versionContext: options.versionContext ?? DEFAULT_VERSION_CONTEXT,
|
|
1463
1412
|
minConsensus: options.minConsensus ?? DEFAULT_MIN_CONSENSUS,
|
|
@@ -1467,7 +1416,7 @@ function getAccount(ctx, address, options = {}) {
|
|
|
1467
1416
|
}
|
|
1468
1417
|
function getRawAccount(ctx, address, options = {}) {
|
|
1469
1418
|
const request = create(GetRawAccountRequestSchema, {
|
|
1470
|
-
address:
|
|
1419
|
+
address: Pubkey.from(address).toProtoPubkey(),
|
|
1471
1420
|
view: options.view ?? DEFAULT_ACCOUNT_VIEW,
|
|
1472
1421
|
versionContext: options.versionContext ?? DEFAULT_VERSION_CONTEXT,
|
|
1473
1422
|
minConsensus: options.minConsensus ?? DEFAULT_MIN_CONSENSUS
|
|
@@ -1488,7 +1437,7 @@ function listAccounts(ctx, options) {
|
|
|
1488
1437
|
}));
|
|
1489
1438
|
}
|
|
1490
1439
|
async function createAccount(ctx, options) {
|
|
1491
|
-
const feePayer =
|
|
1440
|
+
const feePayer = Pubkey.from(options.publicKey).toBytes();
|
|
1492
1441
|
const height = await getBlockHeight(ctx);
|
|
1493
1442
|
const startSlot = height.finalized;
|
|
1494
1443
|
const proofResponse = await generateStateProof(ctx, {
|
|
@@ -1848,6 +1797,62 @@ function normalizeBytes(bytes, size) {
|
|
|
1848
1797
|
}
|
|
1849
1798
|
return bytes;
|
|
1850
1799
|
}
|
|
1800
|
+
function toBlockHash(value) {
|
|
1801
|
+
return create(BlockHashSchema, { value: ensureBytes(value, "blockHash") });
|
|
1802
|
+
}
|
|
1803
|
+
function deriveProgramAddress(options) {
|
|
1804
|
+
const programAddress = Pubkey.from(options.programAddress).toBytes();
|
|
1805
|
+
const seed = normalizeSeed(options.seed);
|
|
1806
|
+
const ephemeral = options.ephemeral === true;
|
|
1807
|
+
const derivationInput = new Uint8Array(
|
|
1808
|
+
programAddress.length + 1 + seed.length
|
|
1809
|
+
);
|
|
1810
|
+
derivationInput.set(programAddress, 0);
|
|
1811
|
+
derivationInput[programAddress.length] = ephemeral ? 1 : 0;
|
|
1812
|
+
derivationInput.set(seed, programAddress.length + 1);
|
|
1813
|
+
const hash = sha256(derivationInput);
|
|
1814
|
+
const derivedBytes = new Uint8Array(hash.slice(0, 32));
|
|
1815
|
+
return {
|
|
1816
|
+
bytes: derivedBytes,
|
|
1817
|
+
address: encodeAddress(derivedBytes)
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
function normalizeSeed(value) {
|
|
1821
|
+
if (value instanceof Uint8Array) {
|
|
1822
|
+
if (value.length === 0) {
|
|
1823
|
+
throw new Error("Seed cannot be empty");
|
|
1824
|
+
}
|
|
1825
|
+
if (value.length > 32) {
|
|
1826
|
+
throw new Error("Seed cannot exceed 32 bytes");
|
|
1827
|
+
}
|
|
1828
|
+
const seed = new Uint8Array(32);
|
|
1829
|
+
seed.set(value);
|
|
1830
|
+
return seed;
|
|
1831
|
+
}
|
|
1832
|
+
if (typeof value === "string") {
|
|
1833
|
+
if (value.length === 0) {
|
|
1834
|
+
throw new Error("Seed cannot be empty");
|
|
1835
|
+
}
|
|
1836
|
+
if (isHexString(value)) {
|
|
1837
|
+
const bytes = hexToBytes(value);
|
|
1838
|
+
if (bytes.length !== 32) {
|
|
1839
|
+
throw new Error(
|
|
1840
|
+
`Hex seed must decode to 32 bytes, got ${bytes.length}`
|
|
1841
|
+
);
|
|
1842
|
+
}
|
|
1843
|
+
return bytes;
|
|
1844
|
+
}
|
|
1845
|
+
const encoder = new TextEncoder();
|
|
1846
|
+
const utf8 = encoder.encode(value);
|
|
1847
|
+
if (utf8.length > 32) {
|
|
1848
|
+
throw new Error(`UTF-8 seed too long: ${utf8.length} bytes (max 32)`);
|
|
1849
|
+
}
|
|
1850
|
+
const seed = new Uint8Array(32);
|
|
1851
|
+
seed.set(utf8);
|
|
1852
|
+
return seed;
|
|
1853
|
+
}
|
|
1854
|
+
throw new Error("Seed must be provided as Uint8Array or string");
|
|
1855
|
+
}
|
|
1851
1856
|
|
|
1852
1857
|
// thru-ts-client-sdk/modules/blocks.ts
|
|
1853
1858
|
var blocks_exports = {};
|
|
@@ -2129,7 +2134,7 @@ function streamBlocks(ctx, options = {}) {
|
|
|
2129
2134
|
}
|
|
2130
2135
|
function streamAccountUpdates(ctx, address, options = {}) {
|
|
2131
2136
|
const request = create(StreamAccountUpdatesRequestSchema, {
|
|
2132
|
-
address:
|
|
2137
|
+
address: Pubkey.from(address).toProtoPubkey(),
|
|
2133
2138
|
view: options.view ?? DEFAULT_ACCOUNT_VIEW,
|
|
2134
2139
|
filter: options.filter?.toProto()
|
|
2135
2140
|
});
|
|
@@ -2180,7 +2185,7 @@ function streamEvents(ctx, options = {}) {
|
|
|
2180
2185
|
function trackTransaction(ctx, signature, options = {}) {
|
|
2181
2186
|
const timeoutMs = options.timeoutMs;
|
|
2182
2187
|
const request = create(TrackTransactionRequestSchema, {
|
|
2183
|
-
signature:
|
|
2188
|
+
signature: Signature.from(signature).toProtoSignature(),
|
|
2184
2189
|
timeout: timeoutMs != null ? {
|
|
2185
2190
|
seconds: BigInt(Math.floor(timeoutMs / 1e3)),
|
|
2186
2191
|
nanos: timeoutMs % 1e3 * 1e6
|
|
@@ -2253,7 +2258,7 @@ __export(transactions_exports, {
|
|
|
2253
2258
|
});
|
|
2254
2259
|
async function getTransaction(ctx, signature, options = {}) {
|
|
2255
2260
|
const request = create(GetTransactionRequestSchema, {
|
|
2256
|
-
signature:
|
|
2261
|
+
signature: Signature.from(signature).toProtoSignature(),
|
|
2257
2262
|
view: options.view ?? DEFAULT_TRANSACTION_VIEW,
|
|
2258
2263
|
versionContext: options.versionContext ?? DEFAULT_VERSION_CONTEXT,
|
|
2259
2264
|
minConsensus: options.minConsensus ?? DEFAULT_MIN_CONSENSUS
|
|
@@ -2263,7 +2268,7 @@ async function getTransaction(ctx, signature, options = {}) {
|
|
|
2263
2268
|
}
|
|
2264
2269
|
async function getRawTransaction(ctx, signature, options = {}) {
|
|
2265
2270
|
const request = create(GetRawTransactionRequestSchema, {
|
|
2266
|
-
signature:
|
|
2271
|
+
signature: Signature.from(signature).toProtoSignature(),
|
|
2267
2272
|
versionContext: options.versionContext ?? DEFAULT_VERSION_CONTEXT,
|
|
2268
2273
|
minConsensus: options.minConsensus ?? DEFAULT_MIN_CONSENSUS
|
|
2269
2274
|
});
|
|
@@ -2271,14 +2276,14 @@ async function getRawTransaction(ctx, signature, options = {}) {
|
|
|
2271
2276
|
}
|
|
2272
2277
|
async function getTransactionStatus(ctx, signature) {
|
|
2273
2278
|
const request = create(GetTransactionStatusRequestSchema, {
|
|
2274
|
-
signature:
|
|
2279
|
+
signature: Signature.from(signature).toProtoSignature()
|
|
2275
2280
|
});
|
|
2276
2281
|
const proto = await ctx.query.getTransactionStatus(request, withCallOptions(ctx));
|
|
2277
2282
|
return TransactionStatusSnapshot.fromProto(proto);
|
|
2278
2283
|
}
|
|
2279
2284
|
async function listTransactionsForAccount(ctx, account, options = {}) {
|
|
2280
2285
|
const request = create(ListTransactionsForAccountRequestSchema, {
|
|
2281
|
-
account:
|
|
2286
|
+
account: Pubkey.from(account).toProtoPubkey(),
|
|
2282
2287
|
filter: options.filter?.toProto(),
|
|
2283
2288
|
page: options.page?.toProto()
|
|
2284
2289
|
});
|
|
@@ -2286,12 +2291,13 @@ async function listTransactionsForAccount(ctx, account, options = {}) {
|
|
|
2286
2291
|
request,
|
|
2287
2292
|
withCallOptions(ctx)
|
|
2288
2293
|
);
|
|
2294
|
+
const protoTransactionSignatures = (response.transactions ?? []).map((transaction) => transaction.signature);
|
|
2289
2295
|
const transactions = await Promise.all(
|
|
2290
|
-
|
|
2291
|
-
if (!
|
|
2296
|
+
protoTransactionSignatures.map((signature) => {
|
|
2297
|
+
if (!signature) {
|
|
2292
2298
|
throw new Error("ListTransactionsForAccount returned an empty signature");
|
|
2293
2299
|
}
|
|
2294
|
-
return getTransaction(ctx,
|
|
2300
|
+
return getTransaction(ctx, signature.value, options.transactionOptions);
|
|
2295
2301
|
})
|
|
2296
2302
|
);
|
|
2297
2303
|
return {
|
|
@@ -2338,8 +2344,8 @@ function createTransactionBuilder() {
|
|
|
2338
2344
|
return new TransactionBuilder();
|
|
2339
2345
|
}
|
|
2340
2346
|
async function createBuildParams(ctx, options) {
|
|
2341
|
-
const feePayerPublicKey =
|
|
2342
|
-
const program =
|
|
2347
|
+
const feePayerPublicKey = Pubkey.from(options.feePayer.publicKey).toBytes();
|
|
2348
|
+
const program = Pubkey.from(options.program).toBytes();
|
|
2343
2349
|
const header = await createTransactionHeader(ctx, options.header ?? {}, feePayerPublicKey);
|
|
2344
2350
|
const accounts = parseAccounts(options.accounts);
|
|
2345
2351
|
const context = createInstructionContext(feePayerPublicKey, program, accounts);
|
|
@@ -2350,7 +2356,7 @@ async function createBuildParams(ctx, options) {
|
|
|
2350
2356
|
publicKey: feePayerPublicKey,
|
|
2351
2357
|
privateKey: options.feePayer.privateKey
|
|
2352
2358
|
},
|
|
2353
|
-
program: options.program,
|
|
2359
|
+
program: Pubkey.from(options.program).toBytes(),
|
|
2354
2360
|
header,
|
|
2355
2361
|
accounts,
|
|
2356
2362
|
instructionData,
|
|
@@ -2376,10 +2382,10 @@ function parseAccounts(accounts) {
|
|
|
2376
2382
|
return void 0;
|
|
2377
2383
|
}
|
|
2378
2384
|
const readWrite = accounts.readWrite?.map(
|
|
2379
|
-
(value, index) =>
|
|
2385
|
+
(value, index) => Pubkey.from(value).toBytes()
|
|
2380
2386
|
);
|
|
2381
2387
|
const readOnly = accounts.readOnly?.map(
|
|
2382
|
-
(value, index) =>
|
|
2388
|
+
(value, index) => Pubkey.from(value).toBytes()
|
|
2383
2389
|
);
|
|
2384
2390
|
const result = {};
|
|
2385
2391
|
if (readWrite && readWrite.length > 0) {
|
|
@@ -2395,25 +2401,14 @@ function parseAccounts(accounts) {
|
|
|
2395
2401
|
}
|
|
2396
2402
|
function createInstructionContext(feePayer, program, accounts) {
|
|
2397
2403
|
const allAccounts = [
|
|
2398
|
-
feePayer,
|
|
2399
|
-
program,
|
|
2400
|
-
...accounts?.readWriteAccounts ?? [],
|
|
2401
|
-
...accounts?.readOnlyAccounts ?? []
|
|
2404
|
+
Pubkey.from(feePayer),
|
|
2405
|
+
Pubkey.from(program),
|
|
2406
|
+
...accounts?.readWriteAccounts?.map((value) => Pubkey.from(value)) ?? [],
|
|
2407
|
+
...accounts?.readOnlyAccounts?.map((value) => Pubkey.from(value)) ?? []
|
|
2402
2408
|
];
|
|
2403
|
-
const accountsEqual = (a, b) => {
|
|
2404
|
-
if (a.length !== 32 || b.length !== 32) {
|
|
2405
|
-
return false;
|
|
2406
|
-
}
|
|
2407
|
-
for (let i = 0; i < 32; i++) {
|
|
2408
|
-
if (a[i] !== b[i]) {
|
|
2409
|
-
return false;
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
return true;
|
|
2413
|
-
};
|
|
2414
2409
|
const getAccountIndex = (pubkey) => {
|
|
2415
2410
|
for (let i = 0; i < allAccounts.length; i++) {
|
|
2416
|
-
if (
|
|
2411
|
+
if (allAccounts[i].equals(Pubkey.from(pubkey))) {
|
|
2417
2412
|
return i;
|
|
2418
2413
|
}
|
|
2419
2414
|
}
|
|
@@ -2470,6 +2465,6 @@ var VersionInfo = class _VersionInfo {
|
|
|
2470
2465
|
}
|
|
2471
2466
|
};
|
|
2472
2467
|
|
|
2473
|
-
export { Account, AccountView, Block, BlockView, ChainEvent, ConsensusStatus, ExecutionStatus, FilterParamValueSchema, FilterSchema, GetVersionRequestSchema, HeightSnapshot, PageRequest, PageResponse, StateProof, Transaction, TransactionBuilder, TransactionStatusSnapshot, TransactionView, TransactionVmError, VersionInfo, accounts_exports, batchSendTransactions, blocks_exports, buildAndSignTransaction, buildTransaction, collectStream, consensusStatusToString, consensus_exports, createAccount, createThruClientContext, currentOrHistoricalVersionContext, currentVersionContext, deriveProgramAddress, events_exports, firstStreamValue, forEachStreamValue, fromPrivateKey, generateKeyPair, generateStateProof, getAccount, getBlock, getBlockHeight, getEvent, getRawAccount, getRawBlock, getRawTransaction, getTransaction, getTransactionStatus, height_exports, keys_exports, listAccounts, listBlocks, listTransactionsForAccount, proofs_exports,
|
|
2474
|
-
//# sourceMappingURL=chunk-
|
|
2475
|
-
//# sourceMappingURL=chunk-
|
|
2468
|
+
export { Account, AccountView, Block, BlockView, ChainEvent, ConsensusStatus, ExecutionStatus, FilterParamValueSchema, FilterSchema, GetVersionRequestSchema, HeightSnapshot, PageRequest, PageResponse, Pubkey, Signature, SignatureDomain, StateProof, Transaction, TransactionBuilder, TransactionStatusSnapshot, TransactionView, TransactionVmError, VersionInfo, accounts_exports, batchSendTransactions, blocks_exports, buildAndSignTransaction, buildTransaction, collectStream, consensusStatusToString, consensus_exports, createAccount, createThruClientContext, currentOrHistoricalVersionContext, currentVersionContext, deriveProgramAddress, events_exports, firstStreamValue, forEachStreamValue, fromPrivateKey, generateKeyPair, generateStateProof, getAccount, getBlock, getBlockHeight, getEvent, getRawAccount, getRawBlock, getRawTransaction, getTransaction, getTransactionStatus, height_exports, keys_exports, listAccounts, listBlocks, listTransactionsForAccount, proofs_exports, sendTransaction, seqVersionContext, signWithDomain, slotVersionContext, streamAccountUpdates, streamBlocks, streamEvents, streamTransactions, streaming_exports, timestampVersionContext, trackTransaction, transactions_exports, verifyWithDomain, versionContext, withCallOptions };
|
|
2469
|
+
//# sourceMappingURL=chunk-NXEQLBXB.js.map
|
|
2470
|
+
//# sourceMappingURL=chunk-NXEQLBXB.js.map
|