@onekeyfe/onekey-aptos-provider 2.2.18 → 2.2.19
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/dist/OnekeyAptosProvider.d.ts +6 -6
- package/dist/OnekeyAptosProvider.js +12 -3
- package/dist/OnekeyMartianAptosProvider.d.ts +1 -0
- package/dist/OnekeyMartianAptosProvider.js +19 -15
- package/dist/StandardProvider.js +2 -7
- package/dist/__tests__/fixtures/payloadSerializer.test.d.ts +1 -0
- package/dist/__tests__/fixtures/payloadSerializer.test.js +94 -0
- package/dist/__tests__/fixtures/serializer.test.d.ts +1 -0
- package/dist/__tests__/fixtures/serializer.test.js +256 -0
- package/dist/cjs/OnekeyAptosProvider.js +12 -3
- package/dist/cjs/OnekeyMartianAptosProvider.js +19 -15
- package/dist/cjs/StandardProvider.js +1 -6
- package/dist/cjs/__tests__/fixtures/payloadSerializer.test.js +96 -0
- package/dist/cjs/__tests__/fixtures/serializer.test.js +258 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/serializer.js +433 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/serializer.d.ts +65 -0
- package/dist/serializer.js +424 -0
- package/package.json +6 -6
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { Serializer, Deserializer, MoveVector, MoveOption, U8, U64, U128, AccountAddress, Bool, U16, U32, U256, Serialized, MoveString, FixedBytes, TypeTag, standardizeTypeTags, } from '@aptos-labs/ts-sdk';
|
|
2
|
+
import { hexToBytes, bytesToHex } from '@noble/hashes/utils';
|
|
3
|
+
export var TransactionPayloadType;
|
|
4
|
+
(function (TransactionPayloadType) {
|
|
5
|
+
TransactionPayloadType[TransactionPayloadType["SCRIPT"] = 0] = "SCRIPT";
|
|
6
|
+
TransactionPayloadType[TransactionPayloadType["ENTRY_FUNCTION"] = 1] = "ENTRY_FUNCTION";
|
|
7
|
+
TransactionPayloadType[TransactionPayloadType["SCRIPT_LEGACY"] = 2] = "SCRIPT_LEGACY";
|
|
8
|
+
TransactionPayloadType[TransactionPayloadType["ENTRY_FUNCTION_LEGACY"] = 3] = "ENTRY_FUNCTION_LEGACY";
|
|
9
|
+
})(TransactionPayloadType || (TransactionPayloadType = {}));
|
|
10
|
+
// OneKey Primitive Types
|
|
11
|
+
export var ArgumentType;
|
|
12
|
+
(function (ArgumentType) {
|
|
13
|
+
ArgumentType[ArgumentType["NULL"] = 10000] = "NULL";
|
|
14
|
+
ArgumentType[ArgumentType["UNDEFINED"] = 10001] = "UNDEFINED";
|
|
15
|
+
ArgumentType[ArgumentType["BOOLEAN"] = 10002] = "BOOLEAN";
|
|
16
|
+
ArgumentType[ArgumentType["NUMBER"] = 10003] = "NUMBER";
|
|
17
|
+
ArgumentType[ArgumentType["BIGINT"] = 10004] = "BIGINT";
|
|
18
|
+
ArgumentType[ArgumentType["STRING"] = 10005] = "STRING";
|
|
19
|
+
ArgumentType[ArgumentType["UINT8_ARRAY"] = 10006] = "UINT8_ARRAY";
|
|
20
|
+
ArgumentType[ArgumentType["ARRAY_BUFFER"] = 10007] = "ARRAY_BUFFER";
|
|
21
|
+
ArgumentType[ArgumentType["ARRAY"] = 10008] = "ARRAY";
|
|
22
|
+
ArgumentType[ArgumentType["MOVE_OPTION"] = 10009] = "MOVE_OPTION";
|
|
23
|
+
ArgumentType[ArgumentType["MOVE_STRING"] = 10010] = "MOVE_STRING";
|
|
24
|
+
ArgumentType[ArgumentType["MOVE_FIXED_BYTES"] = 10011] = "MOVE_FIXED_BYTES";
|
|
25
|
+
ArgumentType[ArgumentType["MOVE_VECTOR"] = 10012] = "MOVE_VECTOR";
|
|
26
|
+
ArgumentType[ArgumentType["V1SDK_ACCOUNT_ADDRESS"] = 10013] = "V1SDK_ACCOUNT_ADDRESS";
|
|
27
|
+
})(ArgumentType || (ArgumentType = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Variants of script transaction arguments used in Rust, encompassing various data types for transaction processing.
|
|
30
|
+
* {@link https://github.com/aptos-labs/aptos-core/blob/main/third_party/move/move-core/types/src/transaction_argument.rs#L11}
|
|
31
|
+
*/
|
|
32
|
+
export var ScriptArgumentType;
|
|
33
|
+
(function (ScriptArgumentType) {
|
|
34
|
+
ScriptArgumentType[ScriptArgumentType["U8"] = 0] = "U8";
|
|
35
|
+
ScriptArgumentType[ScriptArgumentType["U64"] = 1] = "U64";
|
|
36
|
+
ScriptArgumentType[ScriptArgumentType["U128"] = 2] = "U128";
|
|
37
|
+
ScriptArgumentType[ScriptArgumentType["Address"] = 3] = "Address";
|
|
38
|
+
ScriptArgumentType[ScriptArgumentType["U8Vector"] = 4] = "U8Vector";
|
|
39
|
+
ScriptArgumentType[ScriptArgumentType["Bool"] = 5] = "Bool";
|
|
40
|
+
ScriptArgumentType[ScriptArgumentType["U16"] = 6] = "U16";
|
|
41
|
+
ScriptArgumentType[ScriptArgumentType["U32"] = 7] = "U32";
|
|
42
|
+
ScriptArgumentType[ScriptArgumentType["U256"] = 8] = "U256";
|
|
43
|
+
ScriptArgumentType[ScriptArgumentType["Serialized"] = 9] = "Serialized";
|
|
44
|
+
})(ScriptArgumentType || (ScriptArgumentType = {}));
|
|
45
|
+
export function serializeTransactionPayload(args) {
|
|
46
|
+
const serializer = new Serializer();
|
|
47
|
+
if (!('type' in args) && 'function' in args && !('multisigAddress' in args)) {
|
|
48
|
+
// V2 SDK Entry Function Params
|
|
49
|
+
serializeTransactionPayloadEntryFunction(args, serializer);
|
|
50
|
+
}
|
|
51
|
+
else if (!('type' in args) && 'bytecode' in args) {
|
|
52
|
+
// V2 SDK Script Params
|
|
53
|
+
serializeTransactionPayloadScript(args, serializer);
|
|
54
|
+
}
|
|
55
|
+
else if (!('type' in args) && 'value' in args) {
|
|
56
|
+
// fix wormhole v1 sdk
|
|
57
|
+
// not support complex type
|
|
58
|
+
const value = args.value;
|
|
59
|
+
if ('code' in value) {
|
|
60
|
+
serializableTransactionPayloadV1ScriptLegacy(value, serializer);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error('Invalid transaction payload type');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if ('type' in args) {
|
|
67
|
+
// V1 SDK Legacy Params
|
|
68
|
+
serializableTransactionPayloadV1Legacy(args, serializer);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
throw new Error('Invalid transaction payload type');
|
|
72
|
+
}
|
|
73
|
+
return bytesToHex(serializer.toUint8Array());
|
|
74
|
+
}
|
|
75
|
+
export function deserializeTransactionPayload(hex) {
|
|
76
|
+
const deserializer = new Deserializer(hexToBytes(hex));
|
|
77
|
+
const type = deserializer.deserializeUleb128AsU32();
|
|
78
|
+
if (type === TransactionPayloadType.ENTRY_FUNCTION) {
|
|
79
|
+
return deserializeTransactionPayloadEntryFunction(deserializer);
|
|
80
|
+
}
|
|
81
|
+
else if (type === TransactionPayloadType.SCRIPT) {
|
|
82
|
+
return deserializeTransactionPayloadScript(deserializer);
|
|
83
|
+
}
|
|
84
|
+
else if (type === TransactionPayloadType.ENTRY_FUNCTION_LEGACY) {
|
|
85
|
+
return deserializableTransactionPayloadV1EntryFunctionLegacy(deserializer);
|
|
86
|
+
}
|
|
87
|
+
else if (type === TransactionPayloadType.SCRIPT_LEGACY) {
|
|
88
|
+
return deserializableTransactionPayloadV1ScriptLegacy(deserializer);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error('Invalid transaction payload type');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// https://github.com/aptos-labs/aptos-ts-sdk/blob/289f944ef157a6bd13b1cb0949065ee4330a8c36/src/transactions/instances/transactionPayload.ts#L28-L29
|
|
95
|
+
function deserializeFromScriptArgument(index, deserializer) {
|
|
96
|
+
switch (index) {
|
|
97
|
+
case ScriptArgumentType.U8:
|
|
98
|
+
return U8.deserialize(deserializer);
|
|
99
|
+
case ScriptArgumentType.U64:
|
|
100
|
+
return U64.deserialize(deserializer);
|
|
101
|
+
case ScriptArgumentType.U128:
|
|
102
|
+
return U128.deserialize(deserializer);
|
|
103
|
+
case ScriptArgumentType.Address:
|
|
104
|
+
return AccountAddress.deserialize(deserializer);
|
|
105
|
+
case ScriptArgumentType.U8Vector:
|
|
106
|
+
return MoveVector.deserialize(deserializer, U8);
|
|
107
|
+
case ScriptArgumentType.Bool:
|
|
108
|
+
return Bool.deserialize(deserializer);
|
|
109
|
+
case ScriptArgumentType.U16:
|
|
110
|
+
return U16.deserialize(deserializer);
|
|
111
|
+
case ScriptArgumentType.U32:
|
|
112
|
+
return U32.deserialize(deserializer);
|
|
113
|
+
case ScriptArgumentType.U256:
|
|
114
|
+
return U256.deserialize(deserializer);
|
|
115
|
+
case ScriptArgumentType.Serialized:
|
|
116
|
+
return Serialized.deserialize(deserializer);
|
|
117
|
+
default:
|
|
118
|
+
throw new Error(`Unknown script argument type: ${index}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function serializeArgument(serializer, arg) {
|
|
122
|
+
if (arg === null) {
|
|
123
|
+
serializer.serializeU32AsUleb128(ArgumentType.NULL);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (arg === undefined) {
|
|
127
|
+
serializer.serializeU32AsUleb128(ArgumentType.UNDEFINED);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (typeof arg === 'boolean') {
|
|
131
|
+
serializer.serializeU32AsUleb128(ArgumentType.BOOLEAN);
|
|
132
|
+
serializer.serializeBool(arg);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (typeof arg === 'number') {
|
|
136
|
+
if (arg > Number.MAX_SAFE_INTEGER) {
|
|
137
|
+
serializer.serializeU32AsUleb128(ArgumentType.BIGINT);
|
|
138
|
+
serializer.serializeU256(BigInt(arg));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
serializer.serializeU32AsUleb128(ArgumentType.NUMBER);
|
|
142
|
+
serializer.serializeU64(arg);
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (typeof arg === 'bigint') {
|
|
147
|
+
serializer.serializeU32AsUleb128(ArgumentType.BIGINT);
|
|
148
|
+
serializer.serializeU256(arg);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (typeof arg === 'string') {
|
|
152
|
+
serializer.serializeU32AsUleb128(ArgumentType.STRING);
|
|
153
|
+
serializer.serializeOption(arg);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (arg instanceof Uint8Array) {
|
|
157
|
+
serializer.serializeU32AsUleb128(ArgumentType.UINT8_ARRAY);
|
|
158
|
+
serializer.serializeBytes(arg);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (arg instanceof ArrayBuffer) {
|
|
162
|
+
serializer.serializeU32AsUleb128(ArgumentType.ARRAY_BUFFER);
|
|
163
|
+
const uint8Array = new Uint8Array(arg);
|
|
164
|
+
serializer.serializeBytes(uint8Array);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(arg)) {
|
|
168
|
+
serializer.serializeU32AsUleb128(ArgumentType.ARRAY);
|
|
169
|
+
serializer.serializeU32(arg.length);
|
|
170
|
+
arg.forEach((item) => serializeArgument(serializer, item));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (arg instanceof MoveOption) {
|
|
174
|
+
serializer.serializeU32AsUleb128(ArgumentType.MOVE_OPTION);
|
|
175
|
+
serializer.serializeU8(arg.isSome() ? 1 : 0);
|
|
176
|
+
if (arg.isSome()) {
|
|
177
|
+
serializeArgument(serializer, arg.value);
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (arg instanceof MoveString) {
|
|
182
|
+
serializer.serializeU32AsUleb128(ArgumentType.MOVE_STRING);
|
|
183
|
+
serializer.serializeOption(arg.value);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (arg instanceof FixedBytes) {
|
|
187
|
+
serializer.serializeU32AsUleb128(ArgumentType.MOVE_FIXED_BYTES);
|
|
188
|
+
serializer.serializeBytes(arg.value);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (arg instanceof MoveVector) {
|
|
192
|
+
serializer.serializeU32AsUleb128(ArgumentType.MOVE_VECTOR);
|
|
193
|
+
serializer.serializeU32(arg.values.length);
|
|
194
|
+
arg.values.forEach((item) => serializeArgument(serializer, item));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
if ('serializeForScriptFunction' in arg) {
|
|
199
|
+
// V2 SDK Serializer
|
|
200
|
+
arg.serializeForScriptFunction(serializer);
|
|
201
|
+
}
|
|
202
|
+
else if ('value' in arg) {
|
|
203
|
+
// fix wormhole v1 sdk
|
|
204
|
+
// @ts-expect-error
|
|
205
|
+
const value = arg.value;
|
|
206
|
+
if (typeof value === 'object' &&
|
|
207
|
+
value !== null &&
|
|
208
|
+
'address' in value &&
|
|
209
|
+
value.address instanceof Uint8Array) {
|
|
210
|
+
serializer.serializeU32AsUleb128(ArgumentType.V1SDK_ACCOUNT_ADDRESS);
|
|
211
|
+
serializer.serializeBytes(value.address);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
serializeArgument(serializer, value);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.log('==>> error ', typeof arg, arg, error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export function deserializeArgument(deserializer) {
|
|
223
|
+
var _a;
|
|
224
|
+
const type = deserializer.deserializeUleb128AsU32();
|
|
225
|
+
switch (type) {
|
|
226
|
+
case ArgumentType.NULL:
|
|
227
|
+
return null;
|
|
228
|
+
case ArgumentType.UNDEFINED:
|
|
229
|
+
return undefined;
|
|
230
|
+
case ArgumentType.BOOLEAN:
|
|
231
|
+
return deserializer.deserializeBool();
|
|
232
|
+
case ArgumentType.NUMBER: {
|
|
233
|
+
const value = deserializer.deserializeU64();
|
|
234
|
+
if (value <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
235
|
+
return Number(value);
|
|
236
|
+
}
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
case ArgumentType.BIGINT: {
|
|
240
|
+
return deserializer.deserializeU256();
|
|
241
|
+
}
|
|
242
|
+
case ArgumentType.STRING: {
|
|
243
|
+
return deserializer.deserializeOption('string');
|
|
244
|
+
}
|
|
245
|
+
case ArgumentType.UINT8_ARRAY: {
|
|
246
|
+
const bytes = deserializer.deserializeBytes();
|
|
247
|
+
return new Uint8Array(bytes);
|
|
248
|
+
}
|
|
249
|
+
case ArgumentType.ARRAY_BUFFER: {
|
|
250
|
+
const bytes = deserializer.deserializeBytes();
|
|
251
|
+
return new Uint8Array(bytes).buffer;
|
|
252
|
+
}
|
|
253
|
+
case ArgumentType.ARRAY: {
|
|
254
|
+
const length = deserializer.deserializeU32();
|
|
255
|
+
const elements = [];
|
|
256
|
+
for (let i = 0; i < length; i++) {
|
|
257
|
+
elements.push(deserializeArgument(deserializer));
|
|
258
|
+
}
|
|
259
|
+
return elements;
|
|
260
|
+
}
|
|
261
|
+
case ArgumentType.MOVE_OPTION: {
|
|
262
|
+
const isSome = deserializer.deserializeU8() === 1;
|
|
263
|
+
if (!isSome) {
|
|
264
|
+
return new MoveOption();
|
|
265
|
+
}
|
|
266
|
+
const value = deserializeArgument(deserializer);
|
|
267
|
+
return new MoveOption(value);
|
|
268
|
+
}
|
|
269
|
+
case ArgumentType.MOVE_STRING: {
|
|
270
|
+
return new MoveString((_a = deserializer.deserializeOption('string')) !== null && _a !== void 0 ? _a : '');
|
|
271
|
+
}
|
|
272
|
+
case ArgumentType.MOVE_FIXED_BYTES: {
|
|
273
|
+
const bytes = deserializer.deserializeBytes();
|
|
274
|
+
return new FixedBytes(new Uint8Array(bytes));
|
|
275
|
+
}
|
|
276
|
+
case ArgumentType.MOVE_VECTOR: {
|
|
277
|
+
const length = deserializer.deserializeU32();
|
|
278
|
+
const values = [];
|
|
279
|
+
for (let i = 0; i < length; i++) {
|
|
280
|
+
values.push(deserializeArgument(deserializer));
|
|
281
|
+
}
|
|
282
|
+
return new MoveVector(values);
|
|
283
|
+
}
|
|
284
|
+
case ArgumentType.V1SDK_ACCOUNT_ADDRESS: {
|
|
285
|
+
return new AccountAddress(deserializer.deserializeBytes());
|
|
286
|
+
}
|
|
287
|
+
default: {
|
|
288
|
+
return deserializeFromScriptArgument(type, deserializer);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export function deserializeArguments(bytes) {
|
|
293
|
+
const deserializer = new Deserializer(hexToBytes(bytes));
|
|
294
|
+
const length = deserializer.deserializeU32();
|
|
295
|
+
const args = [];
|
|
296
|
+
for (let i = 0; i < length; i++) {
|
|
297
|
+
args.push(deserializeArgument(deserializer));
|
|
298
|
+
}
|
|
299
|
+
return args;
|
|
300
|
+
}
|
|
301
|
+
export function serializeArguments(args) {
|
|
302
|
+
const serializer = new Serializer();
|
|
303
|
+
serializer.serializeU32(args.length);
|
|
304
|
+
args.forEach((arg) => serializeArgument(serializer, arg));
|
|
305
|
+
return bytesToHex(serializer.toUint8Array());
|
|
306
|
+
}
|
|
307
|
+
function serializeTransactionPayloadScript(args, serializer) {
|
|
308
|
+
const { bytecode, typeArguments, functionArguments } = args;
|
|
309
|
+
serializer.serializeU32AsUleb128(TransactionPayloadType.SCRIPT);
|
|
310
|
+
const bytecodeBytes = typeof bytecode === 'string' ? bytecode : bytesToHex(bytecode);
|
|
311
|
+
serializer.serializeOption(bytecodeBytes);
|
|
312
|
+
serializer.serializeVector(standardizeTypeTags(typeArguments));
|
|
313
|
+
const hex = serializeArguments(functionArguments);
|
|
314
|
+
serializer.serializeOption(hex !== null && hex !== void 0 ? hex : '');
|
|
315
|
+
}
|
|
316
|
+
function deserializeTransactionPayloadScript(deserializer) {
|
|
317
|
+
var _a;
|
|
318
|
+
const bytecode = deserializer.deserializeOption('string');
|
|
319
|
+
const typeArguments = deserializer.deserializeVector(TypeTag);
|
|
320
|
+
const args = deserializeArguments((_a = deserializer.deserializeOption('string')) !== null && _a !== void 0 ? _a : '');
|
|
321
|
+
return {
|
|
322
|
+
bytecode: bytecode !== null && bytecode !== void 0 ? bytecode : '',
|
|
323
|
+
typeArguments,
|
|
324
|
+
functionArguments: args,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function serializeTransactionPayloadEntryFunction(args, serializer) {
|
|
328
|
+
const { function: functionName, typeArguments, functionArguments } = args;
|
|
329
|
+
serializer.serializeU32AsUleb128(TransactionPayloadType.ENTRY_FUNCTION);
|
|
330
|
+
serializer.serializeOption(functionName);
|
|
331
|
+
serializer.serializeVector(standardizeTypeTags(typeArguments));
|
|
332
|
+
const hex = serializeArguments(functionArguments);
|
|
333
|
+
serializer.serializeOption(hex !== null && hex !== void 0 ? hex : '');
|
|
334
|
+
}
|
|
335
|
+
function deserializeTransactionPayloadEntryFunction(deserializer) {
|
|
336
|
+
var _a;
|
|
337
|
+
const functionName = deserializer.deserializeOption('string');
|
|
338
|
+
const typeArguments = deserializer.deserializeVector(TypeTag);
|
|
339
|
+
const functionArguments = deserializeArguments((_a = deserializer.deserializeOption('string')) !== null && _a !== void 0 ? _a : '');
|
|
340
|
+
return {
|
|
341
|
+
function: functionName,
|
|
342
|
+
typeArguments,
|
|
343
|
+
functionArguments,
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
// V1 SDK Script Wormhole Params
|
|
347
|
+
function serializableTransactionPayloadV1ScriptLegacy(args, serializer) {
|
|
348
|
+
serializer.serializeU32AsUleb128(TransactionPayloadType.SCRIPT_LEGACY);
|
|
349
|
+
serializer.serializeBytes(args.code);
|
|
350
|
+
serializer.serializeVector(args.ty_args);
|
|
351
|
+
serializer.serializeOption(serializeArguments(args.args));
|
|
352
|
+
}
|
|
353
|
+
function deserializableTransactionPayloadV1ScriptLegacy(deserializer) {
|
|
354
|
+
var _a;
|
|
355
|
+
const code = deserializer.deserializeBytes();
|
|
356
|
+
const ty_args = deserializer.deserializeVector(TypeTag);
|
|
357
|
+
const args = deserializeArguments((_a = deserializer.deserializeOption('string')) !== null && _a !== void 0 ? _a : '');
|
|
358
|
+
// @ts-expect-error
|
|
359
|
+
const convertArgs = args.map((arg) => {
|
|
360
|
+
if (typeof arg === 'number') {
|
|
361
|
+
if (arg > Number.MAX_SAFE_INTEGER) {
|
|
362
|
+
return new U256(arg);
|
|
363
|
+
}
|
|
364
|
+
return new U64(arg);
|
|
365
|
+
}
|
|
366
|
+
if (typeof arg === 'bigint') {
|
|
367
|
+
return new U256(arg);
|
|
368
|
+
}
|
|
369
|
+
if (typeof arg === 'string') {
|
|
370
|
+
return new MoveString(arg);
|
|
371
|
+
}
|
|
372
|
+
if (arg instanceof Uint8Array) {
|
|
373
|
+
return MoveVector.U8(arg);
|
|
374
|
+
}
|
|
375
|
+
if (arg instanceof ArrayBuffer) {
|
|
376
|
+
return MoveVector.U8(new Uint8Array(arg));
|
|
377
|
+
}
|
|
378
|
+
if (typeof arg === 'boolean') {
|
|
379
|
+
return new Bool(arg);
|
|
380
|
+
}
|
|
381
|
+
if (Array.isArray(arg)) {
|
|
382
|
+
// @ts-expect-error
|
|
383
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
384
|
+
return new MoveVector(arg.map((item) => convertArgs(item)));
|
|
385
|
+
}
|
|
386
|
+
return arg;
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
bytecode: code,
|
|
390
|
+
typeArguments: ty_args,
|
|
391
|
+
functionArguments: convertArgs,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
// V1 SDK Legacy Params
|
|
395
|
+
function serializableTransactionPayloadV1Legacy(args, serializer) {
|
|
396
|
+
if (args.type === 'entry_function_payload') {
|
|
397
|
+
serializer.serializeU32AsUleb128(TransactionPayloadType.ENTRY_FUNCTION_LEGACY);
|
|
398
|
+
const { function: functionName, type_arguments, arguments: functionArguments, } = args;
|
|
399
|
+
serializer.serializeOption(functionName);
|
|
400
|
+
const length = type_arguments.length;
|
|
401
|
+
serializer.serializeU32(length);
|
|
402
|
+
for (let i = 0; i < length; i++) {
|
|
403
|
+
serializer.serializeOption(type_arguments[i]);
|
|
404
|
+
}
|
|
405
|
+
serializer.serializeOption(serializeArguments(functionArguments));
|
|
406
|
+
}
|
|
407
|
+
// not exist type script_payload
|
|
408
|
+
}
|
|
409
|
+
function deserializableTransactionPayloadV1EntryFunctionLegacy(deserializer) {
|
|
410
|
+
var _a, _b, _c;
|
|
411
|
+
const function_name = (_a = deserializer.deserializeOption('string')) !== null && _a !== void 0 ? _a : '';
|
|
412
|
+
const length = deserializer.deserializeU32();
|
|
413
|
+
const typeArguments = [];
|
|
414
|
+
for (let i = 0; i < length; i++) {
|
|
415
|
+
typeArguments.push((_b = deserializer.deserializeOption('string')) !== null && _b !== void 0 ? _b : '');
|
|
416
|
+
}
|
|
417
|
+
const args = deserializeArguments((_c = deserializer.deserializeOption('string')) !== null && _c !== void 0 ? _c : '');
|
|
418
|
+
return {
|
|
419
|
+
// @ts-expect-error
|
|
420
|
+
function: function_name,
|
|
421
|
+
typeArguments,
|
|
422
|
+
functionArguments: args,
|
|
423
|
+
};
|
|
424
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-aptos-provider",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.19",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@aptos-labs/wallet-standard": "^0.2.0",
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-core": "2.2.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-errors": "2.2.
|
|
34
|
-
"@onekeyfe/cross-inpage-provider-types": "2.2.
|
|
35
|
-
"@onekeyfe/extension-bridge-injected": "2.2.
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-core": "2.2.19",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.2.19",
|
|
34
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.19",
|
|
35
|
+
"@onekeyfe/extension-bridge-injected": "2.2.19",
|
|
36
36
|
"@wallet-standard/core": "1.0.3",
|
|
37
37
|
"eth-rpc-errors": "^4.0.3"
|
|
38
38
|
},
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"@aptos-labs/ts-sdk": "^1.30.0",
|
|
44
44
|
"aptos": "^1.3.17"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "f655c12ef639067becb3b9fede6000c864949538"
|
|
47
47
|
}
|