@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.ts +0 -46
@@ -1,124 +0,0 @@
1
- import {
2
- Network,
3
- TransactionPayload,
4
- InputGenerateTransactionPayloadData,
5
- TypeTag,
6
- AptosConfig,
7
- InputEntryFunctionData,
8
- InputMultiSigData,
9
- MoveFunctionId,
10
- generateTransactionPayload,
11
- TransactionPayloadEntryFunction,
12
- } from "@aptos-labs/ts-sdk";
13
- import { NetworkInfo as StandardNetworkInfo } from "@aptos-labs/wallet-standard";
14
- import { BCS, TxnBuilderTypes, Types } from "aptos";
15
- import { NetworkInfo } from "./types";
16
-
17
- // old => new
18
- export function convertNetwork(
19
- networkInfo: NetworkInfo | StandardNetworkInfo | null,
20
- ): Network {
21
- switch (networkInfo?.name) {
22
- case "mainnet" as Network:
23
- return Network.MAINNET;
24
- case "testnet" as Network:
25
- return Network.TESTNET;
26
- case "devnet" as Network:
27
- return Network.DEVNET;
28
- case "local" as Network:
29
- return Network.LOCAL;
30
- default:
31
- throw new Error("Invalid Aptos network name");
32
- }
33
- }
34
-
35
- // new => old
36
- export function convertV2TransactionPayloadToV1BCSPayload(
37
- payload: TransactionPayload,
38
- ): TxnBuilderTypes.TransactionPayload {
39
- const deserializer = new BCS.Deserializer(payload.bcsToBytes());
40
- return TxnBuilderTypes.TransactionPayload.deserialize(deserializer);
41
- }
42
-
43
- export function convertV2PayloadToV1JSONPayload(
44
- payload: InputGenerateTransactionPayloadData,
45
- ): Types.TransactionPayload {
46
- if ("bytecode" in payload) {
47
- // is a script payload
48
- throw new Error("script payload not supported");
49
- // is multisig function payload
50
- } else if ("multisigAddress" in payload) {
51
- const stringTypeTags: string[] | undefined = payload.typeArguments?.map(
52
- (typeTag) => {
53
- if (typeTag instanceof TypeTag) {
54
- return typeTag.toString();
55
- }
56
- return typeTag;
57
- },
58
- );
59
- const newPayload: Types.TransactionPayload = {
60
- type: "multisig_payload",
61
- multisig_address: payload.multisigAddress.toString(),
62
- function: payload.function,
63
- type_arguments: stringTypeTags || [],
64
- arguments: payload.functionArguments,
65
- };
66
-
67
- return newPayload;
68
- } else {
69
- // is entry function payload
70
- const stringTypeTags: string[] | undefined = payload.typeArguments?.map(
71
- (typeTag) => {
72
- if (typeTag instanceof TypeTag) {
73
- return typeTag.toString();
74
- }
75
- return typeTag;
76
- },
77
- );
78
- const newPayload: Types.TransactionPayload = {
79
- type: "entry_function_payload",
80
- function: payload.function,
81
- type_arguments: stringTypeTags || [],
82
- arguments: payload.functionArguments,
83
- };
84
-
85
- return newPayload;
86
- }
87
- }
88
-
89
- export function convertPayloadInputV1ToV2(inputV1: Types.TransactionPayload) {
90
- if ("function" in inputV1) {
91
- const inputV2: InputEntryFunctionData | InputMultiSigData = {
92
- function: inputV1.function as MoveFunctionId,
93
- functionArguments: inputV1.arguments,
94
- typeArguments: inputV1.type_arguments,
95
- };
96
- return inputV2;
97
- }
98
-
99
- throw new Error("Payload type not supported");
100
- }
101
-
102
- export async function generateTransactionPayloadFromV1Input(
103
- aptosConfig: AptosConfig,
104
- inputV1: Types.TransactionPayload,
105
- ): Promise<TransactionPayloadEntryFunction> {
106
- if ("function" in inputV1) {
107
- const inputV2 = convertPayloadInputV1ToV2(inputV1);
108
- return generateTransactionPayload({ ...inputV2, aptosConfig });
109
- }
110
-
111
- throw new Error("Payload type not supported");
112
- }
113
-
114
- export interface CompatibleTransactionOptions {
115
- expireTimestamp?: number;
116
- expirationSecondsFromNow?: number;
117
- expirationTimestamp?: number;
118
- gasUnitPrice?: number;
119
- gas_unit_price?: number;
120
- maxGasAmount?: number;
121
- max_gas_amount?: number;
122
- sender?: string;
123
- sequenceNumber?: number;
124
- }
@@ -1,3 +0,0 @@
1
- export * from "./WalletCoreV1";
2
- export * from "./conversion";
3
- export * from "./types";
@@ -1,188 +0,0 @@
1
- import { Types } from "aptos";
2
- import {
3
- Network,
4
- InputGenerateTransactionOptions,
5
- InputSubmitTransactionData,
6
- PendingTransactionResponse,
7
- AccountAddressInput,
8
- InputGenerateTransactionPayloadData,
9
- AnyRawTransaction,
10
- Signature,
11
- AccountAuthenticator,
12
- } from "@aptos-labs/ts-sdk";
13
- import { WalletReadyState } from "../constants";
14
- import {
15
- AptosSignAndSubmitTransactionOutput,
16
- AptosSignMessageOutput,
17
- UserResponse,
18
- AccountInfo as StandardAccountInfo,
19
- NetworkInfo as StandardNetworkInfo,
20
- AptosChangeNetworkMethod,
21
- AptosSignAndSubmitTransactionInput,
22
- } from "@aptos-labs/wallet-standard";
23
- import { AptosStandardSupportedWallet } from "../AIP62StandardWallets/types";
24
-
25
- export { TxnBuilderTypes, Types } from "aptos";
26
- export type {
27
- InputGenerateTransactionData,
28
- InputGenerateTransactionOptions,
29
- AnyRawTransaction,
30
- InputSubmitTransactionData,
31
- PendingTransactionResponse,
32
- AccountAuthenticator,
33
- Network,
34
- } from "@aptos-labs/ts-sdk";
35
-
36
- export type {
37
- NetworkInfo as StandardNetworkInfo,
38
- AptosChangeNetworkOutput,
39
- } from "@aptos-labs/wallet-standard";
40
-
41
- // WalletName is a nominal type that wallet adapters should use, e.g. `'MyCryptoWallet' as WalletName<'MyCryptoWallet'>`
42
- export type WalletName<T extends string = string> = T & {
43
- __brand__: "WalletName";
44
- };
45
-
46
- export type NetworkInfo = {
47
- name: Network;
48
- chainId?: string;
49
- url?: string;
50
- };
51
-
52
- export type WalletInfo = {
53
- name: WalletName;
54
- icon: string;
55
- url: string;
56
- };
57
-
58
- export type AccountInfo = {
59
- address: string;
60
- publicKey: string | string[];
61
- minKeysRequired?: number;
62
- ansName?: string | null;
63
- };
64
-
65
- export interface AptosWalletErrorResult {
66
- code: number;
67
- name: string;
68
- message: string;
69
- }
70
-
71
- export declare interface WalletCoreEvents {
72
- connect(account: AccountInfo | null): void;
73
- disconnect(): void;
74
- readyStateChange(wallet: Wallet): void;
75
- standardWalletsAdded(wallets: Wallet | AptosStandardSupportedWallet): void;
76
- networkChange(network: NetworkInfo | null): void;
77
- accountChange(account: AccountInfo | null): void;
78
- }
79
-
80
- export interface SignMessagePayload {
81
- address?: boolean; // Should we include the address of the account in the message
82
- application?: boolean; // Should we include the domain of the dapp
83
- chainId?: boolean; // Should we include the current chain id the wallet is connected to
84
- message: string; // The message to be signed and displayed to the user
85
- nonce: string; // A nonce the dapp should generate
86
- }
87
-
88
- export interface SignMessageResponse {
89
- address?: string;
90
- application?: string;
91
- chainId?: number;
92
- fullMessage: string; // The message that was generated to sign
93
- message: string; // The message passed in by the user
94
- nonce: string;
95
- prefix: "APTOS"; // Should always be APTOS
96
- signature: string | string[] | Signature; // The signed full message
97
- bitmap?: Uint8Array; // a 4-byte (32 bits) bit-vector of length N
98
- }
99
-
100
- export type OnNetworkChange = (
101
- callBack: (networkInfo: NetworkInfo | StandardNetworkInfo) => Promise<void>,
102
- ) => Promise<void>;
103
-
104
- export type OnAccountChange = (
105
- callBack: (accountInfo: AccountInfo | StandardAccountInfo) => Promise<any>,
106
- ) => Promise<void>;
107
-
108
- export interface AdapterPluginEvents {
109
- onNetworkChange: OnNetworkChange;
110
- onAccountChange: OnAccountChange;
111
- }
112
-
113
- // TODO add signTransaction()
114
- export interface AdapterPluginProps<Name extends string = string> {
115
- name: WalletName<Name>;
116
- url: string;
117
- icon: `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
118
- providerName?: string;
119
- provider: any;
120
- // Compatible with legacy wallet plugin
121
- deeplinkProvider?: (data: { url: string }) => string;
122
- // Comaptible with AIP-62 standard wallet
123
- openInMobileApp?: () => void;
124
- connect(): Promise<any>;
125
- disconnect: () => Promise<any>;
126
- network: () => Promise<any>;
127
- signAndSubmitTransaction?(
128
- transaction:
129
- | Types.TransactionPayload
130
- | InputTransactionData
131
- | AnyRawTransaction
132
- | AptosSignAndSubmitTransactionInput,
133
- options?: InputGenerateTransactionOptions,
134
- ): Promise<
135
- | { hash: Types.HexEncodedBytes; output?: any }
136
- | PendingTransactionResponse
137
- | UserResponse<AptosSignAndSubmitTransactionOutput>
138
- >;
139
- submitTransaction?(
140
- transaction: InputSubmitTransactionData,
141
- ): Promise<PendingTransactionResponse>;
142
- signMessage<T extends SignMessagePayload>(
143
- message: T,
144
- ): Promise<SignMessageResponse | UserResponse<AptosSignMessageOutput>>;
145
- signTransaction?( // `any` type for backwards compatibility, especially for identity connect
146
- transactionOrPayload: any,
147
- optionsOrAsFeePayer?: any,
148
- ): Promise<any>;
149
- account?: () => Promise<AccountInfo | StandardAccountInfo>;
150
- changeNetwork?: AptosChangeNetworkMethod;
151
- }
152
-
153
- export type AdapterPlugin<Name extends string = string> =
154
- AdapterPluginProps<Name> & AdapterPluginEvents;
155
-
156
- export type Wallet<Name extends string = string> = AdapterPlugin<Name> & {
157
- readyState?: WalletReadyState;
158
- isAIP62Standard?: boolean;
159
- isSignTransactionV1_1?: boolean;
160
- };
161
-
162
- export interface TransactionOptions {
163
- max_gas_amount?: bigint;
164
- gas_unit_price?: bigint;
165
- }
166
-
167
- export type InputTransactionData = {
168
- sender?: AccountAddressInput;
169
- data: InputGenerateTransactionPayloadData;
170
- options?: InputGenerateTransactionOptions;
171
- };
172
-
173
- // To be used by a wallet plugin
174
- export interface PluginProvider {
175
- connect: () => Promise<AccountInfo>;
176
- account: () => Promise<AccountInfo>;
177
- disconnect: () => Promise<void>;
178
- signAndSubmitTransaction: (
179
- transaction: any,
180
- options?: any,
181
- ) => Promise<{ hash: Types.HexEncodedBytes } | AptosWalletErrorResult>;
182
- signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
183
- network: () => Promise<NetworkInfo>;
184
- onAccountChange: (
185
- listener: (newAddress: AccountInfo) => Promise<void>,
186
- ) => Promise<void>;
187
- onNetworkChange: OnNetworkChange;
188
- }
@@ -1,46 +0,0 @@
1
- export function scopePollingDetectionStrategy(detect: () => boolean): void {
2
- // Early return when server-side rendering
3
- if (typeof window === "undefined" || typeof document === "undefined") return;
4
-
5
- const disposers: (() => void)[] = [];
6
-
7
- function detectAndDispose() {
8
- const detected = detect();
9
- if (detected) {
10
- for (const dispose of disposers) {
11
- dispose();
12
- }
13
- }
14
- }
15
-
16
- // Strategy #1: Try detecting every second.
17
- const interval =
18
- // TODO: #334 Replace with idle callback strategy.
19
- setInterval(detectAndDispose, 1000);
20
- disposers.push(() => clearInterval(interval));
21
-
22
- // Strategy #2: Detect as soon as the DOM becomes 'ready'/'interactive'.
23
- if (
24
- // Implies that `DOMContentLoaded` has not yet fired.
25
- document.readyState === "loading"
26
- ) {
27
- document.addEventListener("DOMContentLoaded", detectAndDispose, {
28
- once: true,
29
- });
30
- disposers.push(() =>
31
- document.removeEventListener("DOMContentLoaded", detectAndDispose),
32
- );
33
- }
34
-
35
- // Strategy #3: Detect after the `window` has fully loaded.
36
- if (
37
- // If the `complete` state has been reached, we're too late.
38
- document.readyState !== "complete"
39
- ) {
40
- window.addEventListener("load", detectAndDispose, { once: true });
41
- disposers.push(() => window.removeEventListener("load", detectAndDispose));
42
- }
43
-
44
- // Strategy #4: Detect synchronously, now.
45
- detectAndDispose();
46
- }