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