@solana/transactions 6.3.1 → 6.3.2-canary-20260313112147
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/package.json +15 -14
- package/src/codecs/__tests__/signatures-encoder-test.ts +255 -0
- package/src/codecs/__tests__/transaction-codec-test.ts +1164 -0
- package/src/codecs/index.ts +1 -0
- package/src/codecs/signatures-encoder.ts +49 -0
- package/src/codecs/transaction-codec.ts +334 -0
- package/src/compile-transaction.ts +61 -0
- package/src/index.ts +19 -0
- package/src/lifetime.ts +362 -0
- package/src/sendable-transaction.ts +77 -0
- package/src/signatures.ts +213 -0
- package/src/transaction-message-size.ts +73 -0
- package/src/transaction-size.ts +99 -0
- package/src/transaction.ts +34 -0
- package/src/wire-transaction.ts +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/transactions",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.2-canary-20260313112147",
|
|
4
4
|
"description": "Helpers for creating and serializing transactions",
|
|
5
5
|
"homepage": "https://www.solanakit.com/api#solanatransactions",
|
|
6
6
|
"exports": {
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"types": "./dist/types/index.d.ts",
|
|
34
34
|
"type": "commonjs",
|
|
35
35
|
"files": [
|
|
36
|
-
"./dist/"
|
|
36
|
+
"./dist/",
|
|
37
|
+
"./src/"
|
|
37
38
|
],
|
|
38
39
|
"sideEffects": false,
|
|
39
40
|
"keywords": [
|
|
@@ -55,18 +56,18 @@
|
|
|
55
56
|
"maintained node versions"
|
|
56
57
|
],
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"@solana/addresses": "6.3.
|
|
59
|
-
"@solana/codecs-
|
|
60
|
-
"@solana/codecs-
|
|
61
|
-
"@solana/codecs-
|
|
62
|
-
"@solana/codecs-strings": "6.3.
|
|
63
|
-
"@solana/errors": "6.3.
|
|
64
|
-
"@solana/functional": "6.3.
|
|
65
|
-
"@solana/instructions": "6.3.
|
|
66
|
-
"@solana/keys": "6.3.
|
|
67
|
-
"@solana/nominal-types": "6.3.
|
|
68
|
-
"@solana/rpc-types": "6.3.
|
|
69
|
-
"@solana/transaction-messages": "6.3.
|
|
59
|
+
"@solana/addresses": "6.3.2-canary-20260313112147",
|
|
60
|
+
"@solana/codecs-core": "6.3.2-canary-20260313112147",
|
|
61
|
+
"@solana/codecs-data-structures": "6.3.2-canary-20260313112147",
|
|
62
|
+
"@solana/codecs-numbers": "6.3.2-canary-20260313112147",
|
|
63
|
+
"@solana/codecs-strings": "6.3.2-canary-20260313112147",
|
|
64
|
+
"@solana/errors": "6.3.2-canary-20260313112147",
|
|
65
|
+
"@solana/functional": "6.3.2-canary-20260313112147",
|
|
66
|
+
"@solana/instructions": "6.3.2-canary-20260313112147",
|
|
67
|
+
"@solana/keys": "6.3.2-canary-20260313112147",
|
|
68
|
+
"@solana/nominal-types": "6.3.2-canary-20260313112147",
|
|
69
|
+
"@solana/rpc-types": "6.3.2-canary-20260313112147",
|
|
70
|
+
"@solana/transaction-messages": "6.3.2-canary-20260313112147"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"typescript": "^5.0.0"
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { Address } from '@solana/addresses';
|
|
2
|
+
import {
|
|
3
|
+
SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS,
|
|
4
|
+
SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES,
|
|
5
|
+
SolanaError,
|
|
6
|
+
} from '@solana/errors';
|
|
7
|
+
import { SignatureBytes } from '@solana/keys';
|
|
8
|
+
|
|
9
|
+
import { SignaturesMap } from '../../transaction';
|
|
10
|
+
import { getSignaturesEncoderWithLength, getSignaturesEncoderWithSizePrefix } from '../signatures-encoder';
|
|
11
|
+
|
|
12
|
+
describe('getSignaturesEncoderWithSizePrefix', () => {
|
|
13
|
+
const encoder = getSignaturesEncoderWithSizePrefix();
|
|
14
|
+
|
|
15
|
+
it('should throw if the signatures map is empty', () => {
|
|
16
|
+
const signatures: SignaturesMap = {};
|
|
17
|
+
expect(() => encoder.encode(signatures)).toThrow(
|
|
18
|
+
new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES),
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('when the signatures map contains one entry', () => {
|
|
23
|
+
const address = 'abc' as Address;
|
|
24
|
+
|
|
25
|
+
it('should return the bytes of a single signature if it is defined', () => {
|
|
26
|
+
const signature = new Uint8Array(64).fill(1) as SignatureBytes;
|
|
27
|
+
const signatures: SignaturesMap = { [address]: signature };
|
|
28
|
+
const encoded = encoder.encode(signatures);
|
|
29
|
+
|
|
30
|
+
expect(encoded).toStrictEqual(
|
|
31
|
+
new Uint8Array([
|
|
32
|
+
/* length of signatures */
|
|
33
|
+
1,
|
|
34
|
+
/* signature */
|
|
35
|
+
...signature,
|
|
36
|
+
]),
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should return all 0 bytes for the signature if it is not defined', () => {
|
|
41
|
+
const signatures: SignaturesMap = { [address]: null };
|
|
42
|
+
const encoded = encoder.encode(signatures);
|
|
43
|
+
|
|
44
|
+
expect(encoded).toStrictEqual(
|
|
45
|
+
new Uint8Array([
|
|
46
|
+
/* length of signatures */
|
|
47
|
+
1,
|
|
48
|
+
/* null signature */
|
|
49
|
+
...new Uint8Array(64).fill(0),
|
|
50
|
+
]),
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('when the signatures map contains multiple entries', () => {
|
|
56
|
+
// intentionally out of order
|
|
57
|
+
const address1 = 'fff' as Address;
|
|
58
|
+
const address2 = 'eee' as Address;
|
|
59
|
+
const address3 = 'ddd' as Address;
|
|
60
|
+
|
|
61
|
+
const signature1 = new Uint8Array(64).fill(1) as SignatureBytes;
|
|
62
|
+
const signature2 = new Uint8Array(64).fill(2) as SignatureBytes;
|
|
63
|
+
const signature3 = new Uint8Array(64).fill(3) as SignatureBytes;
|
|
64
|
+
|
|
65
|
+
it('should return the bytes of multiple signatures if all are defined', () => {
|
|
66
|
+
const signatures: SignaturesMap = {
|
|
67
|
+
[address1]: signature1,
|
|
68
|
+
[address2]: signature2,
|
|
69
|
+
[address3]: signature3,
|
|
70
|
+
};
|
|
71
|
+
const encoded = encoder.encode(signatures);
|
|
72
|
+
|
|
73
|
+
expect(encoded).toStrictEqual(
|
|
74
|
+
new Uint8Array([
|
|
75
|
+
/* length of signatures */
|
|
76
|
+
3,
|
|
77
|
+
/* signatures */
|
|
78
|
+
...signature1,
|
|
79
|
+
...signature2,
|
|
80
|
+
...signature3,
|
|
81
|
+
]),
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should return multiple all 0 byte signatures if all are not defined', () => {
|
|
86
|
+
const signatures: SignaturesMap = {
|
|
87
|
+
[address1]: null,
|
|
88
|
+
[address2]: null,
|
|
89
|
+
[address3]: null,
|
|
90
|
+
};
|
|
91
|
+
const encoded = encoder.encode(signatures);
|
|
92
|
+
|
|
93
|
+
expect(encoded).toStrictEqual(
|
|
94
|
+
new Uint8Array([
|
|
95
|
+
/* length of signatures */
|
|
96
|
+
3,
|
|
97
|
+
/* signatures */
|
|
98
|
+
...new Uint8Array(64).fill(0),
|
|
99
|
+
...new Uint8Array(64).fill(0),
|
|
100
|
+
...new Uint8Array(64).fill(0),
|
|
101
|
+
]),
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should return a mixture of defined and not defined signatures', () => {
|
|
106
|
+
const signatures: SignaturesMap = {
|
|
107
|
+
[address1]: signature1,
|
|
108
|
+
[address2]: null,
|
|
109
|
+
[address3]: signature3,
|
|
110
|
+
};
|
|
111
|
+
const encoded = encoder.encode(signatures);
|
|
112
|
+
|
|
113
|
+
expect(encoded).toStrictEqual(
|
|
114
|
+
new Uint8Array([
|
|
115
|
+
/* length of signatures */
|
|
116
|
+
3,
|
|
117
|
+
/* signatures */
|
|
118
|
+
...signature1,
|
|
119
|
+
...new Uint8Array(64).fill(0),
|
|
120
|
+
...signature3,
|
|
121
|
+
]),
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('getSignaturesEncoderWithLength', () => {
|
|
128
|
+
it('should throw if the signatures map is empty', () => {
|
|
129
|
+
const signatures: SignaturesMap = {};
|
|
130
|
+
const encoder = getSignaturesEncoderWithLength(1);
|
|
131
|
+
expect(() => encoder.encode(signatures)).toThrow(
|
|
132
|
+
new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES),
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('when the signatures map contains one entry', () => {
|
|
137
|
+
const address = 'abc' as Address;
|
|
138
|
+
|
|
139
|
+
it('should return the bytes of a single signature if it is defined', () => {
|
|
140
|
+
const signature = new Uint8Array(64).fill(1) as SignatureBytes;
|
|
141
|
+
const signatures: SignaturesMap = { [address]: signature };
|
|
142
|
+
const encoder = getSignaturesEncoderWithLength(1);
|
|
143
|
+
const encoded = encoder.encode(signatures);
|
|
144
|
+
|
|
145
|
+
expect(encoded).toStrictEqual(
|
|
146
|
+
new Uint8Array([
|
|
147
|
+
/* no size prefix */
|
|
148
|
+
/* signature */
|
|
149
|
+
...signature,
|
|
150
|
+
]),
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should return all 0 bytes for the signature if it is not defined', () => {
|
|
155
|
+
const signatures: SignaturesMap = { [address]: null };
|
|
156
|
+
const encoder = getSignaturesEncoderWithLength(1);
|
|
157
|
+
const encoded = encoder.encode(signatures);
|
|
158
|
+
|
|
159
|
+
expect(encoded).toStrictEqual(
|
|
160
|
+
new Uint8Array([
|
|
161
|
+
/* no size prefix */
|
|
162
|
+
/* null signature */
|
|
163
|
+
...new Uint8Array(64).fill(0),
|
|
164
|
+
]),
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('when the signatures map contains multiple entries', () => {
|
|
170
|
+
// intentionally out of order
|
|
171
|
+
const address1 = 'fff' as Address;
|
|
172
|
+
const address2 = 'eee' as Address;
|
|
173
|
+
const address3 = 'ddd' as Address;
|
|
174
|
+
|
|
175
|
+
const signature1 = new Uint8Array(64).fill(1) as SignatureBytes;
|
|
176
|
+
const signature2 = new Uint8Array(64).fill(2) as SignatureBytes;
|
|
177
|
+
const signature3 = new Uint8Array(64).fill(3) as SignatureBytes;
|
|
178
|
+
|
|
179
|
+
it('should return the bytes of multiple signatures if all are defined', () => {
|
|
180
|
+
const signatures: SignaturesMap = {
|
|
181
|
+
[address1]: signature1,
|
|
182
|
+
[address2]: signature2,
|
|
183
|
+
[address3]: signature3,
|
|
184
|
+
};
|
|
185
|
+
const encoder = getSignaturesEncoderWithLength(3);
|
|
186
|
+
const encoded = encoder.encode(signatures);
|
|
187
|
+
|
|
188
|
+
expect(encoded).toStrictEqual(
|
|
189
|
+
new Uint8Array([
|
|
190
|
+
/* no size prefix */
|
|
191
|
+
/* signatures */
|
|
192
|
+
...signature1,
|
|
193
|
+
...signature2,
|
|
194
|
+
...signature3,
|
|
195
|
+
]),
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should return multiple all 0 byte signatures if all are not defined', () => {
|
|
200
|
+
const signatures: SignaturesMap = {
|
|
201
|
+
[address1]: null,
|
|
202
|
+
[address2]: null,
|
|
203
|
+
[address3]: null,
|
|
204
|
+
};
|
|
205
|
+
const encoder = getSignaturesEncoderWithLength(3);
|
|
206
|
+
const encoded = encoder.encode(signatures);
|
|
207
|
+
|
|
208
|
+
expect(encoded).toStrictEqual(
|
|
209
|
+
new Uint8Array([
|
|
210
|
+
/* no size prefix */
|
|
211
|
+
/* signatures */
|
|
212
|
+
...new Uint8Array(64).fill(0),
|
|
213
|
+
...new Uint8Array(64).fill(0),
|
|
214
|
+
...new Uint8Array(64).fill(0),
|
|
215
|
+
]),
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should return a mixture of defined and not defined signatures', () => {
|
|
220
|
+
const signatures: SignaturesMap = {
|
|
221
|
+
[address1]: signature1,
|
|
222
|
+
[address2]: null,
|
|
223
|
+
[address3]: signature3,
|
|
224
|
+
};
|
|
225
|
+
const encoder = getSignaturesEncoderWithLength(3);
|
|
226
|
+
const encoded = encoder.encode(signatures);
|
|
227
|
+
|
|
228
|
+
expect(encoded).toStrictEqual(
|
|
229
|
+
new Uint8Array([
|
|
230
|
+
/* no size prefix */
|
|
231
|
+
/* signatures */
|
|
232
|
+
...signature1,
|
|
233
|
+
...new Uint8Array(64).fill(0),
|
|
234
|
+
...signature3,
|
|
235
|
+
]),
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('should throw if the number of signatures is more than the expected size', () => {
|
|
240
|
+
const signatures: SignaturesMap = {
|
|
241
|
+
[address1]: signature1,
|
|
242
|
+
[address2]: signature2,
|
|
243
|
+
[address3]: signature3,
|
|
244
|
+
};
|
|
245
|
+
const encoder = getSignaturesEncoderWithLength(2);
|
|
246
|
+
expect(() => encoder.encode(signatures)).toThrow(
|
|
247
|
+
new SolanaError(SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS, {
|
|
248
|
+
actual: 3,
|
|
249
|
+
codecDescription: 'signatures',
|
|
250
|
+
expected: 2,
|
|
251
|
+
}),
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|