@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
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ProviderAptosMartian = void 0;
|
|
13
13
|
const extension_bridge_injected_1 = require("@onekeyfe/extension-bridge-injected");
|
|
14
14
|
const OnekeyAptosProvider_1 = require("./OnekeyAptosProvider");
|
|
15
|
-
const cross_inpage_provider_errors_1 = require("@onekeyfe/cross-inpage-provider-errors");
|
|
16
15
|
const lodash_1 = require("lodash");
|
|
17
16
|
class ProviderAptosMartian extends OnekeyAptosProvider_1.ProviderAptos {
|
|
18
17
|
get publicKey() {
|
|
@@ -28,7 +27,16 @@ class ProviderAptosMartian extends OnekeyAptosProvider_1.ProviderAptos {
|
|
|
28
27
|
params.aptosProviderType = this.aptosProviderType;
|
|
29
28
|
return this.bridgeRequest(params);
|
|
30
29
|
}
|
|
30
|
+
hasStandardV2SignAndSubmitTransaction(transaction) {
|
|
31
|
+
if (typeof transaction === 'object' && 'payload' in transaction && !('type' in transaction)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
31
36
|
signAndSubmitTransaction(transaction) {
|
|
37
|
+
const _super = Object.create(null, {
|
|
38
|
+
signAndSubmitTransaction: { get: () => super.signAndSubmitTransaction }
|
|
39
|
+
});
|
|
32
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
41
|
if (typeof transaction === 'string') {
|
|
34
42
|
return yield this._callMartianBridge({
|
|
@@ -37,14 +45,12 @@ class ProviderAptosMartian extends OnekeyAptosProvider_1.ProviderAptos {
|
|
|
37
45
|
});
|
|
38
46
|
}
|
|
39
47
|
else {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
if (!res)
|
|
45
|
-
throw cross_inpage_provider_errors_1.web3Errors.provider.unauthorized();
|
|
48
|
+
if (this.hasStandardV2SignAndSubmitTransaction(transaction)) {
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
return yield this.signAndSubmitTransactionV2(transaction);
|
|
51
|
+
}
|
|
46
52
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
47
|
-
return
|
|
53
|
+
return _super.signAndSubmitTransaction.call(this, transaction);
|
|
48
54
|
}
|
|
49
55
|
});
|
|
50
56
|
}
|
|
@@ -59,6 +65,9 @@ class ProviderAptosMartian extends OnekeyAptosProvider_1.ProviderAptos {
|
|
|
59
65
|
signTransaction(transaction,
|
|
60
66
|
// V2 sign transaction as fee payer
|
|
61
67
|
asFeePayer) {
|
|
68
|
+
const _super = Object.create(null, {
|
|
69
|
+
signTransaction: { get: () => super.signTransaction }
|
|
70
|
+
});
|
|
62
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
72
|
if (typeof transaction === 'string') {
|
|
64
73
|
return this._callMartianBridge({
|
|
@@ -88,13 +97,8 @@ class ProviderAptosMartian extends OnekeyAptosProvider_1.ProviderAptos {
|
|
|
88
97
|
}
|
|
89
98
|
else {
|
|
90
99
|
// aptos V1 sign transaction
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
params: transaction,
|
|
94
|
-
});
|
|
95
|
-
if (!res)
|
|
96
|
-
throw cross_inpage_provider_errors_1.web3Errors.provider.unauthorized();
|
|
97
|
-
return new Uint8Array(Buffer.from(res, 'hex'));
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
101
|
+
return _super.signTransaction.call(this, transaction);
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
});
|
|
@@ -110,12 +110,7 @@ class AptosStandardProvider {
|
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
112
|
this.signAndSubmitTransaction = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const
|
|
114
|
-
const existsBscEncodedArg = payload.functionArguments.find((arg) => (0, ts_sdk_1.isEncodedEntryFunctionArgument)(arg));
|
|
115
|
-
if (existsBscEncodedArg) {
|
|
116
|
-
throw new Error('Unsupported Function Arguments type');
|
|
117
|
-
}
|
|
118
|
-
const result = yield this.provider.signAndSubmitTransactionV2(JSON.stringify(input));
|
|
113
|
+
const result = yield this.provider.signAndSubmitTransactionV2(input);
|
|
119
114
|
return Promise.resolve({
|
|
120
115
|
status: wallet_standard_1.UserResponseStatus.APPROVED,
|
|
121
116
|
args: result,
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("util");
|
|
4
|
+
global.TextEncoder = util_1.TextEncoder;
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
global.TextDecoder = util_1.TextDecoder;
|
|
7
|
+
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
8
|
+
const serializer_1 = require("../../serializer");
|
|
9
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
10
|
+
const aptos_1 = require("aptos");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
describe('TransactionPayloadSerializer', () => {
|
|
13
|
+
it('serialize v1 payload', () => {
|
|
14
|
+
const payload = {
|
|
15
|
+
type: 'script_payload',
|
|
16
|
+
code: {
|
|
17
|
+
bytecode: '0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20',
|
|
18
|
+
},
|
|
19
|
+
type_arguments: [],
|
|
20
|
+
arguments: [
|
|
21
|
+
1,
|
|
22
|
+
'18446744073709551615',
|
|
23
|
+
'340282366920938463463374607431768211455',
|
|
24
|
+
true,
|
|
25
|
+
'1'.repeat(64),
|
|
26
|
+
'0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20',
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
const serialized = (0, serializer_1.serializeTransactionPayload)(payload);
|
|
30
|
+
const deserialized = (0, serializer_1.deserializeTransactionPayload)(serialized);
|
|
31
|
+
expect((0, lodash_1.get)(deserialized, 'bytecode')).toEqual(payload.code.bytecode);
|
|
32
|
+
const sourceArgs = payload.arguments;
|
|
33
|
+
const deserializedArgs = deserialized.functionArguments;
|
|
34
|
+
expect(deserializedArgs.length).toEqual(sourceArgs.length);
|
|
35
|
+
for (let i = 0; i < sourceArgs.length; i++) {
|
|
36
|
+
const currentSourceArg = sourceArgs[i];
|
|
37
|
+
const currentDeserializedArg = deserializedArgs[i];
|
|
38
|
+
expect(currentDeserializedArg === null || currentDeserializedArg === void 0 ? void 0 : currentDeserializedArg.toString()).toEqual(currentSourceArg.toString());
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
it('serialize v1 wormhole payload', () => {
|
|
42
|
+
const script = new aptos_1.TxnBuilderTypes.Script((0, utils_1.hexToBytes)('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20'), [], [
|
|
43
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentU8(1),
|
|
44
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentU64(BigInt('18446744073709551615')),
|
|
45
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentU128(BigInt('340282366920938463463374607431768211455')),
|
|
46
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentBool(true),
|
|
47
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentAddress(new aptos_1.TxnBuilderTypes.AccountAddress((0, utils_1.hexToBytes)('1'.repeat(64)))),
|
|
48
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentU8Vector((0, utils_1.hexToBytes)('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20')),
|
|
49
|
+
]);
|
|
50
|
+
const payload = new aptos_1.TxnBuilderTypes.TransactionPayloadScript(script);
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
const serialized = (0, serializer_1.serializeTransactionPayload)(payload);
|
|
53
|
+
const deserialized = (0, serializer_1.deserializeTransactionPayload)(serialized);
|
|
54
|
+
expect((0, lodash_1.get)(deserialized, 'bytecode')).toEqual(script.code);
|
|
55
|
+
const sourceArgs = script.args;
|
|
56
|
+
const deserializedArgs = deserialized.functionArguments;
|
|
57
|
+
expect(deserializedArgs.length).toEqual(sourceArgs.length);
|
|
58
|
+
for (let i = 0; i < sourceArgs.length; i++) {
|
|
59
|
+
const currentSourceArg = sourceArgs[i];
|
|
60
|
+
const currentDeserializedArg = deserializedArgs[i];
|
|
61
|
+
if (currentDeserializedArg instanceof ts_sdk_1.MoveVector) {
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
const currentSourceArgValues = currentSourceArg.value;
|
|
64
|
+
const currentDeserializedArgValues = currentDeserializedArg.values;
|
|
65
|
+
for (let j = 0; j < currentSourceArgValues.length; j++) {
|
|
66
|
+
expect(currentDeserializedArgValues[j].value).toEqual(currentSourceArgValues[j]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (currentDeserializedArg instanceof ts_sdk_1.MoveOption) {
|
|
70
|
+
// @ts-expect-error
|
|
71
|
+
expect(currentDeserializedArg.value).toEqual(currentSourceArg.value);
|
|
72
|
+
}
|
|
73
|
+
else if (currentDeserializedArg instanceof ts_sdk_1.MoveString ||
|
|
74
|
+
currentDeserializedArg instanceof ts_sdk_1.Bool) {
|
|
75
|
+
// @ts-expect-error
|
|
76
|
+
expect(currentDeserializedArg.value).toEqual(currentSourceArg.value);
|
|
77
|
+
}
|
|
78
|
+
else if (currentDeserializedArg instanceof ts_sdk_1.U8 ||
|
|
79
|
+
currentDeserializedArg instanceof ts_sdk_1.U16 ||
|
|
80
|
+
currentDeserializedArg instanceof ts_sdk_1.U32 ||
|
|
81
|
+
currentDeserializedArg instanceof ts_sdk_1.U64 ||
|
|
82
|
+
currentDeserializedArg instanceof ts_sdk_1.U128 ||
|
|
83
|
+
currentDeserializedArg instanceof ts_sdk_1.U256) {
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
expect(currentDeserializedArg.value.toString()).toEqual(currentSourceArg.value.toString());
|
|
86
|
+
}
|
|
87
|
+
else if (currentDeserializedArg instanceof ts_sdk_1.AccountAddress) {
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
expect(currentDeserializedArg.data).toEqual(currentSourceArg.value.address);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
throw new Error('Unknown argument type');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("util");
|
|
4
|
+
global.TextEncoder = util_1.TextEncoder;
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
global.TextDecoder = util_1.TextDecoder;
|
|
7
|
+
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
8
|
+
const serializer_1 = require("../../serializer");
|
|
9
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
10
|
+
function deepCompare(input, output) {
|
|
11
|
+
if (input instanceof ts_sdk_1.MoveVector && output instanceof ts_sdk_1.MoveVector) {
|
|
12
|
+
if (input.values.length !== output.values.length) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return input.values.every((val, index) => deepCompare(val, output.values[index]));
|
|
16
|
+
}
|
|
17
|
+
else if (input instanceof ts_sdk_1.MoveOption && output instanceof ts_sdk_1.MoveOption) {
|
|
18
|
+
if (input.isSome() !== output.isSome()) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return input.isSome() ? deepCompare(input.value, output.value) : true;
|
|
22
|
+
}
|
|
23
|
+
else if (input instanceof Object && output instanceof Object) {
|
|
24
|
+
return input.constructor === output.constructor && input.value === output.value;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return input === output;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
describe('Serializer', () => {
|
|
31
|
+
describe('SimpleEntryFunctionArgumentTypes', () => {
|
|
32
|
+
it('should handle primitive types', () => {
|
|
33
|
+
const inputs = [
|
|
34
|
+
null,
|
|
35
|
+
undefined,
|
|
36
|
+
true,
|
|
37
|
+
false,
|
|
38
|
+
42,
|
|
39
|
+
BigInt('0x1234567890'),
|
|
40
|
+
'hello world',
|
|
41
|
+
new Uint8Array([1, 2, 3]),
|
|
42
|
+
new ArrayBuffer(3),
|
|
43
|
+
];
|
|
44
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
45
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
46
|
+
expect(deserialized[0]).toBeNull();
|
|
47
|
+
expect(deserialized[1]).toBeUndefined();
|
|
48
|
+
expect(deserialized[2]).toBe(true);
|
|
49
|
+
expect(deserialized[3]).toBe(false);
|
|
50
|
+
expect(deserialized[4]).toBe(42);
|
|
51
|
+
expect(deserialized[5]).toBe(BigInt('0x1234567890'));
|
|
52
|
+
expect(deserialized[6]).toBe('hello world');
|
|
53
|
+
expect(deserialized[7]).toEqual(new Uint8Array([1, 2, 3]));
|
|
54
|
+
expect(deserialized[8]).toBeInstanceOf(ArrayBuffer);
|
|
55
|
+
});
|
|
56
|
+
it('should handle nested arrays of primitive types', () => {
|
|
57
|
+
const inputs = [
|
|
58
|
+
[1, 2, 3],
|
|
59
|
+
['a', 'b', 'c'],
|
|
60
|
+
[true, false],
|
|
61
|
+
[BigInt(1), BigInt(2)],
|
|
62
|
+
[
|
|
63
|
+
[1, 2],
|
|
64
|
+
[3, 4],
|
|
65
|
+
],
|
|
66
|
+
];
|
|
67
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
68
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
69
|
+
expect(deserialized).toEqual(inputs);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('EntryFunctionArgumentTypes', () => {
|
|
73
|
+
it('should handle Move types', () => {
|
|
74
|
+
const inputs = [
|
|
75
|
+
new ts_sdk_1.Bool(true),
|
|
76
|
+
new ts_sdk_1.U8(255),
|
|
77
|
+
new ts_sdk_1.U16(65535),
|
|
78
|
+
new ts_sdk_1.U32(4294967295),
|
|
79
|
+
new ts_sdk_1.U64(BigInt('18446744073709551615')),
|
|
80
|
+
new ts_sdk_1.U128(BigInt('340282366920938463463374607431768211455')),
|
|
81
|
+
new ts_sdk_1.U256(BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')),
|
|
82
|
+
new ts_sdk_1.AccountAddress((0, utils_1.hexToBytes)('1'.repeat(64))),
|
|
83
|
+
new ts_sdk_1.MoveString('SDK'),
|
|
84
|
+
new ts_sdk_1.FixedBytes((0, utils_1.hexToBytes)('010203')),
|
|
85
|
+
];
|
|
86
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
87
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
88
|
+
deepCompare(inputs, deserialized);
|
|
89
|
+
});
|
|
90
|
+
it('should handle MoveVector with different element types', () => {
|
|
91
|
+
const inputs = [
|
|
92
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.U8(1), new ts_sdk_1.U8(2), new ts_sdk_1.U8(3)]),
|
|
93
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
94
|
+
new ts_sdk_1.MoveVector([
|
|
95
|
+
new ts_sdk_1.AccountAddress((0, utils_1.hexToBytes)('1'.repeat(64))),
|
|
96
|
+
new ts_sdk_1.AccountAddress((0, utils_1.hexToBytes)('2'.repeat(64))),
|
|
97
|
+
]),
|
|
98
|
+
new ts_sdk_1.MoveVector([
|
|
99
|
+
new ts_sdk_1.MoveString('SDK'),
|
|
100
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
101
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.U8(1), new ts_sdk_1.U8(2), new ts_sdk_1.U8(3)]),
|
|
102
|
+
new ts_sdk_1.MoveVector([
|
|
103
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.U8(1), new ts_sdk_1.U8(2), new ts_sdk_1.U8(3)]),
|
|
104
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
105
|
+
]),
|
|
106
|
+
]),
|
|
107
|
+
];
|
|
108
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
109
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
110
|
+
deepCompare(inputs, deserialized);
|
|
111
|
+
});
|
|
112
|
+
it('should handle nested MoveOption', () => {
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
114
|
+
const inputs = [
|
|
115
|
+
new ts_sdk_1.MoveOption(), // None
|
|
116
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.U64(BigInt(42))), // Some(U64)
|
|
117
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.MoveOption(new ts_sdk_1.Bool(true))), // Some(Some(Bool))
|
|
118
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.MoveVector([new ts_sdk_1.U8(1), new ts_sdk_1.U8(2)])), // Some(Vector<U8>)
|
|
119
|
+
];
|
|
120
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
121
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
122
|
+
// None
|
|
123
|
+
expect(deserialized[0]).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
124
|
+
expect(deserialized[0].isSome()).toBe(false);
|
|
125
|
+
// Some(U64)
|
|
126
|
+
expect(deserialized[1]).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
127
|
+
expect(deserialized[1].isSome()).toBe(true);
|
|
128
|
+
expect(deserialized[1].value).toBeInstanceOf(ts_sdk_1.U64);
|
|
129
|
+
expect((_a = deserialized[1].value) === null || _a === void 0 ? void 0 : _a.value).toBe(BigInt(42));
|
|
130
|
+
// Some(Some(Bool))
|
|
131
|
+
const nestedOption = deserialized[2];
|
|
132
|
+
expect(nestedOption.isSome()).toBe(true);
|
|
133
|
+
expect(nestedOption.value).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
134
|
+
expect((_b = nestedOption.value) === null || _b === void 0 ? void 0 : _b.isSome()).toBe(true);
|
|
135
|
+
expect((_c = nestedOption.value) === null || _c === void 0 ? void 0 : _c.value).toBeInstanceOf(ts_sdk_1.Bool);
|
|
136
|
+
expect((_e = (_d = nestedOption.value) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.value).toBe(true);
|
|
137
|
+
// Some(Vector<U8>)
|
|
138
|
+
const optionVector = deserialized[3];
|
|
139
|
+
expect(optionVector.isSome()).toBe(true);
|
|
140
|
+
expect(optionVector.value).toBeInstanceOf(ts_sdk_1.MoveVector);
|
|
141
|
+
expect((_f = optionVector.value) === null || _f === void 0 ? void 0 : _f.values.length).toBe(2);
|
|
142
|
+
expect((_g = optionVector.value) === null || _g === void 0 ? void 0 : _g.values[0].value).toBe(1);
|
|
143
|
+
expect((_h = optionVector.value) === null || _h === void 0 ? void 0 : _h.values[1].value).toBe(2);
|
|
144
|
+
});
|
|
145
|
+
it('should handle large numbers for U64, U128, and U256', () => {
|
|
146
|
+
const inputs = [
|
|
147
|
+
new ts_sdk_1.U64(BigInt('18446744073709551615')), // U64 max value
|
|
148
|
+
new ts_sdk_1.U128(BigInt('340282366920938463463374607431768211455')), // U128 max value
|
|
149
|
+
new ts_sdk_1.U256(BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')), // U256 max value
|
|
150
|
+
];
|
|
151
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
152
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
153
|
+
deepCompare(inputs, deserialized);
|
|
154
|
+
});
|
|
155
|
+
it('should handle large MoveVector', () => {
|
|
156
|
+
const largeArray = Array.from({ length: 10000 }, (_, i) => new ts_sdk_1.U8(i % 256));
|
|
157
|
+
const inputs = [new ts_sdk_1.MoveVector(largeArray)];
|
|
158
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
159
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
160
|
+
deepCompare(inputs, deserialized);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
describe('Mixed Types', () => {
|
|
164
|
+
it('should handle mixture of simple and Move types', () => {
|
|
165
|
+
var _a;
|
|
166
|
+
const inputs = [
|
|
167
|
+
42,
|
|
168
|
+
new ts_sdk_1.U64(BigInt(42)),
|
|
169
|
+
'hello',
|
|
170
|
+
new ts_sdk_1.MoveString('hello'),
|
|
171
|
+
[1, 2, new ts_sdk_1.U8(3)],
|
|
172
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.U8(1), new ts_sdk_1.U8(2)]),
|
|
173
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.FixedBytes((0, utils_1.hexToBytes)('010203'))),
|
|
174
|
+
[
|
|
175
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.U64(BigInt(42))),
|
|
176
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
177
|
+
'simple string',
|
|
178
|
+
456,
|
|
179
|
+
],
|
|
180
|
+
];
|
|
181
|
+
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
182
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
183
|
+
// 验证简单类型
|
|
184
|
+
expect(deserialized[0]).toBe(42);
|
|
185
|
+
expect(deserialized[2]).toBe('hello');
|
|
186
|
+
// 验证 Move 类型
|
|
187
|
+
expect(deserialized[1]).toBeInstanceOf(ts_sdk_1.U64);
|
|
188
|
+
expect(deserialized[1].value).toBe(BigInt(42));
|
|
189
|
+
expect(deserialized[3]).toBeInstanceOf(ts_sdk_1.MoveString);
|
|
190
|
+
expect(deserialized[3].value).toBe('hello');
|
|
191
|
+
// 验证混合数组
|
|
192
|
+
const mixedArray = deserialized[4];
|
|
193
|
+
expect(mixedArray[0]).toBe(1);
|
|
194
|
+
expect(mixedArray[1]).toBe(2);
|
|
195
|
+
expect(mixedArray[2]).toBeInstanceOf(ts_sdk_1.U8);
|
|
196
|
+
expect(mixedArray[2].value).toBe(3);
|
|
197
|
+
// 验证 MoveVector
|
|
198
|
+
expect(deserialized[5]).toBeInstanceOf(ts_sdk_1.MoveVector);
|
|
199
|
+
// 验证 MoveOption
|
|
200
|
+
expect(deserialized[6]).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
201
|
+
expect(deserialized[6].isSome()).toBe(true);
|
|
202
|
+
const fixedBytes = deserialized[6].value;
|
|
203
|
+
expect(fixedBytes).toBeInstanceOf(ts_sdk_1.FixedBytes);
|
|
204
|
+
expect(fixedBytes === null || fixedBytes === void 0 ? void 0 : fixedBytes.toString()).toEqual(new ts_sdk_1.FixedBytes((0, utils_1.hexToBytes)('010203')).toString());
|
|
205
|
+
// 验证复杂嵌套结构
|
|
206
|
+
const complexArray = deserialized[7];
|
|
207
|
+
expect(complexArray[0]).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
208
|
+
expect(complexArray[0].isSome()).toBe(true);
|
|
209
|
+
const index70 = complexArray[0];
|
|
210
|
+
expect(index70).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
211
|
+
expect(index70.isSome()).toBe(true);
|
|
212
|
+
expect(index70.value).toBeInstanceOf(ts_sdk_1.U64);
|
|
213
|
+
expect((_a = index70.value) === null || _a === void 0 ? void 0 : _a.value).toBe(BigInt(42));
|
|
214
|
+
const index71 = complexArray[1];
|
|
215
|
+
expect(index71).toBeInstanceOf(ts_sdk_1.MoveVector);
|
|
216
|
+
expect(index71.values[0]).toBeInstanceOf(ts_sdk_1.Bool);
|
|
217
|
+
expect(index71.values[0].value).toBe(true);
|
|
218
|
+
expect(index71.values[1]).toBeInstanceOf(ts_sdk_1.Bool);
|
|
219
|
+
expect(index71.values[1].value).toBe(false);
|
|
220
|
+
expect(complexArray[2]).toBe('simple string');
|
|
221
|
+
expect(complexArray[3]).toBe(456);
|
|
222
|
+
});
|
|
223
|
+
it('should handle complex nested structures', () => {
|
|
224
|
+
var _a, _b;
|
|
225
|
+
const complexStruct = [
|
|
226
|
+
new ts_sdk_1.MoveVector([
|
|
227
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.U64(BigInt(1))),
|
|
228
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.U64(BigInt(2))),
|
|
229
|
+
new ts_sdk_1.MoveOption(),
|
|
230
|
+
]),
|
|
231
|
+
[
|
|
232
|
+
new ts_sdk_1.AccountAddress((0, utils_1.hexToBytes)('1'.repeat(64))),
|
|
233
|
+
123,
|
|
234
|
+
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
235
|
+
[new ts_sdk_1.MoveOption(new ts_sdk_1.MoveVector([new ts_sdk_1.U8(1), new ts_sdk_1.U8(2)])), 'nested string', BigInt(456)],
|
|
236
|
+
],
|
|
237
|
+
];
|
|
238
|
+
const serialized = (0, serializer_1.serializeArguments)(complexStruct);
|
|
239
|
+
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
240
|
+
// 验证第一个元素:MoveVector<MoveOption<U64>>
|
|
241
|
+
const vectorOfOptions = deserialized[0];
|
|
242
|
+
expect(vectorOfOptions).toBeInstanceOf(ts_sdk_1.MoveVector);
|
|
243
|
+
expect((_a = vectorOfOptions.values[0].value) === null || _a === void 0 ? void 0 : _a.value).toBe(BigInt(1));
|
|
244
|
+
expect((_b = vectorOfOptions.values[1].value) === null || _b === void 0 ? void 0 : _b.value).toBe(BigInt(2));
|
|
245
|
+
expect(vectorOfOptions.values[2].isSome()).toBe(false);
|
|
246
|
+
// 验证第二个元素:混合数组
|
|
247
|
+
const mixedArray = deserialized[1];
|
|
248
|
+
expect(mixedArray[0]).toBeInstanceOf(ts_sdk_1.AccountAddress);
|
|
249
|
+
expect(mixedArray[1]).toBe(123);
|
|
250
|
+
expect(mixedArray[2]).toBeInstanceOf(ts_sdk_1.MoveVector);
|
|
251
|
+
// 验证深层嵌套
|
|
252
|
+
const nestedArray = mixedArray[3];
|
|
253
|
+
expect(nestedArray[0]).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
254
|
+
expect(nestedArray[1]).toBe('nested string');
|
|
255
|
+
expect(nestedArray[2]).toBe(BigInt(456));
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,3 +18,4 @@ __exportStar(require("./OnekeyAptosProvider"), exports);
|
|
|
18
18
|
__exportStar(require("./OnekeyMartianAptosProvider"), exports);
|
|
19
19
|
__exportStar(require("./ProviderAptosBase"), exports);
|
|
20
20
|
__exportStar(require("./StandardProvider"), exports);
|
|
21
|
+
__exportStar(require("./serializer"), exports);
|