@onekeyfe/onekey-aptos-provider 2.2.25 → 2.2.26
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 +1 -1
- package/dist/StandardProvider.js +2 -1
- package/dist/__tests__/fixtures/payloadSerializer.test.js +1 -1
- package/dist/__tests__/fixtures/serializer.test.js +1 -1
- package/dist/cjs/StandardProvider.js +4 -3
- package/dist/cjs/__tests__/fixtures/payloadSerializer.test.js +4 -4
- package/dist/cjs/__tests__/fixtures/serializer.test.js +8 -8
- package/dist/cjs/serializer.js +6 -6
- package/dist/cjs/utils.js +10 -0
- package/dist/serializer.js +1 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +6 -0
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
|
|
2
2
|
import { ProviderAptosBase } from './ProviderAptosBase';
|
|
3
|
-
import
|
|
3
|
+
import { 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
6
|
import type { AccountAuthenticator, PendingTransactionResponse } from '@aptos-labs/ts-sdk';
|
package/dist/StandardProvider.js
CHANGED
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
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 {
|
|
12
|
+
import { bytesToHex } from '@noble/hashes/utils';
|
|
13
|
+
import { stripHexPrefix } from './utils';
|
|
13
14
|
export class WalletAccount {
|
|
14
15
|
constructor(account) {
|
|
15
16
|
this.chains = APTOS_CHAINS;
|
|
@@ -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 '@noble/hashes/utils';
|
|
8
8
|
import { TxnBuilderTypes } from 'aptos';
|
|
9
9
|
import { get } from 'lodash';
|
|
10
10
|
describe('TransactionPayloadSerializer', () => {
|
|
@@ -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 '@noble/hashes/utils';
|
|
8
8
|
function deepCompare(input, output) {
|
|
9
9
|
if (input instanceof MoveVector && output instanceof MoveVector) {
|
|
10
10
|
if (input.values.length !== output.values.length) {
|
|
@@ -13,7 +13,8 @@ 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 utils_1 = require("@noble/hashes/utils");
|
|
17
|
+
const utils_2 = require("./utils");
|
|
17
18
|
class WalletAccount {
|
|
18
19
|
constructor(account) {
|
|
19
20
|
this.chains = wallet_standard_1.APTOS_CHAINS;
|
|
@@ -115,7 +116,7 @@ class AptosStandardProvider {
|
|
|
115
116
|
const serializer = new ts_sdk_1.Serializer();
|
|
116
117
|
input.serialize(serializer);
|
|
117
118
|
const payload = serializer.toUint8Array();
|
|
118
|
-
const result = yield this.provider.signAndSubmitTransactionStandardV1((0,
|
|
119
|
+
const result = yield this.provider.signAndSubmitTransactionStandardV1((0, utils_1.bytesToHex)(payload));
|
|
119
120
|
return {
|
|
120
121
|
status: wallet_standard_1.UserResponseStatus.APPROVED,
|
|
121
122
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -162,7 +163,7 @@ class AptosStandardProvider {
|
|
|
162
163
|
this.onAccountChange = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
163
164
|
this.provider.onAccountChangeStandardV2((account) => {
|
|
164
165
|
var _a, _b;
|
|
165
|
-
const address = (0,
|
|
166
|
+
const address = (0, utils_2.stripHexPrefix)((_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : '');
|
|
166
167
|
if (account && address.length === 64) {
|
|
167
168
|
input(new wallet_standard_1.AccountInfo({
|
|
168
169
|
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 utils_1 = require("@noble/hashes/utils");
|
|
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, utils_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, utils_1.hexToBytes)('1'.repeat(64)))),
|
|
48
|
+
new aptos_1.TxnBuilderTypes.TransactionArgumentU8Vector((0, utils_1.hexToBytes)('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20')),
|
|
49
49
|
]);
|
|
50
50
|
const payload = new aptos_1.TxnBuilderTypes.TransactionPayloadScript(script);
|
|
51
51
|
// @ts-expect-error
|
|
@@ -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 utils_1 = require("@noble/hashes/utils");
|
|
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, utils_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, utils_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, utils_1.hexToBytes)('1'.repeat(64))),
|
|
96
|
+
new ts_sdk_1.AccountAddress((0, utils_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, utils_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, utils_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, utils_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 utils_1 = require("@noble/hashes/utils");
|
|
12
12
|
var TransactionPayloadType;
|
|
13
13
|
(function (TransactionPayloadType) {
|
|
14
14
|
TransactionPayloadType[TransactionPayloadType["SCRIPT"] = 0] = "SCRIPT";
|
|
@@ -83,10 +83,10 @@ function serializeTransactionPayload(args) {
|
|
|
83
83
|
else {
|
|
84
84
|
throw new Error('Invalid transaction payload type');
|
|
85
85
|
}
|
|
86
|
-
return (0,
|
|
86
|
+
return (0, utils_1.bytesToHex)(serializer.toUint8Array());
|
|
87
87
|
}
|
|
88
88
|
function deserializeTransactionPayload(hex) {
|
|
89
|
-
const deserializer = new ts_sdk_1.Deserializer((0,
|
|
89
|
+
const deserializer = new ts_sdk_1.Deserializer((0, utils_1.hexToBytes)(hex));
|
|
90
90
|
const type = deserializer.deserializeUleb128AsU32();
|
|
91
91
|
if (type === TransactionPayloadType.ENTRY_FUNCTION) {
|
|
92
92
|
return deserializeTransactionPayloadEntryFunction(deserializer);
|
|
@@ -303,7 +303,7 @@ function deserializeArgument(deserializer) {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
function deserializeArguments(bytes) {
|
|
306
|
-
const deserializer = new ts_sdk_1.Deserializer((0,
|
|
306
|
+
const deserializer = new ts_sdk_1.Deserializer((0, utils_1.hexToBytes)(bytes));
|
|
307
307
|
const length = deserializer.deserializeU32();
|
|
308
308
|
const args = [];
|
|
309
309
|
for (let i = 0; i < length; i++) {
|
|
@@ -315,12 +315,12 @@ function serializeArguments(args) {
|
|
|
315
315
|
const serializer = new ts_sdk_1.Serializer();
|
|
316
316
|
serializer.serializeU32(args.length);
|
|
317
317
|
args.forEach((arg) => serializeArgument(serializer, arg));
|
|
318
|
-
return (0,
|
|
318
|
+
return (0, utils_1.bytesToHex)(serializer.toUint8Array());
|
|
319
319
|
}
|
|
320
320
|
function serializeTransactionPayloadScript(args, serializer) {
|
|
321
321
|
const { bytecode, typeArguments, functionArguments } = args;
|
|
322
322
|
serializer.serializeU32AsUleb128(TransactionPayloadType.SCRIPT);
|
|
323
|
-
const bytecodeBytes = typeof bytecode === 'string' ? bytecode : (0,
|
|
323
|
+
const bytecodeBytes = typeof bytecode === 'string' ? bytecode : (0, utils_1.bytesToHex)(bytecode);
|
|
324
324
|
serializer.serializeOption(bytecodeBytes);
|
|
325
325
|
serializer.serializeVector((0, ts_sdk_1.standardizeTypeTags)(typeArguments));
|
|
326
326
|
const hex = serializeArguments(functionArguments);
|
|
@@ -0,0 +1,10 @@
|
|
|
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/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 '@noble/hashes/utils';
|
|
3
3
|
export var TransactionPayloadType;
|
|
4
4
|
(function (TransactionPayloadType) {
|
|
5
5
|
TransactionPayloadType[TransactionPayloadType["SCRIPT"] = 0] = "SCRIPT";
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
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.26",
|
|
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.26",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.2.26",
|
|
34
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.26",
|
|
35
|
+
"@onekeyfe/extension-bridge-injected": "2.2.26",
|
|
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": "bbf6e9bae844ea2d5aaed884a4ace9cc8051569d"
|
|
47
47
|
}
|