@near-wallet-selector/core
Advanced tools
Comparing version 3.1.0 to 4.0.0-alpha.0
@@ -1,8 +0,9 @@ | ||
import NearWalletSelector from "./lib/NearWalletSelector"; | ||
export { NetworkId, Options } from "./lib/Options"; | ||
export { NetworkConfiguration } from "./lib/network"; | ||
export { Subscription } from "./lib/services"; | ||
export { Wallet, WalletType, WalletModule, BrowserWallet, InjectedWallet, HardwareWallet, BridgeWallet, AccountInfo, Transaction, Action, ActionType, CreateAccountAction, DeployContractAction, FunctionCallAction, TransferAction, StakeAction, AddKeyAction, DeleteKeyAction, DeleteAccountAction, } from "./lib/wallet"; | ||
export { transformActions } from "./lib/wallet"; | ||
export type { WalletSelector, WalletSelectorParams, WalletSelectorEvents, WalletSelectorStore, } from "./lib/wallet-selector.types"; | ||
export { setupWalletSelector } from "./lib/wallet-selector"; | ||
export type { Network, NetworkId } from "./lib/options.types"; | ||
export type { Subscription, StorageService, JsonStorageService, } from "./lib/services"; | ||
export type { Optional } from "./lib/utils.types"; | ||
export type { WalletSelectorState, ContractState, ModuleState, AccountState, } from "./lib/store.types"; | ||
export type { WalletModuleFactory, WalletModule, WalletBehaviourFactory, WalletBehaviourOptions, Wallet, WalletType, WalletMetadata, WalletEvents, SignInParams, BrowserWalletMetadata, BrowserWalletBehaviour, BrowserWallet, InjectedWalletMetadata, InjectedWalletBehaviour, InjectedWallet, HardwareWalletMetadata, HardwareWalletSignInParams, HardwareWalletBehaviour, HardwareWallet, BridgeWalletMetadata, BridgeWalletBehaviour, BridgeWallet, Account, Transaction, Action, ActionType, CreateAccountAction, DeployContractAction, FunctionCallAction, TransferAction, StakeAction, AddKeyAction, DeleteKeyAction, DeleteAccountAction, AddKeyPermission, } from "./lib/wallet"; | ||
export type { FinalExecutionOutcome } from "near-api-js/lib/providers"; | ||
export { waitFor } from "./lib/helpers"; | ||
export default NearWalletSelector; |
export declare const PACKAGE_NAME = "near-wallet-selector"; | ||
export declare const LOCAL_STORAGE_SELECTED_WALLET_ID = "selectedWalletId"; | ||
export declare const MODAL_ELEMENT_ID = "near-wallet-selector-modal"; | ||
export declare const DEFAULT_DERIVATION_PATH = "44'/397'/0'/0'/1'"; | ||
export declare const CONTRACT = "contract"; | ||
export declare const PENDING_CONTRACT = "contract:pending"; | ||
export declare const SELECTED_WALLET_ID = "selectedWalletId"; | ||
export declare const PENDING_SELECTED_WALLET_ID = "selectedWalletId:pending"; |
export declare const waitFor: (cb: () => boolean, opts?: { | ||
timeout?: number; | ||
interval?: number; | ||
}) => Promise<unknown>; | ||
}) => Promise<boolean>; |
@@ -1,10 +0,3 @@ | ||
export interface Subscription { | ||
remove: () => void; | ||
} | ||
export interface Emitter<Events extends Record<string, unknown>> { | ||
on<EventName extends keyof Events>(eventName: EventName, callback: (event: Events[EventName]) => void): Subscription; | ||
off<EventName extends keyof Events>(eventName: EventName, callback: (event: Events[EventName]) => void): void; | ||
emit<EventName extends keyof Events>(eventName: EventName, event: Events[EventName]): void; | ||
} | ||
export declare class EventEmitter<Events extends Record<string, unknown>> implements Emitter<Events> { | ||
import type { EventEmitterService, Subscription } from "./event-emitter.types"; | ||
export declare class EventEmitter<Events extends Record<string, unknown>> implements EventEmitterService<Events> { | ||
private emitter; | ||
@@ -11,0 +4,0 @@ on<Event extends keyof Events>(eventName: Event, callback: (event: Events[Event]) => void): Subscription; |
export * from "./provider/provider.service"; | ||
export * from "./persistent-storage/persistent-storage.service"; | ||
export * from "./logger/logging.service"; | ||
export * from "./provider/provider.service.types"; | ||
export * from "./storage/storage.service.types"; | ||
export * from "./storage/json-storage.service.types"; | ||
export * from "./storage/json-storage.service"; | ||
export * from "./storage/web-storage.service"; | ||
export * from "./logger/logger.service"; | ||
export * from "./logger/logger.service.types"; | ||
export * from "./wallet-modules/wallet-modules.service"; | ||
export * from "./event-emitter/event-emitter.service"; | ||
export * from "./event-emitter/event-emitter.types"; |
import { providers } from "near-api-js"; | ||
import { AccessKeyView, BlockReference, QueryResponseKind } from "near-api-js/lib/providers/provider"; | ||
import type { AccessKeyView, BlockReference, QueryResponseKind } from "near-api-js/lib/providers/provider"; | ||
import { SignedTransaction } from "near-api-js/lib/transaction"; | ||
export declare type QueryParams = { | ||
[key in string]: unknown; | ||
}; | ||
export interface ViewAccessKeyParams { | ||
accountId: string; | ||
publicKey: string; | ||
} | ||
export declare class Provider { | ||
import type { ProviderService, QueryParams, ViewAccessKeyParams } from "./provider.service.types"; | ||
export declare class Provider implements ProviderService { | ||
private provider; | ||
@@ -13,0 +7,0 @@ constructor(url: string); |
@@ -1,2 +0,2 @@ | ||
import { QueryResponseKind } from "near-api-js/lib/providers/provider"; | ||
import type { QueryResponseKind } from "near-api-js/lib/providers/provider"; | ||
export declare const createQueryResponseMock: () => QueryResponseKind; | ||
@@ -3,0 +3,0 @@ export declare const createViewAccessKeyResponseMock: () => { |
@@ -1,3 +0,2 @@ | ||
export * from "./wallet"; | ||
export * from "./transactions"; | ||
export * from "./actions"; | ||
export * from "./wallet.types"; | ||
export * from "./transactions.types"; |
{ | ||
"name": "@near-wallet-selector/core", | ||
"version": "3.1.0", | ||
"version": "4.0.0-alpha.0", | ||
"main": "./index.umd.js", | ||
@@ -8,8 +8,6 @@ "module": "./index.esm.js", | ||
"dependencies": { | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"near-api-js": "0.44.2", | ||
"bn.js": "^5.2.0" | ||
"rxjs": "~7.4.0" | ||
}, | ||
"peerDependencies": {} | ||
} |
431
README.md
@@ -20,427 +20,32 @@ # @near-wallet-selector/core | ||
```ts | ||
import NearWalletSelector from "@near-wallet-selector/core"; | ||
import { setupWalletSelector } from "@near-wallet-selector/core"; | ||
import { setupNearWallet } from "@near-wallet-selector/near-wallet"; | ||
const selector = await NearWalletSelector.init({ | ||
// The entire set of options can be found in the section below. | ||
const selector = await setupWalletSelector({ | ||
network: "testnet", | ||
contractId: "guest-book.testnet", | ||
wallets: [setupNearWallet()], | ||
modules: [setupNearWallet()], | ||
}); | ||
``` | ||
## API Reference | ||
## Options | ||
### `.init(options)` | ||
- `network` (`NetworkId | Network`): Network ID or object matching that of your dApp configuration . Network ID can be either `mainnet`, `testnet` or `betanet`. | ||
- `networkId` (`string`): Custom network ID (e.g. `localnet`). | ||
- `nodeUrl` (`string`): Custom URL for RPC requests. | ||
- `helperUrl` (`string`): Custom URL for creating accounts. | ||
- `explorerUrl` (`string`): Custom URL for the NEAR explorer. | ||
- `debug` (`boolean?`): Enable internal logging for debugging purposes. Defaults to `false`. | ||
- `storage` (`StorageService?`): Async storage implementation. Useful when [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) is unavailable. Defaults to `localStorage`. | ||
- `modules` (`Array<WalletModuleFactory>`): List of wallets to support in your dApp. | ||
- `ui` (`ModalOptions?`) | ||
- `theme` (`Theme?`): Specify light/dark theme for UI. Defaults to the browser configuration when omitted or set to 'auto'. This can be either `light`, `dark` or `auto`. | ||
- `description` (`string?`): Define a custom description in the UI. | ||
**Parameters** | ||
## API Reference | ||
- `options` (`object`) | ||
- `network` (`string | object`): Network ID or object matching that of your dApp configuration . Network ID can be either `mainnet`, `testnet` or `betanet`. | ||
- `networkId` (`string`): Custom network ID (e.g. `localnet`). | ||
- `nodeUrl` (`string`): Custom URL for RPC requests. | ||
- `helperUrl` (`string`): Custom URL for creating accounts. | ||
- `explorerUrl` (`string`): Custom URL for | ||
- `contractId` (`string`): Account ID of the Smart Contract used for sign in and transactions. | ||
- `wallets` (`Array<string | WalletModule>`): List of wallets you want to support in your dApp. | ||
- `methodNames` (`Array<string>?`): Specify limited access to particular methods on the Smart Contract. | ||
- `ui`: (`object?`) | ||
- `theme` (`string?`): Specify light/dark theme for UI. Defaults to the browser configuration when omitted or set to 'auto'. This can be either `light`, `dark` or `auto`. | ||
- `description` (`string?`): Define a custom description in the UI. | ||
You can find the entire API reference for Wallet Selector [here](./docs/api/selector.md). | ||
**Returns** | ||
- `Promise<NearWalletSelector>` | ||
**Description** | ||
Initialises the selector using the configured options before rendering the UI. If a user has previously signed in, this method will also initialise the selected wallet, ready to handle signing. | ||
**Example** | ||
```ts | ||
await NearWalletSelector.init({ | ||
network: "testnet", | ||
contractId: "guest-book.testnet", | ||
wallets: [/* Supported wallets in your dApp */], | ||
}); | ||
``` | ||
### `.show()` | ||
****Parameters**** | ||
- N/A | ||
**Returns** | ||
- `void` | ||
**Description** | ||
Opens the modal for users to sign in to their preferred wallet. You can also use this method to switch wallets. | ||
**Example** | ||
```ts | ||
selector.show(); | ||
``` | ||
### `.hide()` | ||
**Parameters** | ||
- N/A | ||
**Returns** | ||
- `void` | ||
**Description** | ||
Closes the modal. | ||
**Example** | ||
```ts | ||
selector.hide(); | ||
``` | ||
### `.signIn(params)` | ||
**Parameters** | ||
- `params` (`object`) | ||
- `walletId` (`string`): ID of the wallet (see example for specific values). | ||
- `accountId` (`string?`): Required for hardware wallets (e.g. Ledger Wallet). This is the account ID related to the public key found at `derivationPath`. | ||
- `derviationPath` (`string?`): Required for hardware wallets (e.g. Ledger Wallet). This is the path to the public key on your device. | ||
**Returns** | ||
- `Promise<void>` | ||
**Description** | ||
Programmatically sign in to a specific wallet without presenting the UI. Hardware wallets (e.g. Ledger Wallet) require `accountId` and `derivationPath` to validate access key permissions. | ||
**Example** | ||
```ts | ||
// NEAR Wallet. | ||
await selector.signIn({ | ||
walletId: "near-wallet", | ||
}); | ||
// Sender. | ||
await selector.signIn({ | ||
walletId: "sender", | ||
}); | ||
// Math Wallet. | ||
await selector.signIn({ | ||
walletId: "math-wallet", | ||
}); | ||
// Ledger | ||
await selector.signIn({ | ||
walletId: "ledger", | ||
accountId: "account-id.testnet", | ||
derviationPath: "44'/397'/0'/0'/1'", | ||
}); | ||
// WalletConnect. | ||
await selector.signIn({ | ||
walletId: "wallet-connect", | ||
}); | ||
``` | ||
### `.signOut()` | ||
**Parameters** | ||
- N/A | ||
**Returns** | ||
- `Promise<void>` | ||
**Description** | ||
Signs out of the selected wallet. | ||
**Example** | ||
```ts | ||
await selector.signOut(); | ||
``` | ||
### `.isSignedIn()` | ||
**Parameters** | ||
- N/A | ||
**Returns** | ||
- `Promise<boolean>` | ||
**Description** | ||
Determines whether the user is signed in. | ||
**Example** | ||
```ts | ||
const signedIn = await selector.isSignedIn(); | ||
console.log(signedIn) // true | ||
``` | ||
### `.getAccounts()` | ||
**Parameters** | ||
- N/A | ||
**Returns** | ||
- `Promise<Array<object>>` | ||
- `accountId`: An account id for each account associated with the selected wallet. | ||
**Description** | ||
Retrieves account information when the user is signed in. Returns an empty array when the user is signed out. This method can be useful for wallets that support accounts at once such as WalletConnect. In this case, you can use an `accountId` returned as the `signerId` for `signAndSendTransaction`. | ||
**Example** | ||
```ts | ||
const accounts = await selector.getAccounts(); | ||
console.log(accounts); // [{ accountId: "test.testnet" }] | ||
``` | ||
### `.on(event, callback)` | ||
**Parameters** | ||
- `event` (`string`): Name of the event. This can be either `signIn` or `signOut`. | ||
- `callback` (`() => void`): Handler to be triggered when the `event` fires. | ||
**Returns** | ||
- `object` | ||
- `remove` (`() => void`): Removes the event handler. | ||
**Description** | ||
Attach an event handler to important events. | ||
**Example** | ||
```ts | ||
const subscription = selector.on("signIn", () => { | ||
console.log("User signed in!"); | ||
}); | ||
// Unsubscribe. | ||
subscription.remove(); | ||
``` | ||
### `.off(event, callback)` | ||
**Parameters** | ||
- `event` (`string`): Name of the event. This can be either `signIn` or `signOut`. | ||
- `callback` (`() => void`): Original handler passed to `.on(event, callback)`. | ||
**Returns** | ||
- `void` | ||
**Description** | ||
Removes the event handler attached to the given `event`. | ||
**Example** | ||
```ts | ||
const handleSignIn = () => { | ||
console.log("User signed in!"); | ||
} | ||
selector.on("signIn", handleSignIn); | ||
selector.off("signIn", handleSignIn); | ||
``` | ||
### `.getContractId()` | ||
**Parameters** | ||
- N/A | ||
**Returns** | ||
- `string` | ||
**Description** | ||
Retrieves account ID of the configured Smart Contract. | ||
**Example** | ||
```ts | ||
const contractId = selector.getContractId(); | ||
console.log(contractId); // "guest-book.testnet" | ||
``` | ||
### `.signAndSendTransaction(params)` | ||
**Parameters** | ||
- `params` (`object`) | ||
- `signerId` (`string?`): Account ID used to sign the transaction. Defaults to the first account. | ||
- `receiverId` (`string?`): Account ID to receive the transaction. Defaults to `contractId` defined in `.init`. | ||
- `actions` (`Array<Action>`) | ||
- `type` (`string`): Action type. See below for available values. | ||
- `params` (`object?`): Parameters for the Action (if applicable). | ||
- `callbackUrl` (`string?`): Applicable to browser wallets (e.g. NEAR Wallet). This the callback url once the transaction is approved. | ||
**Returns** | ||
- `Promise<void | object>`: Browser wallets won't return the transaction outcome as they may need to redirect for signing. More details on this can be found [here](https://docs.near.org/docs/api/rpc/transactions#send-transaction-await). | ||
**Description** | ||
Signs one or more actions before sending to the network. The user must be signed in to call this method as there's at least charges for gas spent. | ||
Note: Sender only supports `"FunctionCall"` action types right now. If you wish to use other NEAR Actions in your dApp, it's recommended to remove this wallet in your configuration. | ||
Below are the 8 supported NEAR Actions: | ||
```ts | ||
export interface CreateAccountAction { | ||
type: "CreateAccount"; | ||
} | ||
export interface DeployContractAction { | ||
type: "DeployContract"; | ||
params: { | ||
code: Uint8Array; | ||
}; | ||
} | ||
export interface FunctionCallAction { | ||
type: "FunctionCall"; | ||
params: { | ||
methodName: string; | ||
args: object; | ||
gas: string; | ||
deposit: string; | ||
}; | ||
} | ||
export interface TransferAction { | ||
type: "Transfer"; | ||
params: { | ||
deposit: string; | ||
}; | ||
} | ||
export interface StakeAction { | ||
type: "Stake"; | ||
params: { | ||
stake: string; | ||
publicKey: string; | ||
}; | ||
} | ||
export interface AddKeyAction { | ||
type: "AddKey"; | ||
params: { | ||
publicKey: string; | ||
accessKey: { | ||
nonce?: number; | ||
permission: | ||
| "FullAccess" | ||
| { | ||
receiverId: string; | ||
allowance?: string; | ||
methodNames?: Array<string>; | ||
}; | ||
}; | ||
}; | ||
} | ||
export interface DeleteKeyAction { | ||
type: "DeleteKey"; | ||
params: { | ||
publicKey: string; | ||
}; | ||
} | ||
export interface DeleteAccountAction { | ||
type: "DeleteAccount"; | ||
params: { | ||
beneficiaryId: string; | ||
}; | ||
} | ||
``` | ||
**Example** | ||
```ts | ||
await selector.signAndSendTransaction({ | ||
actions: [{ | ||
type: "FunctionCall", | ||
params: { | ||
methodName: "addMessage", | ||
args: { text: "Hello World!" }, | ||
gas: "30000000000000", | ||
deposit: "10000000000000000000000", | ||
} | ||
}] | ||
}); | ||
``` | ||
### `.signAndSendTransactions(params)` | ||
**Parameters** | ||
- `params` (`object`) | ||
- `transactions` (`Array<Transaction>`) | ||
- `signerId` (`string?`): Account ID used to sign the transaction. Defaults to the first account. | ||
- `receiverId` (`string`): Account ID to receive the transaction. | ||
- `actions` (`Array<Action>`) | ||
- `type` (`string`): Action type. See above for available values. | ||
- `params` (`object?`): Parameters for the Action (if applicable). | ||
- `callbackUrl` (`string?`): Applicable to browser wallets (e.g. NEAR Wallet). This the callback url once the transactions are approved. | ||
**Returns** | ||
- `Promise<void | Array<object>>`: Browser wallets won't return the transaction outcomes as they may need to redirect for signing. More details on this can be found [here](https://docs.near.org/docs/api/rpc/transactions#send-transaction-await). | ||
**Description** | ||
Signs one or more transactions before sending to the network. The user must be signed in to call this method as there's at least charges for gas spent. | ||
Note: Sender only supports `"FunctionCall"` action types right now. If you wish to use other NEAR Actions in your dApp, it's recommended to remove this wallet in your configuration. | ||
**Example** | ||
```ts | ||
await selector.signAndSendTransactions({ | ||
transactions: [{ | ||
receiverId: "guest-book.testnet", | ||
actions: [{ | ||
type: "FunctionCall", | ||
params: { | ||
methodName: "addMessage", | ||
args: { text: "Hello World!" }, | ||
gas: "30000000000000", | ||
deposit: "10000000000000000000000", | ||
} | ||
}] | ||
}] | ||
}); | ||
``` | ||
## License | ||
This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
34
386694
10198
2
51
+ Addedrxjs@~7.4.0
+ Addedrxjs@7.4.0(transitive)
+ Addedtslib@2.1.0(transitive)
- Removedbn.js@^5.2.0
- Removedreact@^17.0.2
- Removedreact-dom@^17.0.2
- Removedbn.js@5.2.1(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedreact@17.0.2(transitive)
- Removedreact-dom@17.0.2(transitive)
- Removedscheduler@0.20.2(transitive)