@onekeyfe/onekey-aptos-provider 2.2.21 → 2.2.23
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 +4 -1
- package/dist/OnekeyAptosProvider.js +12 -0
- package/dist/StandardProvider.js +14 -1
- package/dist/__tests__/fixtures/payloadSerializer.test.js +21 -0
- package/dist/cjs/OnekeyAptosProvider.js +12 -0
- package/dist/cjs/StandardProvider.js +15 -2
- package/dist/cjs/__tests__/fixtures/payloadSerializer.test.js +21 -0
- package/dist/cjs/serializer.js +3 -0
- package/dist/serializer.js +3 -0
- package/package.json +6 -6
|
@@ -3,7 +3,7 @@ import { ProviderAptosBase } from './ProviderAptosBase';
|
|
|
3
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
|
-
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,8 +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 { bytesToHex } from '@noble/hashes/utils';
|
|
12
13
|
import { stripHexPrefix } from './utils';
|
|
13
14
|
export class WalletAccount {
|
|
14
15
|
constructor(account) {
|
|
@@ -105,6 +106,18 @@ export class AptosStandardProvider {
|
|
|
105
106
|
});
|
|
106
107
|
});
|
|
107
108
|
this.signAndSubmitTransaction = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
if (!!input && 'rawTransaction' in input) {
|
|
110
|
+
// Support standard sign and send transaction 1.0.0
|
|
111
|
+
const serializer = new Serializer();
|
|
112
|
+
input.serialize(serializer);
|
|
113
|
+
const payload = serializer.toUint8Array();
|
|
114
|
+
const result = yield this.provider.signAndSubmitTransactionStandardV1(bytesToHex(payload));
|
|
115
|
+
return {
|
|
116
|
+
status: UserResponseStatus.APPROVED,
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
118
|
+
args: result,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
108
121
|
const result = yield this.provider.signAndSubmitTransactionV2(input);
|
|
109
122
|
return Promise.resolve({
|
|
110
123
|
status: UserResponseStatus.APPROVED,
|
|
@@ -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
|
});
|
|
@@ -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,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 utils_1 = require("
|
|
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;
|
|
@@ -110,6 +111,18 @@ class AptosStandardProvider {
|
|
|
110
111
|
});
|
|
111
112
|
});
|
|
112
113
|
this.signAndSubmitTransaction = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
if (!!input && 'rawTransaction' in input) {
|
|
115
|
+
// Support standard sign and send transaction 1.0.0
|
|
116
|
+
const serializer = new ts_sdk_1.Serializer();
|
|
117
|
+
input.serialize(serializer);
|
|
118
|
+
const payload = serializer.toUint8Array();
|
|
119
|
+
const result = yield this.provider.signAndSubmitTransactionStandardV1((0, utils_1.bytesToHex)(payload));
|
|
120
|
+
return {
|
|
121
|
+
status: wallet_standard_1.UserResponseStatus.APPROVED,
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
123
|
+
args: result,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
113
126
|
const result = yield this.provider.signAndSubmitTransactionV2(input);
|
|
114
127
|
return Promise.resolve({
|
|
115
128
|
status: wallet_standard_1.UserResponseStatus.APPROVED,
|
|
@@ -150,7 +163,7 @@ class AptosStandardProvider {
|
|
|
150
163
|
this.onAccountChange = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
151
164
|
this.provider.onAccountChangeStandardV2((account) => {
|
|
152
165
|
var _a, _b;
|
|
153
|
-
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 : '');
|
|
154
167
|
if (account && address.length === 64) {
|
|
155
168
|
input(new wallet_standard_1.AccountInfo({
|
|
156
169
|
address: new ts_sdk_1.AccountAddress(Buffer.from(address, 'hex')),
|
|
@@ -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
|
});
|
package/dist/cjs/serializer.js
CHANGED
|
@@ -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.
|
package/dist/serializer.js
CHANGED
|
@@ -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.23",
|
|
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.23",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.2.23",
|
|
34
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.23",
|
|
35
|
+
"@onekeyfe/extension-bridge-injected": "2.2.23",
|
|
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": "3754c167ab566db6a3b93ca8e46f8fc79afc6009"
|
|
47
47
|
}
|