@fastxyz/fast-connector 0.1.0
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/LICENSE +21 -0
- package/README.md +115 -0
- package/dist/client.d.ts +48 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +591 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +66 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +280 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fast.xyz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# `@fastxyz/fast-connector`
|
|
2
|
+
|
|
3
|
+
Dapp-facing connector for injected Fast wallets.
|
|
4
|
+
|
|
5
|
+
## Positioning
|
|
6
|
+
|
|
7
|
+
- `@fastxyz/sdk` is the low-level Fast client layer, parallel to `viem` or `ethers`
|
|
8
|
+
- `window.fastset` is the injected wallet surface, parallel to `window.ethereum`
|
|
9
|
+
- `@fastxyz/fast-connector` is the app-facing wallet adapter layer, parallel to a wagmi injected connector or an app wrapper around `ethers.BrowserProvider(window.ethereum)`
|
|
10
|
+
|
|
11
|
+
This package is for browser apps such as InfoFi. It is not for extension-internal wallet logic.
|
|
12
|
+
|
|
13
|
+
The extension still owns:
|
|
14
|
+
|
|
15
|
+
- key management
|
|
16
|
+
- permissions and approval UI
|
|
17
|
+
- signing
|
|
18
|
+
- transaction submission
|
|
19
|
+
|
|
20
|
+
This package owns:
|
|
21
|
+
|
|
22
|
+
- injected wallet detection
|
|
23
|
+
- adapter typing
|
|
24
|
+
- dapp-facing connection state
|
|
25
|
+
- a reusable app connector over `window.fastset`
|
|
26
|
+
- optional provider-backed reads through `@fastxyz/sdk/browser`
|
|
27
|
+
- high-level transaction helpers over injected wallet methods
|
|
28
|
+
|
|
29
|
+
## Status
|
|
30
|
+
|
|
31
|
+
This repo includes:
|
|
32
|
+
|
|
33
|
+
- injected wallet detection and waiting for `fastset#initialized`
|
|
34
|
+
- connection/account state
|
|
35
|
+
- message signing
|
|
36
|
+
- provider-backed read helpers for balances, tokens, certificates, and explorer URLs
|
|
37
|
+
- high-level `transfer()` and `submitClaim()` wrappers
|
|
38
|
+
- a `@fastxyz/fast-connector/testing` entrypoint for reusable wallet mocks
|
|
39
|
+
|
|
40
|
+
It intentionally does not own onramp/vendor logic. Swapper, AllSet, and fiat adapters should live in `fast-onramp`.
|
|
41
|
+
|
|
42
|
+
## Planned Usage
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { FastConnector } from '@fastxyz/fast-connector';
|
|
46
|
+
|
|
47
|
+
const connector = FastConnector.fromInjected(window.fastset);
|
|
48
|
+
await connector.connect();
|
|
49
|
+
|
|
50
|
+
const account = await connector.exportKeys();
|
|
51
|
+
const signed = await connector.sign({ message: 'hello fast' });
|
|
52
|
+
const balance = await connector.getBalance('FAST');
|
|
53
|
+
const payment = await connector.transfer({
|
|
54
|
+
recipient: 'fast1...',
|
|
55
|
+
amount: '0x32',
|
|
56
|
+
});
|
|
57
|
+
const explorerUrl = await connector.getExplorerUrl(payment.txHash);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You can also inject a custom read provider, or let the connector build one from the installed SDK:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { FastConnector } from '@fastxyz/fast-connector';
|
|
64
|
+
|
|
65
|
+
const connector = FastConnector.fromInjected(window.fastset, {
|
|
66
|
+
providerOptions: {
|
|
67
|
+
network: 'mainnet',
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await connector.connect();
|
|
72
|
+
const tokens = await connector.getTokens();
|
|
73
|
+
const network = await connector.getNetwork();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Testing
|
|
77
|
+
|
|
78
|
+
`@fastxyz/fast-connector/testing` provides reusable mocks for app and integration tests:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { FastConnector } from '@fastxyz/fast-connector';
|
|
82
|
+
import {
|
|
83
|
+
createMockAccount,
|
|
84
|
+
createMockInjectedFastConnector,
|
|
85
|
+
dispatchFastsetInitialized,
|
|
86
|
+
} from '@fastxyz/fast-connector/testing';
|
|
87
|
+
|
|
88
|
+
const wallet = createMockInjectedFastConnector();
|
|
89
|
+
window.fastset = wallet;
|
|
90
|
+
dispatchFastsetInitialized(window);
|
|
91
|
+
|
|
92
|
+
const connector = FastConnector.fromInjected(wallet);
|
|
93
|
+
await connector.connect();
|
|
94
|
+
|
|
95
|
+
wallet.mock.emitAccountChanged(createMockAccount({
|
|
96
|
+
publicKey: 'bb'.repeat(32),
|
|
97
|
+
injected: true,
|
|
98
|
+
}));
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The testing entrypoint includes:
|
|
102
|
+
|
|
103
|
+
- mock injected wallet factory
|
|
104
|
+
- canonical and injected mock accounts
|
|
105
|
+
- mock transfer and claim certificates
|
|
106
|
+
- helpers for `fastset#initialized`
|
|
107
|
+
- helpers for account-change events
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npm install
|
|
113
|
+
npm run build
|
|
114
|
+
npm test
|
|
115
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { FastConnectorAccount, FastConnectorAdapter, FastConnectorConnectOptions, FastConnectorOptions, FastConnectorSubmitClaimParams, FastConnectorSubmitClaimResult, FastConnectorTransferParams, FastConnectorTransferResult } from './types.js';
|
|
2
|
+
export declare function getInjectedFastConnector(): FastConnectorAdapter | undefined;
|
|
3
|
+
export declare function waitForInjectedFastConnector(timeoutMs?: number): Promise<FastConnectorAdapter | undefined>;
|
|
4
|
+
export declare class FastConnector {
|
|
5
|
+
private readonly adapter;
|
|
6
|
+
private readonly customProvider?;
|
|
7
|
+
private provider?;
|
|
8
|
+
private providerNetworkKey?;
|
|
9
|
+
private readonly providerOptions?;
|
|
10
|
+
private accounts;
|
|
11
|
+
private locallyDisconnected;
|
|
12
|
+
private constructor();
|
|
13
|
+
static fromInjected(injected?: FastConnectorAdapter | undefined, options?: FastConnectorOptions): FastConnector;
|
|
14
|
+
getNetwork(): Promise<string>;
|
|
15
|
+
get address(): string | null;
|
|
16
|
+
connect(options?: FastConnectorConnectOptions): Promise<boolean>;
|
|
17
|
+
disconnect(): Promise<boolean>;
|
|
18
|
+
isConnected(): boolean;
|
|
19
|
+
getAccounts(): Promise<FastConnectorAccount[]>;
|
|
20
|
+
getActiveNetwork(): Promise<string>;
|
|
21
|
+
onAccountChanged(callback: (account: FastConnectorAccount) => void): () => void;
|
|
22
|
+
exportKeys(): Promise<FastConnectorAccount>;
|
|
23
|
+
sign(params: {
|
|
24
|
+
message: string | Uint8Array;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
signature: string;
|
|
27
|
+
address: string;
|
|
28
|
+
messageBytes: string;
|
|
29
|
+
}>;
|
|
30
|
+
transfer(params: FastConnectorTransferParams): Promise<FastConnectorTransferResult>;
|
|
31
|
+
submitClaim(params: FastConnectorSubmitClaimParams): Promise<FastConnectorSubmitClaimResult>;
|
|
32
|
+
getBalance(token?: string): Promise<{
|
|
33
|
+
amount: string;
|
|
34
|
+
token: string;
|
|
35
|
+
}>;
|
|
36
|
+
getTokens(): Promise<import("@fastxyz/sdk/core").TokenBalance[]>;
|
|
37
|
+
getTokenInfo(token: string): Promise<import("@fastxyz/sdk/core").TokenInfo | null>;
|
|
38
|
+
getCertificateByNonce(nonce: number): Promise<import("@fastxyz/sdk/core").FastTransactionCertificate | null>;
|
|
39
|
+
getExplorerUrl(txHash?: string): Promise<string | null>;
|
|
40
|
+
private captureTransactionFreshness;
|
|
41
|
+
private assertFreshTransaction;
|
|
42
|
+
private getExplorerUrlSafe;
|
|
43
|
+
private requireAccount;
|
|
44
|
+
private resolveTransferTokenId;
|
|
45
|
+
private resolveProviderNetwork;
|
|
46
|
+
private requireProvider;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,2BAA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