@aptos-labs/wallet-adapter-core 4.25.0 → 5.0.1

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.
Files changed (70) hide show
  1. package/README.md +10 -0
  2. package/dist/WalletCore.d.ts +71 -112
  3. package/dist/WalletCore.d.ts.map +1 -1
  4. package/dist/constants.d.ts +4 -14
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/error/index.d.ts +3 -0
  7. package/dist/error/index.d.ts.map +1 -1
  8. package/dist/index.d.ts +3 -3
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +379 -859
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +408 -894
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/{AIP62StandardWallets/registry.d.ts → registry.d.ts} +1 -1
  15. package/dist/registry.d.ts.map +1 -0
  16. package/dist/sdkWallets.d.ts +3 -0
  17. package/dist/sdkWallets.d.ts.map +1 -0
  18. package/dist/utils/helpers.d.ts +7 -7
  19. package/dist/utils/helpers.d.ts.map +1 -1
  20. package/dist/utils/index.d.ts +1 -1
  21. package/dist/utils/index.d.ts.map +1 -1
  22. package/dist/utils/localStorage.d.ts +1 -2
  23. package/dist/utils/localStorage.d.ts.map +1 -1
  24. package/dist/utils/types.d.ts +26 -0
  25. package/dist/utils/types.d.ts.map +1 -0
  26. package/dist/utils/walletSelector.d.ts +18 -19
  27. package/dist/utils/walletSelector.d.ts.map +1 -1
  28. package/dist/version.d.ts +1 -1
  29. package/dist/version.d.ts.map +1 -1
  30. package/package.json +4 -5
  31. package/src/WalletCore.ts +474 -686
  32. package/src/constants.ts +3 -13
  33. package/src/error/index.ts +4 -0
  34. package/src/index.ts +3 -3
  35. package/src/{AIP62StandardWallets/registry.ts → registry.ts} +19 -6
  36. package/src/{AIP62StandardWallets/sdkWallets.ts → sdkWallets.ts} +6 -6
  37. package/src/utils/helpers.ts +46 -32
  38. package/src/utils/index.ts +1 -1
  39. package/src/utils/localStorage.ts +1 -3
  40. package/src/{AIP62StandardWallets → utils}/types.ts +22 -3
  41. package/src/utils/walletSelector.ts +32 -26
  42. package/src/version.ts +1 -1
  43. package/dist/AIP62StandardWallets/WalletStandard.d.ts +0 -44
  44. package/dist/AIP62StandardWallets/WalletStandard.d.ts.map +0 -1
  45. package/dist/AIP62StandardWallets/index.d.ts +0 -3
  46. package/dist/AIP62StandardWallets/index.d.ts.map +0 -1
  47. package/dist/AIP62StandardWallets/registry.d.ts.map +0 -1
  48. package/dist/AIP62StandardWallets/sdkWallets.d.ts +0 -4
  49. package/dist/AIP62StandardWallets/sdkWallets.d.ts.map +0 -1
  50. package/dist/AIP62StandardWallets/types.d.ts +0 -12
  51. package/dist/AIP62StandardWallets/types.d.ts.map +0 -1
  52. package/dist/LegacyWalletPlugins/WalletCoreV1.d.ts +0 -50
  53. package/dist/LegacyWalletPlugins/WalletCoreV1.d.ts.map +0 -1
  54. package/dist/LegacyWalletPlugins/conversion.d.ts +0 -21
  55. package/dist/LegacyWalletPlugins/conversion.d.ts.map +0 -1
  56. package/dist/LegacyWalletPlugins/index.d.ts +0 -4
  57. package/dist/LegacyWalletPlugins/index.d.ts.map +0 -1
  58. package/dist/LegacyWalletPlugins/types.d.ts +0 -116
  59. package/dist/LegacyWalletPlugins/types.d.ts.map +0 -1
  60. package/dist/__tests__/WalletCore.test.d.ts +0 -2
  61. package/dist/__tests__/WalletCore.test.d.ts.map +0 -1
  62. package/dist/utils/scopePollingDetectionStrategy.d.ts +0 -2
  63. package/dist/utils/scopePollingDetectionStrategy.d.ts.map +0 -1
  64. package/src/AIP62StandardWallets/WalletStandard.ts +0 -242
  65. package/src/AIP62StandardWallets/index.ts +0 -2
  66. package/src/LegacyWalletPlugins/WalletCoreV1.ts +0 -258
  67. package/src/LegacyWalletPlugins/conversion.ts +0 -124
  68. package/src/LegacyWalletPlugins/index.ts +0 -3
  69. package/src/LegacyWalletPlugins/types.ts +0 -188
  70. package/src/utils/scopePollingDetectionStrategy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 +0,0 @@
1
- export * from "./WalletCoreV1";
2
- export * from "./conversion";
3
- export * from "./types";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/LegacyWalletPlugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
@@ -1,116 +0,0 @@
1
- import { Types } from "aptos";
2
- import { Network, InputGenerateTransactionOptions, InputSubmitTransactionData, PendingTransactionResponse, AccountAddressInput, InputGenerateTransactionPayloadData, AnyRawTransaction, Signature } from "@aptos-labs/ts-sdk";
3
- import { WalletReadyState } from "../constants";
4
- import { AptosSignAndSubmitTransactionOutput, AptosSignMessageOutput, UserResponse, AccountInfo as StandardAccountInfo, NetworkInfo as StandardNetworkInfo, AptosChangeNetworkMethod, AptosSignAndSubmitTransactionInput } from "@aptos-labs/wallet-standard";
5
- import { AptosStandardSupportedWallet } from "../AIP62StandardWallets/types";
6
- export { TxnBuilderTypes, Types } from "aptos";
7
- export type { InputGenerateTransactionData, InputGenerateTransactionOptions, AnyRawTransaction, InputSubmitTransactionData, PendingTransactionResponse, AccountAuthenticator, Network, } from "@aptos-labs/ts-sdk";
8
- export type { NetworkInfo as StandardNetworkInfo, AptosChangeNetworkOutput, } from "@aptos-labs/wallet-standard";
9
- export type WalletName<T extends string = string> = T & {
10
- __brand__: "WalletName";
11
- };
12
- export type NetworkInfo = {
13
- name: Network;
14
- chainId?: string;
15
- url?: string;
16
- };
17
- export type WalletInfo = {
18
- name: WalletName;
19
- icon: string;
20
- url: string;
21
- };
22
- export type AccountInfo = {
23
- address: string;
24
- publicKey: string | string[];
25
- minKeysRequired?: number;
26
- ansName?: string | null;
27
- };
28
- export interface AptosWalletErrorResult {
29
- code: number;
30
- name: string;
31
- message: string;
32
- }
33
- export declare interface WalletCoreEvents {
34
- connect(account: AccountInfo | null): void;
35
- disconnect(): void;
36
- readyStateChange(wallet: Wallet): void;
37
- standardWalletsAdded(wallets: Wallet | AptosStandardSupportedWallet): void;
38
- networkChange(network: NetworkInfo | null): void;
39
- accountChange(account: AccountInfo | null): void;
40
- }
41
- export interface SignMessagePayload {
42
- address?: boolean;
43
- application?: boolean;
44
- chainId?: boolean;
45
- message: string;
46
- nonce: string;
47
- }
48
- export interface SignMessageResponse {
49
- address?: string;
50
- application?: string;
51
- chainId?: number;
52
- fullMessage: string;
53
- message: string;
54
- nonce: string;
55
- prefix: "APTOS";
56
- signature: string | string[] | Signature;
57
- bitmap?: Uint8Array;
58
- }
59
- export type OnNetworkChange = (callBack: (networkInfo: NetworkInfo | StandardNetworkInfo) => Promise<void>) => Promise<void>;
60
- export type OnAccountChange = (callBack: (accountInfo: AccountInfo | StandardAccountInfo) => Promise<any>) => Promise<void>;
61
- export interface AdapterPluginEvents {
62
- onNetworkChange: OnNetworkChange;
63
- onAccountChange: OnAccountChange;
64
- }
65
- export interface AdapterPluginProps<Name extends string = string> {
66
- name: WalletName<Name>;
67
- url: string;
68
- icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
69
- providerName?: string;
70
- provider: any;
71
- deeplinkProvider?: (data: {
72
- url: string;
73
- }) => string;
74
- openInMobileApp?: () => void;
75
- connect(): Promise<any>;
76
- disconnect: () => Promise<any>;
77
- network: () => Promise<any>;
78
- signAndSubmitTransaction?(transaction: Types.TransactionPayload | InputTransactionData | AnyRawTransaction | AptosSignAndSubmitTransactionInput, options?: InputGenerateTransactionOptions): Promise<{
79
- hash: Types.HexEncodedBytes;
80
- output?: any;
81
- } | PendingTransactionResponse | UserResponse<AptosSignAndSubmitTransactionOutput>>;
82
- submitTransaction?(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>;
83
- signMessage<T extends SignMessagePayload>(message: T): Promise<SignMessageResponse | UserResponse<AptosSignMessageOutput>>;
84
- signTransaction?(// `any` type for backwards compatibility, especially for identity connect
85
- transactionOrPayload: any, optionsOrAsFeePayer?: any): Promise<any>;
86
- account?: () => Promise<AccountInfo | StandardAccountInfo>;
87
- changeNetwork?: AptosChangeNetworkMethod;
88
- }
89
- export type AdapterPlugin<Name extends string = string> = AdapterPluginProps<Name> & AdapterPluginEvents;
90
- export type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
91
- readyState?: WalletReadyState;
92
- isAIP62Standard?: boolean;
93
- isSignTransactionV1_1?: boolean;
94
- };
95
- export interface TransactionOptions {
96
- max_gas_amount?: bigint;
97
- gas_unit_price?: bigint;
98
- }
99
- export type InputTransactionData = {
100
- sender?: AccountAddressInput;
101
- data: InputGenerateTransactionPayloadData;
102
- options?: InputGenerateTransactionOptions;
103
- };
104
- export interface PluginProvider {
105
- connect: () => Promise<AccountInfo>;
106
- account: () => Promise<AccountInfo>;
107
- disconnect: () => Promise<void>;
108
- signAndSubmitTransaction: (transaction: any, options?: any) => Promise<{
109
- hash: Types.HexEncodedBytes;
110
- } | AptosWalletErrorResult>;
111
- signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
112
- network: () => Promise<NetworkInfo>;
113
- onAccountChange: (listener: (newAddress: AccountInfo) => Promise<void>) => Promise<void>;
114
- onNetworkChange: OnNetworkChange;
115
- }
116
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/LegacyWalletPlugins/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EACL,OAAO,EACP,+BAA+B,EAC/B,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACnB,mCAAmC,EACnC,iBAAiB,EACjB,SAAS,EAEV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,mCAAmC,EACnC,sBAAsB,EACtB,YAAY,EACZ,WAAW,IAAI,mBAAmB,EAClC,WAAW,IAA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CAAC;IACpC,eAAe,EAAE,CACf,QAAQ,EAAE,CAAC,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,KACjD,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;CAClC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=WalletCore.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WalletCore.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/WalletCore.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare function scopePollingDetectionStrategy(detect: () => boolean): void;
2
- //# sourceMappingURL=scopePollingDetectionStrategy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scopePollingDetectionStrategy.d.ts","sourceRoot":"","sources":["../../src/utils/scopePollingDetectionStrategy.ts"],"names":[],"mappings":"AAAA,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,OAAO,GAAG,IAAI,CA6CzE"}
@@ -1,242 +0,0 @@
1
- import {
2
- UserResponse,
3
- AptosSignTransactionInputV1_1,
4
- AptosSignTransactionOutput,
5
- AptosSignMessageOutput,
6
- AptosSignMessageInput,
7
- AptosWallet,
8
- UserResponseStatus,
9
- AptosSignAndSubmitTransactionOutput,
10
- AccountInfo as StandardAccountInfo,
11
- AptosConnectOutput,
12
- AptosSignTransactionOutputV1_1,
13
- } from "@aptos-labs/wallet-standard";
14
- import {
15
- AnyPublicKey,
16
- AnyPublicKeyVariant,
17
- AnyRawTransaction,
18
- PendingTransactionResponse,
19
- Aptos,
20
- MultiEd25519Signature,
21
- MultiEd25519PublicKey,
22
- } from "@aptos-labs/ts-sdk";
23
-
24
- import { WalletReadyState } from "../constants";
25
- import {
26
- WalletConnectionError,
27
- WalletSignAndSubmitMessageError,
28
- WalletSignMessageAndVerifyError,
29
- WalletSignMessageError,
30
- } from "../error";
31
- import {
32
- AccountInfo,
33
- InputTransactionData,
34
- Wallet,
35
- } from "../LegacyWalletPlugins";
36
- import { generalizedErrorMessage } from "../utils";
37
-
38
- export type AptosStandardWallet = AptosWallet & {
39
- readyState?: WalletReadyState;
40
- };
41
-
42
- export class WalletStandardCore {
43
- async connect(wallet: Wallet) {
44
- const response =
45
- (await wallet.connect()) as UserResponse<AptosConnectOutput>;
46
-
47
- if (response.status === UserResponseStatus.REJECTED) {
48
- throw new WalletConnectionError("User has rejected the request").message;
49
- }
50
- return response.args;
51
- }
52
-
53
- /**
54
- * Signs and submits a transaction to chain
55
- *
56
- * @param transactionInput InputTransactionData
57
- * @returns PendingTransactionResponse
58
- */
59
- async signAndSubmitTransaction(
60
- transactionInput: InputTransactionData,
61
- aptos: Aptos,
62
- account: AccountInfo,
63
- wallet: Wallet,
64
- standardWallets: ReadonlyArray<AptosStandardWallet>,
65
- ): Promise<AptosSignAndSubmitTransactionOutput> {
66
- try {
67
- // need to find the standard wallet type to do the
68
- // next features check
69
- const standardWallet = standardWallets.find(
70
- (standardWallet: AptosStandardWallet) =>
71
- wallet.name === standardWallet.name,
72
- );
73
-
74
- // check for backward compatibility. before version 1.1.0 the standard expected
75
- // AnyRawTransaction input so the adapter built the transaction before sending it to the wallet
76
- if (
77
- standardWallet?.features["aptos:signAndSubmitTransaction"]?.version !==
78
- "1.1.0"
79
- ) {
80
- const transaction = await aptos.transaction.build.simple({
81
- sender: account.address.toString(),
82
- data: transactionInput.data,
83
- options: transactionInput.options,
84
- });
85
- const response = (await wallet.signAndSubmitTransaction!(
86
- transaction,
87
- )) as UserResponse<AptosSignAndSubmitTransactionOutput>;
88
-
89
- if (response.status === UserResponseStatus.REJECTED) {
90
- throw new WalletConnectionError("User has rejected the request")
91
- .message;
92
- }
93
-
94
- return response.args;
95
- }
96
-
97
- // build standard json format
98
- const transaction = {
99
- gasUnitPrice: transactionInput.options?.gasUnitPrice,
100
- maxGasAmount: transactionInput.options?.maxGasAmount,
101
- payload: transactionInput.data,
102
- };
103
- const response = (await wallet.signAndSubmitTransaction!(
104
- transaction,
105
- )) as UserResponse<AptosSignAndSubmitTransactionOutput>;
106
-
107
- if (response.status === UserResponseStatus.REJECTED) {
108
- throw new WalletConnectionError("User has rejected the request")
109
- .message;
110
- }
111
-
112
- return response.args;
113
- } catch (error: any) {
114
- const errMsg = generalizedErrorMessage(error);
115
- throw new WalletSignAndSubmitMessageError(errMsg).message;
116
- }
117
- }
118
-
119
- /**
120
- * Signs a transaction
121
- *
122
- * To support both existing wallet adapter V1 and V2, we support 2 input types
123
- *
124
- * @param transactionOrPayload AnyRawTransaction
125
- * @param options asFeePayer. To sign a transaction as the fee payer sponsor
126
- *
127
- * @returns AptosSignTransactionOutput
128
- */
129
- async signTransaction(
130
- transaction: AnyRawTransaction,
131
- wallet: Wallet,
132
- asFeePayer?: boolean,
133
- ): Promise<AptosSignTransactionOutput>;
134
- async signTransaction(
135
- input: AptosSignTransactionInputV1_1,
136
- wallet: Wallet,
137
- ): Promise<AptosSignTransactionOutputV1_1>;
138
- async signTransaction(
139
- transactionOrInput: AnyRawTransaction | AptosSignTransactionInputV1_1,
140
- wallet: Wallet,
141
- asFeePayer?: boolean,
142
- ): Promise<AptosSignTransactionOutput | AptosSignTransactionOutputV1_1> {
143
- const response = (await wallet.signTransaction!(
144
- transactionOrInput,
145
- asFeePayer,
146
- )) as UserResponse<AptosSignTransactionOutput>;
147
- if (response.status === UserResponseStatus.REJECTED) {
148
- throw new WalletConnectionError("User has rejected the request").message;
149
- }
150
- return response.args;
151
- }
152
-
153
- /**
154
- * Sign message
155
- *
156
- * @param message AptosSignMessageInput
157
- * @return AptosSignMessageOutput
158
- * @throws WalletSignMessageError
159
- */
160
- async signMessage(
161
- message: AptosSignMessageInput,
162
- wallet: Wallet,
163
- ): Promise<AptosSignMessageOutput> {
164
- try {
165
- const response = (await wallet.signMessage(
166
- message,
167
- )) as UserResponse<AptosSignMessageOutput>;
168
- if (response.status === UserResponseStatus.REJECTED) {
169
- throw new WalletConnectionError("User has rejected the request")
170
- .message;
171
- }
172
- return response.args;
173
- } catch (error: any) {
174
- const errMsg = generalizedErrorMessage(error);
175
- throw new WalletSignMessageError(errMsg).message;
176
- }
177
- }
178
-
179
- /**
180
- * Signs a message and verifies the signer
181
- * @param message AptosSignMessageInput
182
- * @returns boolean
183
- */
184
- async signMessageAndVerify(
185
- message: AptosSignMessageInput,
186
- wallet: Wallet,
187
- ): Promise<boolean> {
188
- try {
189
- // sign the message
190
- const response = (await wallet.signMessage(
191
- message,
192
- )) as UserResponse<AptosSignMessageOutput>;
193
- // standard wallet account() method is a required method
194
- const account = (await wallet.account!()) as StandardAccountInfo;
195
-
196
- if (response.status === UserResponseStatus.REJECTED) {
197
- throw new WalletConnectionError("Failed to sign a message").message;
198
- }
199
-
200
- // For Keyless wallet accounts we skip verification for now.
201
- // TODO: Remove when client-side verification is done in SDK.
202
- if (
203
- account.publicKey instanceof AnyPublicKey &&
204
- account.publicKey.variant === AnyPublicKeyVariant.Keyless
205
- ) {
206
- return true;
207
- }
208
-
209
- let verified = false;
210
- // if is a multi sig wallet with a MultiEd25519Signature type
211
- if (response.args.signature instanceof MultiEd25519Signature) {
212
- if (!(account.publicKey instanceof MultiEd25519PublicKey)) {
213
- throw new WalletSignMessageAndVerifyError(
214
- "Public key and Signature type mismatch",
215
- ).message;
216
- }
217
- const { fullMessage, signature } = response.args;
218
- const bitmap = signature.bitmap;
219
- if (bitmap) {
220
- const minKeysRequired = account.publicKey.threshold;
221
- if (signature.signatures.length < minKeysRequired) {
222
- verified = false;
223
- } else {
224
- verified = account.publicKey.verifySignature({
225
- message: new TextEncoder().encode(fullMessage),
226
- signature,
227
- });
228
- }
229
- }
230
- } else {
231
- verified = account.publicKey.verifySignature({
232
- message: new TextEncoder().encode(response.args.fullMessage),
233
- signature: response.args.signature,
234
- });
235
- }
236
- return verified;
237
- } catch (error: any) {
238
- const errMsg = generalizedErrorMessage(error);
239
- throw new WalletSignMessageAndVerifyError(errMsg).message;
240
- }
241
- }
242
- }
@@ -1,2 +0,0 @@
1
- export * from "./types";
2
- export * from "./WalletStandard";
@@ -1,258 +0,0 @@
1
- import { HexString, TxnBuilderTypes, Types } from "aptos";
2
- import EventEmitter from "eventemitter3";
3
- import { Buffer } from "buffer";
4
- import {
5
- InputEntryFunctionDataWithRemoteABI,
6
- InputGenerateTransactionPayloadData,
7
- generateTransactionPayload,
8
- } from "@aptos-labs/ts-sdk";
9
- import nacl from "tweetnacl";
10
- import {
11
- WalletNotSupportedMethod,
12
- WalletSignAndSubmitMessageError,
13
- WalletSignMessageAndVerifyError,
14
- WalletSignTransactionError,
15
- } from "../error";
16
- import {
17
- Wallet,
18
- WalletCoreEvents,
19
- TransactionOptions,
20
- NetworkInfo,
21
- InputTransactionData,
22
- AccountInfo,
23
- SignMessagePayload,
24
- SignMessageResponse,
25
- } from "./types";
26
-
27
- import {
28
- convertV2PayloadToV1JSONPayload,
29
- convertV2TransactionPayloadToV1BCSPayload,
30
- } from "./conversion";
31
- import {
32
- areBCSArguments,
33
- generalizedErrorMessage,
34
- getAptosConfig,
35
- } from "../utils";
36
- import { DappConfig } from "../WalletCore";
37
-
38
- export class WalletCoreV1 extends EventEmitter<WalletCoreEvents> {
39
- async connect(wallet: Wallet) {
40
- const account = await wallet.connect();
41
- return account;
42
- }
43
-
44
- /**
45
- * Resolve the transaction type (BCS arguments or Simple arguments)
46
- *
47
- * @param payloadData
48
- * @param network
49
- * @param wallet
50
- * @param transactionInput
51
- *
52
- * @returns
53
- */
54
- async resolveSignAndSubmitTransaction(
55
- payloadData: InputGenerateTransactionPayloadData,
56
- network: NetworkInfo | null,
57
- wallet: Wallet,
58
- transactionInput: InputTransactionData,
59
- dappConfig?: DappConfig,
60
- ) {
61
- // first check if each argument is a BCS serialized argument
62
- if (areBCSArguments(payloadData.functionArguments)) {
63
- const aptosConfig = getAptosConfig(network, dappConfig);
64
- const newPayload = await generateTransactionPayload({
65
- ...(payloadData as InputEntryFunctionDataWithRemoteABI),
66
- aptosConfig: aptosConfig,
67
- });
68
- const oldTransactionPayload =
69
- convertV2TransactionPayloadToV1BCSPayload(newPayload);
70
- // Call and return signAndSubmitBCSTransaction response
71
- return await this.signAndSubmitBCSTransaction(
72
- oldTransactionPayload,
73
- wallet!,
74
- {
75
- max_gas_amount: transactionInput.options?.maxGasAmount
76
- ? BigInt(transactionInput.options?.maxGasAmount)
77
- : undefined,
78
- gas_unit_price: transactionInput.options?.gasUnitPrice
79
- ? BigInt(transactionInput.options?.gasUnitPrice)
80
- : undefined,
81
- },
82
- );
83
- }
84
-
85
- // if it is not a bcs serialized arguments transaction, convert to the old
86
- // json format
87
- const oldTransactionPayload = convertV2PayloadToV1JSONPayload(payloadData);
88
- return await this.signAndSubmitTransaction(oldTransactionPayload, wallet!, {
89
- max_gas_amount: transactionInput.options?.maxGasAmount
90
- ? BigInt(transactionInput.options?.maxGasAmount)
91
- : undefined,
92
- gas_unit_price: transactionInput.options?.gasUnitPrice
93
- ? BigInt(transactionInput.options?.gasUnitPrice)
94
- : undefined,
95
- });
96
- }
97
-
98
- /**
99
- Sign and submit an entry (not bcs serialized) transaction type to chain.
100
- @param transaction a non-bcs serialized transaction
101
- @param options max_gas_amount and gas_unit_limit
102
- @return response from the wallet's signAndSubmitTransaction function
103
- @throws WalletSignAndSubmitMessageError
104
- */
105
- async signAndSubmitTransaction(
106
- transaction: Types.TransactionPayload,
107
- wallet: Wallet,
108
- options?: TransactionOptions,
109
- ): Promise<any> {
110
- try {
111
- const response = await (wallet as any).signAndSubmitTransaction(
112
- transaction,
113
- options,
114
- );
115
- return response;
116
- } catch (error: any) {
117
- const errMsg =
118
- typeof error == "object" && "message" in error ? error.message : error;
119
- throw new WalletSignAndSubmitMessageError(errMsg).message;
120
- }
121
- }
122
-
123
- /**
124
- Sign and submit a bsc serialized transaction type to chain.
125
- @param transaction a bcs serialized transaction
126
- @param options max_gas_amount and gas_unit_limit
127
- @return response from the wallet's signAndSubmitBCSTransaction function
128
- @throws WalletSignAndSubmitMessageError
129
- */
130
- async signAndSubmitBCSTransaction(
131
- transaction: TxnBuilderTypes.TransactionPayload,
132
- wallet: Wallet,
133
- options?: TransactionOptions,
134
- ): Promise<any> {
135
- if (!("signAndSubmitBCSTransaction" in wallet)) {
136
- throw new WalletNotSupportedMethod(
137
- `Submit a BCS Transaction is not supported by ${wallet.name}`,
138
- ).message;
139
- }
140
- try {
141
- const response = await (wallet as any).signAndSubmitBCSTransaction(
142
- transaction,
143
- options,
144
- );
145
- return response;
146
- } catch (error: any) {
147
- const errMsg =
148
- typeof error == "object" && "message" in error ? error.message : error;
149
- throw new WalletSignAndSubmitMessageError(errMsg).message;
150
- }
151
- }
152
-
153
- /**
154
- Sign transaction
155
- @param transaction
156
- @param options max_gas_amount and gas_unit_limit
157
- @return response from the wallet's signTransaction function
158
- @throws WalletSignTransactionError
159
- */
160
- async signTransaction(
161
- transaction: Types.TransactionPayload,
162
- wallet: Wallet,
163
- options?: TransactionOptions,
164
- ): Promise<Uint8Array | null> {
165
- try {
166
- const response = await (wallet as any).signTransaction(
167
- transaction,
168
- options,
169
- );
170
- return response;
171
- } catch (error: any) {
172
- const errMsg =
173
- typeof error == "object" && "message" in error ? error.message : error;
174
- throw new WalletSignTransactionError(errMsg).message;
175
- }
176
- }
177
-
178
- /**
179
- * Signs a message and verifies the signer
180
- * @param message SignMessagePayload
181
- * @returns boolean
182
- */
183
- async signMessageAndVerify(
184
- message: SignMessagePayload,
185
- wallet: Wallet,
186
- account: AccountInfo,
187
- ): Promise<boolean> {
188
- try {
189
- const response = await wallet.signMessage(message);
190
- if (!response)
191
- throw new WalletSignMessageAndVerifyError("Failed to sign a message")
192
- .message;
193
- console.log("signMessageAndVerify signMessage response", response);
194
-
195
- // Verify that the bytes were signed using the private key that matches the known public key
196
- let verified = false;
197
- if (Array.isArray((response as SignMessageResponse).signature)) {
198
- // multi sig wallets
199
- const { fullMessage, signature, bitmap } =
200
- response as SignMessageResponse;
201
- if (bitmap) {
202
- const minKeysRequired = account.minKeysRequired as number;
203
- if ((signature as string[]).length < minKeysRequired) {
204
- verified = false;
205
- } else {
206
- // Getting an array which marks the keys signing the message with 1, while marking 0 for the keys not being used.
207
- const bits = Array.from(bitmap).flatMap((n) =>
208
- Array.from({ length: 8 }).map((_, i) => (n >> i) & 1),
209
- );
210
- // Filter out indexes of the keys we need
211
- const index = bits.map((_, i) => i).filter((i) => bits[i]);
212
-
213
- const publicKeys = account.publicKey as string[];
214
- const matchedPublicKeys = publicKeys.filter(
215
- (_: string, i: number) => index.includes(i),
216
- );
217
-
218
- verified = true;
219
- for (let i = 0; i < (signature as string[]).length; i++) {
220
- const isSigVerified = nacl.sign.detached.verify(
221
- Buffer.from(fullMessage),
222
- Buffer.from((signature as string[])[i], "hex"),
223
- Buffer.from(matchedPublicKeys[i], "hex"),
224
- ); // `isSigVerified` should be `true` for every signature
225
-
226
- if (!isSigVerified) {
227
- verified = false;
228
- break;
229
- }
230
- }
231
- }
232
- } else {
233
- throw new WalletSignMessageAndVerifyError("Failed to get a bitmap")
234
- .message;
235
- }
236
- } else {
237
- // single sig wallets
238
- // support for when address doesnt have hex prefix (0x)
239
- const currentAccountPublicKey = new HexString(
240
- account.publicKey as string,
241
- );
242
- // support for when address doesnt have hex prefix (0x)
243
- const signature = new HexString(
244
- (response as SignMessageResponse).signature as string,
245
- );
246
- verified = nacl.sign.detached.verify(
247
- Buffer.from((response as SignMessageResponse).fullMessage),
248
- Buffer.from(signature.noPrefix(), "hex"),
249
- Buffer.from(currentAccountPublicKey.noPrefix(), "hex"),
250
- );
251
- }
252
- return verified;
253
- } catch (error: any) {
254
- const errMsg = generalizedErrorMessage(error);
255
- throw new WalletSignMessageAndVerifyError(errMsg).message;
256
- }
257
- }
258
- }