@onekeyfe/onekey-aptos-provider 2.2.22 → 2.2.24
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 +5 -2
- package/dist/OnekeyAptosProvider.js +12 -0
- package/dist/StandardProvider.js +14 -2
- package/dist/__tests__/fixtures/payloadSerializer.test.js +22 -1
- package/dist/__tests__/fixtures/serializer.test.js +1 -1
- package/dist/cjs/OnekeyAptosProvider.js +12 -0
- package/dist/cjs/StandardProvider.js +14 -2
- package/dist/cjs/__tests__/fixtures/payloadSerializer.test.js +25 -4
- package/dist/cjs/__tests__/fixtures/serializer.test.js +8 -8
- package/dist/cjs/serializer.js +9 -6
- package/dist/serializer.js +4 -1
- package/package.json +6 -6
- package/dist/cjs/utils.js +0 -10
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -6
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
|
|
2
2
|
import { ProviderAptosBase } from './ProviderAptosBase';
|
|
3
|
-
import { AptosAccountInfo, ProviderState, SignMessagePayload, SignMessagePayloadCompatible, SignMessageResponse, SignMessageResponseCompatible } from './types';
|
|
3
|
+
import type { AptosAccountInfo, ProviderState, SignMessagePayload, SignMessagePayloadCompatible, SignMessageResponse, SignMessageResponseCompatible } from './types';
|
|
4
4
|
import { IJsonRpcRequest } from '@onekeyfe/cross-inpage-provider-types';
|
|
5
5
|
import type { Types } from 'aptos';
|
|
6
|
-
import type { AccountAuthenticator } from '@aptos-labs/ts-sdk';
|
|
6
|
+
import type { AccountAuthenticator, PendingTransactionResponse } from '@aptos-labs/ts-sdk';
|
|
7
7
|
import { AptosSignAndSubmitTransactionInput, AptosSignAndSubmitTransactionOutput } from '@aptos-labs/wallet-standard';
|
|
8
8
|
export type AptosProviderType = 'petra' | 'martian';
|
|
9
9
|
type SignTransactionV2Params = {
|
|
@@ -42,6 +42,7 @@ export type AptosRequest = {
|
|
|
42
42
|
publicKey: string;
|
|
43
43
|
}>;
|
|
44
44
|
'signAndSubmitTransactionV2': (params: string) => Promise<AptosSignAndSubmitTransactionOutput>;
|
|
45
|
+
'signAndSubmitTransactionStandardV1': (params: string) => Promise<string>;
|
|
45
46
|
};
|
|
46
47
|
export type PROVIDER_EVENTS_STRINGS = keyof typeof PROVIDER_EVENTS;
|
|
47
48
|
export interface IProviderAptos extends ProviderAptosBase {
|
|
@@ -68,6 +69,7 @@ export interface IProviderAptos extends ProviderAptosBase {
|
|
|
68
69
|
signTransaction(transactions: any): Promise<any>;
|
|
69
70
|
signTransactionV2(params: SignTransactionV2Params): Promise<AccountAuthenticator>;
|
|
70
71
|
signAndSubmitTransactionV2(params: AptosSignAndSubmitTransactionInput): Promise<AptosSignAndSubmitTransactionOutput>;
|
|
72
|
+
signAndSubmitTransactionStandardV1(params: string): Promise<PendingTransactionResponse>;
|
|
71
73
|
/**
|
|
72
74
|
* Sign message
|
|
73
75
|
* @returns Transaction
|
|
@@ -103,6 +105,7 @@ declare class ProviderAptos extends ProviderAptosBase implements IProviderAptos
|
|
|
103
105
|
signTransaction(transactions: Types.TransactionPayload): Promise<any>;
|
|
104
106
|
signTransactionV2(params: SignTransactionV2Params): Promise<AccountAuthenticator>;
|
|
105
107
|
signAndSubmitTransactionV2(params: AptosSignAndSubmitTransactionInput): Promise<AptosSignAndSubmitTransactionOutput>;
|
|
108
|
+
signAndSubmitTransactionStandardV1(params: string): Promise<PendingTransactionResponse>;
|
|
106
109
|
signMessageCompatible(payload: SignMessagePayloadCompatible): Promise<SignMessageResponseCompatible>;
|
|
107
110
|
signMessage(payload: SignMessagePayload): Promise<SignMessageResponse>;
|
|
108
111
|
network(): Promise<string>;
|
|
@@ -203,6 +203,18 @@ class ProviderAptos extends ProviderAptosBase {
|
|
|
203
203
|
});
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
+
signAndSubmitTransactionStandardV1(params) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
const res = yield this._callBridge({
|
|
209
|
+
method: 'signAndSubmitTransactionStandardV1',
|
|
210
|
+
params,
|
|
211
|
+
});
|
|
212
|
+
if (!res)
|
|
213
|
+
throw web3Errors.provider.unauthorized();
|
|
214
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
215
|
+
return JSON.parse(res);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
206
218
|
signMessageCompatible(payload) {
|
|
207
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
220
|
return this._callBridge({
|
package/dist/StandardProvider.js
CHANGED
|
@@ -7,9 +7,9 @@ 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 } from '@aptos-labs/ts-sdk';
|
|
10
|
+
import { Ed25519Signature, Ed25519PublicKey, Network, AccountAddress, Serializer, } from '@aptos-labs/ts-sdk';
|
|
11
11
|
import { APTOS_CHAINS, AccountInfo, registerWallet, UserResponseStatus, } from '@aptos-labs/wallet-standard';
|
|
12
|
-
import { stripHexPrefix } from '
|
|
12
|
+
import { stripHexPrefix, bytesToHex } from '@onekeyfe/cross-inpage-provider-core';
|
|
13
13
|
export class WalletAccount {
|
|
14
14
|
constructor(account) {
|
|
15
15
|
this.chains = APTOS_CHAINS;
|
|
@@ -105,6 +105,18 @@ export class AptosStandardProvider {
|
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
this.signAndSubmitTransaction = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
if (!!input && 'rawTransaction' in input) {
|
|
109
|
+
// Support standard sign and send transaction 1.0.0
|
|
110
|
+
const serializer = new Serializer();
|
|
111
|
+
input.serialize(serializer);
|
|
112
|
+
const payload = serializer.toUint8Array();
|
|
113
|
+
const result = yield this.provider.signAndSubmitTransactionStandardV1(bytesToHex(payload));
|
|
114
|
+
return {
|
|
115
|
+
status: UserResponseStatus.APPROVED,
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
117
|
+
args: result,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
108
120
|
const result = yield this.provider.signAndSubmitTransactionV2(input);
|
|
109
121
|
return Promise.resolve({
|
|
110
122
|
status: UserResponseStatus.APPROVED,
|
|
@@ -4,7 +4,7 @@ global.TextEncoder = TextEncoder;
|
|
|
4
4
|
global.TextDecoder = TextDecoder;
|
|
5
5
|
import { Bool, U8, U16, U32, U64, U128, U256, AccountAddress, MoveVector, MoveOption, MoveString, } from '@aptos-labs/ts-sdk';
|
|
6
6
|
import { serializeTransactionPayload, deserializeTransactionPayload } from '../../serializer';
|
|
7
|
-
import { hexToBytes } from '@
|
|
7
|
+
import { hexToBytes } from '@onekeyfe/cross-inpage-provider-core';
|
|
8
8
|
import { TxnBuilderTypes } from 'aptos';
|
|
9
9
|
import { get } from 'lodash';
|
|
10
10
|
describe('TransactionPayloadSerializer', () => {
|
|
@@ -91,4 +91,25 @@ describe('TransactionPayloadSerializer', () => {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
|
+
it('serialize v2 payload', () => {
|
|
95
|
+
const payload = {
|
|
96
|
+
function: '0xe52923154e25c258d9befb0237a30b4001c63dc3bb73011c29cb3739befffcef::router_v2dot1::swap_exact_input',
|
|
97
|
+
typeArguments: [
|
|
98
|
+
'0x1::aptos_coin::AptosCoin',
|
|
99
|
+
'0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC',
|
|
100
|
+
],
|
|
101
|
+
functionArguments: ['2272000', '61199'],
|
|
102
|
+
};
|
|
103
|
+
const serialized = serializeTransactionPayload(payload);
|
|
104
|
+
const deserialized = deserializeTransactionPayload(serialized);
|
|
105
|
+
expect(get(deserialized, 'function')).toEqual(payload.function);
|
|
106
|
+
const sourceArgs = payload.functionArguments;
|
|
107
|
+
const deserializedArgs = deserialized.functionArguments;
|
|
108
|
+
expect(deserializedArgs.length).toEqual(sourceArgs.length);
|
|
109
|
+
for (let i = 0; i < sourceArgs.length; i++) {
|
|
110
|
+
const currentSourceArg = sourceArgs[i];
|
|
111
|
+
const currentDeserializedArg = deserializedArgs[i];
|
|
112
|
+
expect(currentDeserializedArg).toEqual(currentSourceArg);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
94
115
|
});
|
|
@@ -4,7 +4,7 @@ global.TextEncoder = TextEncoder;
|
|
|
4
4
|
global.TextDecoder = TextDecoder;
|
|
5
5
|
import { Bool, U8, U16, U32, U64, U128, U256, AccountAddress, MoveVector, MoveOption, MoveString, FixedBytes, } from '@aptos-labs/ts-sdk';
|
|
6
6
|
import { serializeArguments, deserializeArguments } from '../../serializer';
|
|
7
|
-
import { hexToBytes } from '@
|
|
7
|
+
import { hexToBytes } from '@onekeyfe/cross-inpage-provider-core';
|
|
8
8
|
function deepCompare(input, output) {
|
|
9
9
|
if (input instanceof MoveVector && output instanceof MoveVector) {
|
|
10
10
|
if (input.values.length !== output.values.length) {
|
|
@@ -206,6 +206,18 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
|
|
|
206
206
|
});
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
|
+
signAndSubmitTransactionStandardV1(params) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
const res = yield this._callBridge({
|
|
212
|
+
method: 'signAndSubmitTransactionStandardV1',
|
|
213
|
+
params,
|
|
214
|
+
});
|
|
215
|
+
if (!res)
|
|
216
|
+
throw cross_inpage_provider_errors_1.web3Errors.provider.unauthorized();
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
218
|
+
return JSON.parse(res);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
209
221
|
signMessageCompatible(payload) {
|
|
210
222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
211
223
|
return this._callBridge({
|
|
@@ -13,7 +13,7 @@ exports.AptosStandardProvider = exports.WalletAccount = void 0;
|
|
|
13
13
|
exports.registerAptosWallet = registerAptosWallet;
|
|
14
14
|
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
15
15
|
const wallet_standard_1 = require("@aptos-labs/wallet-standard");
|
|
16
|
-
const
|
|
16
|
+
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
17
17
|
class WalletAccount {
|
|
18
18
|
constructor(account) {
|
|
19
19
|
this.chains = wallet_standard_1.APTOS_CHAINS;
|
|
@@ -110,6 +110,18 @@ class AptosStandardProvider {
|
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
112
|
this.signAndSubmitTransaction = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
if (!!input && 'rawTransaction' in input) {
|
|
114
|
+
// Support standard sign and send transaction 1.0.0
|
|
115
|
+
const serializer = new ts_sdk_1.Serializer();
|
|
116
|
+
input.serialize(serializer);
|
|
117
|
+
const payload = serializer.toUint8Array();
|
|
118
|
+
const result = yield this.provider.signAndSubmitTransactionStandardV1((0, cross_inpage_provider_core_1.bytesToHex)(payload));
|
|
119
|
+
return {
|
|
120
|
+
status: wallet_standard_1.UserResponseStatus.APPROVED,
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
122
|
+
args: result,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
113
125
|
const result = yield this.provider.signAndSubmitTransactionV2(input);
|
|
114
126
|
return Promise.resolve({
|
|
115
127
|
status: wallet_standard_1.UserResponseStatus.APPROVED,
|
|
@@ -150,7 +162,7 @@ class AptosStandardProvider {
|
|
|
150
162
|
this.onAccountChange = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
151
163
|
this.provider.onAccountChangeStandardV2((account) => {
|
|
152
164
|
var _a, _b;
|
|
153
|
-
const address = (0,
|
|
165
|
+
const address = (0, cross_inpage_provider_core_1.stripHexPrefix)((_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : '');
|
|
154
166
|
if (account && address.length === 64) {
|
|
155
167
|
input(new wallet_standard_1.AccountInfo({
|
|
156
168
|
address: new ts_sdk_1.AccountAddress(Buffer.from(address, 'hex')),
|
|
@@ -6,7 +6,7 @@ global.TextEncoder = util_1.TextEncoder;
|
|
|
6
6
|
global.TextDecoder = util_1.TextDecoder;
|
|
7
7
|
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
8
8
|
const serializer_1 = require("../../serializer");
|
|
9
|
-
const
|
|
9
|
+
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
10
10
|
const aptos_1 = require("aptos");
|
|
11
11
|
const lodash_1 = require("lodash");
|
|
12
12
|
describe('TransactionPayloadSerializer', () => {
|
|
@@ -39,13 +39,13 @@ describe('TransactionPayloadSerializer', () => {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
it('serialize v1 wormhole payload', () => {
|
|
42
|
-
const script = new aptos_1.TxnBuilderTypes.Script((0,
|
|
42
|
+
const script = new aptos_1.TxnBuilderTypes.Script((0, cross_inpage_provider_core_1.hexToBytes)('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20'), [], [
|
|
43
43
|
new aptos_1.TxnBuilderTypes.TransactionArgumentU8(1),
|
|
44
44
|
new aptos_1.TxnBuilderTypes.TransactionArgumentU64(BigInt('18446744073709551615')),
|
|
45
45
|
new aptos_1.TxnBuilderTypes.TransactionArgumentU128(BigInt('340282366920938463463374607431768211455')),
|
|
46
46
|
new aptos_1.TxnBuilderTypes.TransactionArgumentBool(true),
|
|
47
|
-
new aptos_1.TxnBuilderTypes.TransactionArgumentAddress(new aptos_1.TxnBuilderTypes.AccountAddress((0,
|
|
48
|
-
new aptos_1.TxnBuilderTypes.TransactionArgumentU8Vector((0,
|
|
47
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentAddress(new aptos_1.TxnBuilderTypes.AccountAddress((0, cross_inpage_provider_core_1.hexToBytes)('1'.repeat(64)))),
|
|
48
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentU8Vector((0, cross_inpage_provider_core_1.hexToBytes)('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20')),
|
|
49
49
|
]);
|
|
50
50
|
const payload = new aptos_1.TxnBuilderTypes.TransactionPayloadScript(script);
|
|
51
51
|
// @ts-expect-error
|
|
@@ -93,4 +93,25 @@ describe('TransactionPayloadSerializer', () => {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
+
it('serialize v2 payload', () => {
|
|
97
|
+
const payload = {
|
|
98
|
+
function: '0xe52923154e25c258d9befb0237a30b4001c63dc3bb73011c29cb3739befffcef::router_v2dot1::swap_exact_input',
|
|
99
|
+
typeArguments: [
|
|
100
|
+
'0x1::aptos_coin::AptosCoin',
|
|
101
|
+
'0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC',
|
|
102
|
+
],
|
|
103
|
+
functionArguments: ['2272000', '61199'],
|
|
104
|
+
};
|
|
105
|
+
const serialized = (0, serializer_1.serializeTransactionPayload)(payload);
|
|
106
|
+
const deserialized = (0, serializer_1.deserializeTransactionPayload)(serialized);
|
|
107
|
+
expect((0, lodash_1.get)(deserialized, 'function')).toEqual(payload.function);
|
|
108
|
+
const sourceArgs = payload.functionArguments;
|
|
109
|
+
const deserializedArgs = deserialized.functionArguments;
|
|
110
|
+
expect(deserializedArgs.length).toEqual(sourceArgs.length);
|
|
111
|
+
for (let i = 0; i < sourceArgs.length; i++) {
|
|
112
|
+
const currentSourceArg = sourceArgs[i];
|
|
113
|
+
const currentDeserializedArg = deserializedArgs[i];
|
|
114
|
+
expect(currentDeserializedArg).toEqual(currentSourceArg);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
96
117
|
});
|
|
@@ -6,7 +6,7 @@ global.TextEncoder = util_1.TextEncoder;
|
|
|
6
6
|
global.TextDecoder = util_1.TextDecoder;
|
|
7
7
|
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
8
8
|
const serializer_1 = require("../../serializer");
|
|
9
|
-
const
|
|
9
|
+
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
10
10
|
function deepCompare(input, output) {
|
|
11
11
|
if (input instanceof ts_sdk_1.MoveVector && output instanceof ts_sdk_1.MoveVector) {
|
|
12
12
|
if (input.values.length !== output.values.length) {
|
|
@@ -79,9 +79,9 @@ describe('Serializer', () => {
|
|
|
79
79
|
new ts_sdk_1.U64(BigInt('18446744073709551615')),
|
|
80
80
|
new ts_sdk_1.U128(BigInt('340282366920938463463374607431768211455')),
|
|
81
81
|
new ts_sdk_1.U256(BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')),
|
|
82
|
-
new ts_sdk_1.AccountAddress((0,
|
|
82
|
+
new ts_sdk_1.AccountAddress((0, cross_inpage_provider_core_1.hexToBytes)('1'.repeat(64))),
|
|
83
83
|
new ts_sdk_1.MoveString('SDK'),
|
|
84
|
-
new ts_sdk_1.FixedBytes((0,
|
|
84
|
+
new ts_sdk_1.FixedBytes((0, cross_inpage_provider_core_1.hexToBytes)('010203')),
|
|
85
85
|
];
|
|
86
86
|
const serialized = (0, serializer_1.serializeArguments)(inputs);
|
|
87
87
|
const deserialized = (0, serializer_1.deserializeArguments)(serialized);
|
|
@@ -92,8 +92,8 @@ describe('Serializer', () => {
|
|
|
92
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
93
|
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
94
94
|
new ts_sdk_1.MoveVector([
|
|
95
|
-
new ts_sdk_1.AccountAddress((0,
|
|
96
|
-
new ts_sdk_1.AccountAddress((0,
|
|
95
|
+
new ts_sdk_1.AccountAddress((0, cross_inpage_provider_core_1.hexToBytes)('1'.repeat(64))),
|
|
96
|
+
new ts_sdk_1.AccountAddress((0, cross_inpage_provider_core_1.hexToBytes)('2'.repeat(64))),
|
|
97
97
|
]),
|
|
98
98
|
new ts_sdk_1.MoveVector([
|
|
99
99
|
new ts_sdk_1.MoveString('SDK'),
|
|
@@ -170,7 +170,7 @@ describe('Serializer', () => {
|
|
|
170
170
|
new ts_sdk_1.MoveString('hello'),
|
|
171
171
|
[1, 2, new ts_sdk_1.U8(3)],
|
|
172
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,
|
|
173
|
+
new ts_sdk_1.MoveOption(new ts_sdk_1.FixedBytes((0, cross_inpage_provider_core_1.hexToBytes)('010203'))),
|
|
174
174
|
[
|
|
175
175
|
new ts_sdk_1.MoveOption(new ts_sdk_1.U64(BigInt(42))),
|
|
176
176
|
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
@@ -201,7 +201,7 @@ describe('Serializer', () => {
|
|
|
201
201
|
expect(deserialized[6].isSome()).toBe(true);
|
|
202
202
|
const fixedBytes = deserialized[6].value;
|
|
203
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,
|
|
204
|
+
expect(fixedBytes === null || fixedBytes === void 0 ? void 0 : fixedBytes.toString()).toEqual(new ts_sdk_1.FixedBytes((0, cross_inpage_provider_core_1.hexToBytes)('010203')).toString());
|
|
205
205
|
// 验证复杂嵌套结构
|
|
206
206
|
const complexArray = deserialized[7];
|
|
207
207
|
expect(complexArray[0]).toBeInstanceOf(ts_sdk_1.MoveOption);
|
|
@@ -229,7 +229,7 @@ describe('Serializer', () => {
|
|
|
229
229
|
new ts_sdk_1.MoveOption(),
|
|
230
230
|
]),
|
|
231
231
|
[
|
|
232
|
-
new ts_sdk_1.AccountAddress((0,
|
|
232
|
+
new ts_sdk_1.AccountAddress((0, cross_inpage_provider_core_1.hexToBytes)('1'.repeat(64))),
|
|
233
233
|
123,
|
|
234
234
|
new ts_sdk_1.MoveVector([new ts_sdk_1.Bool(true), new ts_sdk_1.Bool(false)]),
|
|
235
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)],
|
package/dist/cjs/serializer.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.deserializeArgument = deserializeArgument;
|
|
|
8
8
|
exports.deserializeArguments = deserializeArguments;
|
|
9
9
|
exports.serializeArguments = serializeArguments;
|
|
10
10
|
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
11
|
-
const
|
|
11
|
+
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
12
12
|
var TransactionPayloadType;
|
|
13
13
|
(function (TransactionPayloadType) {
|
|
14
14
|
TransactionPayloadType[TransactionPayloadType["SCRIPT"] = 0] = "SCRIPT";
|
|
@@ -52,6 +52,9 @@ var ScriptArgumentType;
|
|
|
52
52
|
ScriptArgumentType[ScriptArgumentType["Serialized"] = 9] = "Serialized";
|
|
53
53
|
})(ScriptArgumentType || (exports.ScriptArgumentType = ScriptArgumentType = {}));
|
|
54
54
|
function serializeTransactionPayload(args) {
|
|
55
|
+
if (!args) {
|
|
56
|
+
throw new Error('Transaction payload cannot be undefined');
|
|
57
|
+
}
|
|
55
58
|
const serializer = new ts_sdk_1.Serializer();
|
|
56
59
|
if ('type' in args || ('arguments' in args && 'type_arguments' in args)) {
|
|
57
60
|
// Some Dapps do not pass the type parameter.
|
|
@@ -80,10 +83,10 @@ function serializeTransactionPayload(args) {
|
|
|
80
83
|
else {
|
|
81
84
|
throw new Error('Invalid transaction payload type');
|
|
82
85
|
}
|
|
83
|
-
return (0,
|
|
86
|
+
return (0, cross_inpage_provider_core_1.bytesToHex)(serializer.toUint8Array());
|
|
84
87
|
}
|
|
85
88
|
function deserializeTransactionPayload(hex) {
|
|
86
|
-
const deserializer = new ts_sdk_1.Deserializer((0,
|
|
89
|
+
const deserializer = new ts_sdk_1.Deserializer((0, cross_inpage_provider_core_1.hexToBytes)(hex));
|
|
87
90
|
const type = deserializer.deserializeUleb128AsU32();
|
|
88
91
|
if (type === TransactionPayloadType.ENTRY_FUNCTION) {
|
|
89
92
|
return deserializeTransactionPayloadEntryFunction(deserializer);
|
|
@@ -300,7 +303,7 @@ function deserializeArgument(deserializer) {
|
|
|
300
303
|
}
|
|
301
304
|
}
|
|
302
305
|
function deserializeArguments(bytes) {
|
|
303
|
-
const deserializer = new ts_sdk_1.Deserializer((0,
|
|
306
|
+
const deserializer = new ts_sdk_1.Deserializer((0, cross_inpage_provider_core_1.hexToBytes)(bytes));
|
|
304
307
|
const length = deserializer.deserializeU32();
|
|
305
308
|
const args = [];
|
|
306
309
|
for (let i = 0; i < length; i++) {
|
|
@@ -312,12 +315,12 @@ function serializeArguments(args) {
|
|
|
312
315
|
const serializer = new ts_sdk_1.Serializer();
|
|
313
316
|
serializer.serializeU32(args.length);
|
|
314
317
|
args.forEach((arg) => serializeArgument(serializer, arg));
|
|
315
|
-
return (0,
|
|
318
|
+
return (0, cross_inpage_provider_core_1.bytesToHex)(serializer.toUint8Array());
|
|
316
319
|
}
|
|
317
320
|
function serializeTransactionPayloadScript(args, serializer) {
|
|
318
321
|
const { bytecode, typeArguments, functionArguments } = args;
|
|
319
322
|
serializer.serializeU32AsUleb128(TransactionPayloadType.SCRIPT);
|
|
320
|
-
const bytecodeBytes = typeof bytecode === 'string' ? bytecode : (0,
|
|
323
|
+
const bytecodeBytes = typeof bytecode === 'string' ? bytecode : (0, cross_inpage_provider_core_1.bytesToHex)(bytecode);
|
|
321
324
|
serializer.serializeOption(bytecodeBytes);
|
|
322
325
|
serializer.serializeVector((0, ts_sdk_1.standardizeTypeTags)(typeArguments));
|
|
323
326
|
const hex = serializeArguments(functionArguments);
|
package/dist/serializer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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 '@
|
|
2
|
+
import { hexToBytes, bytesToHex } from '@onekeyfe/cross-inpage-provider-core';
|
|
3
3
|
export var TransactionPayloadType;
|
|
4
4
|
(function (TransactionPayloadType) {
|
|
5
5
|
TransactionPayloadType[TransactionPayloadType["SCRIPT"] = 0] = "SCRIPT";
|
|
@@ -43,6 +43,9 @@ export var ScriptArgumentType;
|
|
|
43
43
|
ScriptArgumentType[ScriptArgumentType["Serialized"] = 9] = "Serialized";
|
|
44
44
|
})(ScriptArgumentType || (ScriptArgumentType = {}));
|
|
45
45
|
export function serializeTransactionPayload(args) {
|
|
46
|
+
if (!args) {
|
|
47
|
+
throw new Error('Transaction payload cannot be undefined');
|
|
48
|
+
}
|
|
46
49
|
const serializer = new Serializer();
|
|
47
50
|
if ('type' in args || ('arguments' in args && 'type_arguments' in args)) {
|
|
48
51
|
// Some Dapps do not pass the type parameter.
|
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.24",
|
|
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.24",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.2.24",
|
|
34
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.24",
|
|
35
|
+
"@onekeyfe/extension-bridge-injected": "2.2.24",
|
|
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": "b1970ec8a9c3f55e56acd2c366ed2b71e601b170"
|
|
47
47
|
}
|
package/dist/cjs/utils.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasHexPrefix = hasHexPrefix;
|
|
4
|
-
exports.stripHexPrefix = stripHexPrefix;
|
|
5
|
-
function hasHexPrefix(data) {
|
|
6
|
-
return data.startsWith('0x');
|
|
7
|
-
}
|
|
8
|
-
function stripHexPrefix(hex) {
|
|
9
|
-
return hasHexPrefix(hex) ? hex.slice(2) : hex;
|
|
10
|
-
}
|
package/dist/utils.d.ts
DELETED