accounts 0.2.1 → 0.4.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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +71 -71
- package/dist/core/AccessKey.d.ts +55 -0
- package/dist/core/AccessKey.d.ts.map +1 -0
- package/dist/core/AccessKey.js +69 -0
- package/dist/core/AccessKey.js.map +1 -0
- package/dist/core/Account.d.ts +91 -0
- package/dist/core/Account.d.ts.map +1 -0
- package/dist/core/Account.js +64 -0
- package/dist/core/Account.js.map +1 -0
- package/dist/core/Adapter.d.ts +187 -0
- package/dist/core/Adapter.d.ts.map +1 -0
- package/dist/core/Adapter.js +7 -0
- package/dist/core/Adapter.js.map +1 -0
- package/dist/core/Ceremony.d.ts +109 -0
- package/dist/core/Ceremony.d.ts.map +1 -0
- package/dist/core/Ceremony.js +104 -0
- package/dist/core/Ceremony.js.map +1 -0
- package/dist/core/Client.d.ts +16 -0
- package/dist/core/Client.d.ts.map +1 -0
- package/dist/core/Client.js +18 -0
- package/dist/core/Client.js.map +1 -0
- package/dist/core/Dialog.d.ts +52 -0
- package/dist/core/Dialog.d.ts.map +1 -0
- package/dist/core/Dialog.js +342 -0
- package/dist/core/Dialog.js.map +1 -0
- package/dist/core/Expiry.d.ts +15 -0
- package/dist/core/Expiry.d.ts.map +1 -0
- package/dist/core/Expiry.js +29 -0
- package/dist/core/Expiry.js.map +1 -0
- package/dist/core/Messenger.d.ts +86 -0
- package/dist/core/Messenger.d.ts.map +1 -0
- package/dist/core/Messenger.js +127 -0
- package/dist/core/Messenger.js.map +1 -0
- package/dist/core/Provider.d.ts +69 -0
- package/dist/core/Provider.d.ts.map +1 -0
- package/dist/core/Provider.js +401 -0
- package/dist/core/Provider.js.map +1 -0
- package/dist/core/Remote.d.ts +114 -0
- package/dist/core/Remote.d.ts.map +1 -0
- package/dist/core/Remote.js +116 -0
- package/dist/core/Remote.js.map +1 -0
- package/dist/core/Schema.d.ts +805 -0
- package/dist/core/Schema.d.ts.map +1 -0
- package/dist/core/Schema.js +43 -0
- package/dist/core/Schema.js.map +1 -0
- package/dist/core/Storage.d.ts +42 -0
- package/dist/core/Storage.d.ts.map +1 -0
- package/dist/core/Storage.js +173 -0
- package/dist/core/Storage.js.map +1 -0
- package/dist/core/Store.d.ts +58 -0
- package/dist/core/Store.d.ts.map +1 -0
- package/dist/core/Store.js +58 -0
- package/dist/core/Store.js.map +1 -0
- package/dist/core/adapters/dangerous_secp256k1.d.ts +30 -0
- package/dist/core/adapters/dangerous_secp256k1.d.ts.map +1 -0
- package/dist/core/adapters/dangerous_secp256k1.js +39 -0
- package/dist/core/adapters/dangerous_secp256k1.js.map +1 -0
- package/dist/core/adapters/dialog.d.ts +31 -0
- package/dist/core/adapters/dialog.d.ts.map +1 -0
- package/dist/core/adapters/dialog.js +306 -0
- package/dist/core/adapters/dialog.js.map +1 -0
- package/dist/core/adapters/local.d.ts +33 -0
- package/dist/core/adapters/local.d.ts.map +1 -0
- package/dist/core/adapters/local.js +227 -0
- package/dist/core/adapters/local.js.map +1 -0
- package/dist/core/adapters/webAuthn.d.ts +36 -0
- package/dist/core/adapters/webAuthn.d.ts.map +1 -0
- package/dist/core/adapters/webAuthn.js +93 -0
- package/dist/core/adapters/webAuthn.js.map +1 -0
- package/dist/core/internal/withDedupe.d.ts +12 -0
- package/dist/core/internal/withDedupe.d.ts.map +1 -0
- package/dist/core/internal/withDedupe.js +12 -0
- package/dist/core/internal/withDedupe.js.map +1 -0
- package/dist/core/zod/request.d.ts +31 -0
- package/dist/core/zod/request.d.ts.map +1 -0
- package/dist/core/zod/request.js +41 -0
- package/dist/core/zod/request.js.map +1 -0
- package/dist/core/zod/rpc.d.ts +603 -0
- package/dist/core/zod/rpc.d.ts.map +1 -0
- package/dist/core/zod/rpc.js +293 -0
- package/dist/core/zod/rpc.js.map +1 -0
- package/dist/core/zod/utils.d.ts +18 -0
- package/dist/core/zod/utils.d.ts.map +1 -0
- package/dist/core/zod/utils.js +21 -0
- package/dist/core/zod/utils.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/types.d.ts +284 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +2 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/server/Handler.d.ts +257 -0
- package/dist/server/Handler.d.ts.map +1 -0
- package/dist/server/Handler.js +433 -0
- package/dist/server/Handler.js.map +1 -0
- package/dist/server/Kv.d.ts +16 -0
- package/dist/server/Kv.d.ts.map +1 -0
- package/dist/server/Kv.js +30 -0
- package/dist/server/Kv.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/internal/requestListener.d.ts +124 -0
- package/dist/server/internal/requestListener.d.ts.map +1 -0
- package/dist/server/internal/requestListener.js +173 -0
- package/dist/server/internal/requestListener.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +93 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +238 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/index.d.ts +3 -0
- package/dist/wagmi/index.d.ts.map +1 -0
- package/dist/wagmi/index.js +3 -0
- package/dist/wagmi/index.js.map +1 -0
- package/package.json +103 -28
- package/src/core/AccessKey.test.ts +257 -0
- package/src/core/AccessKey.ts +123 -0
- package/src/core/Account.test.ts +309 -0
- package/src/core/Account.ts +152 -0
- package/src/core/Adapter.ts +238 -0
- package/src/core/Ceremony.browser.test.ts +239 -0
- package/src/core/Ceremony.test.ts +151 -0
- package/src/core/Ceremony.ts +203 -0
- package/src/core/Client.ts +36 -0
- package/src/core/Dialog.browser.test.ts +309 -0
- package/src/core/Dialog.test-d.ts +19 -0
- package/src/core/Dialog.ts +442 -0
- package/src/core/Expiry.ts +34 -0
- package/src/core/Messenger.ts +206 -0
- package/src/core/Provider.browser.test.ts +774 -0
- package/src/core/Provider.connect.browser.test.ts +415 -0
- package/src/core/Provider.test-d.ts +53 -0
- package/src/core/Provider.test.ts +1566 -0
- package/src/core/Provider.ts +559 -0
- package/src/core/Remote.ts +262 -0
- package/src/core/Schema.test-d.ts +211 -0
- package/src/core/Schema.ts +143 -0
- package/src/core/Storage.ts +213 -0
- package/src/core/Store.test.ts +287 -0
- package/src/core/Store.ts +129 -0
- package/src/core/adapters/dangerous_secp256k1.ts +53 -0
- package/src/core/adapters/dialog.ts +379 -0
- package/src/core/adapters/local.test.ts +97 -0
- package/src/core/adapters/local.ts +277 -0
- package/src/core/adapters/webAuthn.ts +129 -0
- package/src/core/internal/withDedupe.test.ts +116 -0
- package/src/core/internal/withDedupe.ts +20 -0
- package/src/core/mppx.test.ts +83 -0
- package/src/core/zod/request.test.ts +121 -0
- package/src/core/zod/request.ts +70 -0
- package/src/core/zod/rpc.ts +374 -0
- package/src/core/zod/utils.test.ts +69 -0
- package/src/core/zod/utils.ts +40 -0
- package/src/index.ts +14 -0
- package/src/internal/types.ts +378 -0
- package/src/server/Handler.test.ts +1014 -0
- package/src/server/Handler.ts +605 -0
- package/src/server/Kv.ts +46 -0
- package/src/server/index.ts +2 -0
- package/src/server/internal/requestListener.ts +273 -0
- package/src/tsconfig.json +9 -0
- package/src/wagmi/Connector.ts +287 -0
- package/src/wagmi/index.ts +2 -0
- package/lib/admin/hooks.js +0 -26
- package/lib/admin/index.js +0 -14
- package/lib/admin/methods.js +0 -6
- package/lib/app.js +0 -50
- package/lib/apps/helpers.js +0 -11
- package/lib/apps/hooks.js +0 -32
- package/lib/apps/index.js +0 -25
- package/lib/apps/methods.js +0 -23
- package/lib/apps/schemas.js +0 -49
- package/lib/fields/helpers.js +0 -8
- package/lib/fields/hooks.js +0 -30
- package/lib/fields/index.js +0 -26
- package/lib/fields/methods.js +0 -13
- package/lib/fields/schemas.js +0 -19
- package/lib/identities/helpers.js +0 -20
- package/lib/identities/hooks.js +0 -30
- package/lib/identities/index.js +0 -26
- package/lib/identities/methods.js +0 -61
- package/lib/identities/schemas.js +0 -137
- package/lib/index.js +0 -51
- package/lib/login.js +0 -61
- package/lib/options.js +0 -21
- package/lib/storage_bind.js +0 -96
- package/lib/user_profile.js +0 -44
- package/lib/users/helpers.js +0 -26
- package/lib/users/hooks.js +0 -30
- package/lib/users/index.js +0 -26
- package/lib/users/methods.js +0 -43
- package/lib/users/schemas.js +0 -112
- package/lib/utils.js +0 -18
- package/lib/validator.js +0 -46
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present weth, LLC
|
|
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
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tempo Accounts SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Accounts SDK for Tempo Wallets & Apps.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm i accounts
|
|
9
|
+
```
|
|
6
10
|
|
|
7
11
|
## Usage
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
### Vanilla JS
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var Accounts = require('accounts')(storage, options);
|
|
14
|
-
var appId;
|
|
15
|
-
|
|
16
|
-
Accounts.apps.create({
|
|
17
|
-
name: 'Test app'
|
|
18
|
-
}).then(function(app) {
|
|
19
|
-
appId = app.id;
|
|
20
|
-
});
|
|
21
|
-
```
|
|
15
|
+
You can get set up with the Accounts SDK with pure JavaScript by using the
|
|
16
|
+
`Provider` instance.
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var Accounts = require('accounts')(storage);
|
|
26
|
-
var appId = process.env.ACCOUNTS_APP_ID;
|
|
27
|
-
var App = Accounts.app(appId);
|
|
28
|
-
|
|
29
|
-
App.login('social', profile)
|
|
30
|
-
.then(function(user) {
|
|
31
|
-
if (user) {
|
|
32
|
-
console.log(user);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
console.log('login faild');
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
```
|
|
39
|
-
Where `Profile` is a Passport [User Profile](http://passportjs.org/guide/profile/)
|
|
40
|
-
```
|
|
41
|
-
var profile = {
|
|
42
|
-
provider: 'facebook',
|
|
43
|
-
id: '123124234235123',
|
|
44
|
-
displayName: 'Dumitru K',
|
|
45
|
-
accessData: {
|
|
46
|
-
accessToken:'dsgsgs', refreshToken:'gerge'
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
```
|
|
18
|
+
Internally, the `Provider` utilizes [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963) to inject it's provider instance into
|
|
19
|
+
the page so it can be picked up by wallet connection dialogs on external web applications.
|
|
50
20
|
|
|
51
|
-
|
|
21
|
+
```tsx
|
|
22
|
+
import { Provider } from 'accounts'
|
|
52
23
|
|
|
53
|
-
|
|
24
|
+
const provider = Provider.create()
|
|
54
25
|
|
|
55
|
-
|
|
26
|
+
const { accounts } = await provider.request({
|
|
27
|
+
method: 'wallet_connect',
|
|
28
|
+
})
|
|
29
|
+
```
|
|
56
30
|
|
|
57
|
-
|
|
31
|
+
### Viem
|
|
58
32
|
|
|
59
|
-
|
|
33
|
+
The Provider provides a Viem Client instance via the `getClient` accessor.
|
|
60
34
|
|
|
61
|
-
|
|
62
|
-
|
|
35
|
+
```tsx
|
|
36
|
+
import { Provider } from 'accounts'
|
|
63
37
|
|
|
64
|
-
|
|
38
|
+
const provider = Provider.create()
|
|
65
39
|
|
|
66
|
-
|
|
67
|
-
|
|
40
|
+
const client = provider.getClient()
|
|
41
|
+
```
|
|
68
42
|
|
|
69
|
-
###
|
|
43
|
+
### Wagmi
|
|
70
44
|
|
|
71
|
-
|
|
45
|
+
Use the `tempoWallet` Wagmi connector to allow your Wagmi application to enable the Tempo Wallet dialog.
|
|
72
46
|
|
|
73
|
-
|
|
47
|
+
```tsx
|
|
48
|
+
import { createConfig, http } from 'wagmi'
|
|
49
|
+
import { tempo } from 'wagmi/chains'
|
|
50
|
+
import { tempoWallet } from 'accounts/wagmi'
|
|
74
51
|
|
|
75
|
-
|
|
52
|
+
export const wagmiConfig = createConfig({
|
|
53
|
+
chains: [tempo],
|
|
54
|
+
connectors: [tempoWallet()],
|
|
55
|
+
transports: {
|
|
56
|
+
[tempo.id]: http(),
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
```
|
|
76
60
|
|
|
77
|
-
|
|
61
|
+
## Adapters
|
|
62
|
+
|
|
63
|
+
| Adapter | Description |
|
|
64
|
+
| ------------------------ | ---------------------------------------------------------------------------------- |
|
|
65
|
+
| `dialog` / `tempoWallet` | Adapter for the Tempo Wallet dialog (an embedded iframe/popup dialog). |
|
|
66
|
+
| `webAuthn` | App-bound passkey accounts using WebAuthn registration and authentication flows. |
|
|
67
|
+
| `local` | Key agnostic adapter to define arbitrary account/key types and signing mechanisms. |
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
pnpm dev # start embed + embed-ref + playground dev servers
|
|
73
|
+
pnpm dev:embed # start Tempo Wallet embed only
|
|
74
|
+
pnpm dev:embed-ref # start reference embed implementation only (port 5174)
|
|
75
|
+
pnpm dev:playground # start playground app only
|
|
76
|
+
pnpm dev:hosts # start embed + playground instances on different TLDs
|
|
77
|
+
pnpm build # build library
|
|
78
|
+
pnpm check # lint + format
|
|
79
|
+
pnpm check:types # type checks
|
|
80
|
+
pnpm test # run tests
|
|
81
|
+
```
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
> `pnpm dev:hosts` starts three dev servers on different domains for cross-origin testing:
|
|
84
|
+
>
|
|
85
|
+
> - `https://app.moderato.tempo.local:3001`
|
|
86
|
+
> - `https://playground.a:5173`
|
|
87
|
+
> - `https://playground.b:5175`
|
|
83
88
|
|
|
84
|
-
###
|
|
89
|
+
### Embed Reference Implementation
|
|
85
90
|
|
|
86
|
-
-
|
|
87
|
-
- **getById**(id, options) - Get an user identity by id.
|
|
88
|
-
- **findByUserId**(userId, options) - Find user identities by user id.
|
|
89
|
-
- **update**(data, options) - Update an identity.
|
|
90
|
-
- **deleteById**(id, options) - Delete an user identity by id.
|
|
91
|
-
- **deleteByUserId**(userId, options) - Delete user identities by user id.
|
|
91
|
+
The `embed-ref/` directory contains a minimal, unstyled reference implementation of the embed dialog app. It demonstrates how to build a custom embed using the Account SDK's `Remote` API.
|
|
92
92
|
|
|
93
|
+
Select `dialogRefImpl` in the playground's adapter dropdown to test against it.
|
|
93
94
|
|
|
94
|
-
##
|
|
95
|
+
## License
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
- MongoDB: [mongo-accounts](https://github.com/Mitica/mongo-accounts);
|
|
97
|
+
MIT
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Address, WebCryptoP256 } from 'ox';
|
|
2
|
+
import { KeyAuthorization } from 'ox/tempo';
|
|
3
|
+
import { Account as TempoAccount } from 'viem/tempo';
|
|
4
|
+
import type * as Store from './Store.js';
|
|
5
|
+
/** Returns the pending key authorization for an access key account without removing it. */
|
|
6
|
+
export declare function getPending(account: TempoAccount.Account, options: {
|
|
7
|
+
store: Store.Store;
|
|
8
|
+
}): KeyAuthorization.Signed | undefined;
|
|
9
|
+
/** Generates a P256 key pair and access key account. */
|
|
10
|
+
export declare function generate(options?: generate.Options): Promise<generate.ReturnType>;
|
|
11
|
+
export declare namespace generate {
|
|
12
|
+
type Options = {
|
|
13
|
+
/** Root account to attach to the access key. */
|
|
14
|
+
account?: TempoAccount.Account | undefined;
|
|
15
|
+
};
|
|
16
|
+
type ReturnType = {
|
|
17
|
+
/** The generated access key account. */
|
|
18
|
+
accessKey: TempoAccount.AccessKeyAccount;
|
|
19
|
+
/** Generated key pair to pass to `authorizeAccessKey`. */
|
|
20
|
+
keyPair: Awaited<globalThis.ReturnType<typeof WebCryptoP256.createKeyPair>>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Removes an access key entry for the given account from the store. */
|
|
24
|
+
export declare function remove(account: TempoAccount.Account, options: {
|
|
25
|
+
store: Store.Store;
|
|
26
|
+
}): void;
|
|
27
|
+
/** Permanently removes the pending key authorization for an access key account. */
|
|
28
|
+
export declare function removePending(account: TempoAccount.Account, options: {
|
|
29
|
+
store: Store.Store;
|
|
30
|
+
}): void;
|
|
31
|
+
/** Removes an access key from the store. */
|
|
32
|
+
export declare function revoke(options: revoke.Options): void;
|
|
33
|
+
export declare namespace revoke {
|
|
34
|
+
type Options = {
|
|
35
|
+
/** Root account address. */
|
|
36
|
+
address: Address.Address;
|
|
37
|
+
/** Reactive state store. */
|
|
38
|
+
store: Store.Store;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Saves an access key to the store with its one-time key authorization. */
|
|
42
|
+
export declare function save(options: save.Options): void;
|
|
43
|
+
export declare namespace save {
|
|
44
|
+
type Options = {
|
|
45
|
+
/** Root account address that owns this access key. */
|
|
46
|
+
address: Address.Address;
|
|
47
|
+
/** Signed key authorization to attach to the first transaction. */
|
|
48
|
+
keyAuthorization: KeyAuthorization.Signed;
|
|
49
|
+
/** The WebCrypto key pair backing the access key. Only present for locally-generated keys. */
|
|
50
|
+
keyPair?: Awaited<ReturnType<typeof WebCryptoP256.createKeyPair>> | undefined;
|
|
51
|
+
/** Reactive state store. */
|
|
52
|
+
store: Store.Store;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=AccessKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccessKey.d.ts","sourceRoot":"","sources":["../../src/core/AccessKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AAEpD,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AAExC,2FAA2F;AAC3F,wBAAgB,UAAU,CACxB,OAAO,EAAE,YAAY,CAAC,OAAO,EAC7B,OAAO,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;CAAE,GAC9B,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAOrC;AAED,wDAAwD;AACxD,wBAAsB,QAAQ,CAAC,OAAO,GAAE,QAAQ,CAAC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AAA;QACxB,mEAAmE;QACnE,gBAAgB,EAAE,gBAAgB,CAAC,MAAM,CAAA;QACzC,8FAA8F;QAC9F,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,aAAa,CAAC,CAAC,GAAG,SAAS,CAAA;QAC7E,4BAA4B;QAC5B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;KACnB,CAAA;CACF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Address, WebCryptoP256 } from 'ox';
|
|
2
|
+
import { KeyAuthorization } from 'ox/tempo';
|
|
3
|
+
import { Account as TempoAccount } from 'viem/tempo';
|
|
4
|
+
/** Returns the pending key authorization for an access key account without removing it. */
|
|
5
|
+
export function getPending(account, options) {
|
|
6
|
+
if (account.source !== 'accessKey')
|
|
7
|
+
return undefined;
|
|
8
|
+
const { store } = options;
|
|
9
|
+
const accessKeyAddress = account.accessKeyAddress;
|
|
10
|
+
const { accessKeys } = store.getState();
|
|
11
|
+
const entry = accessKeys.find((a) => a.address?.toLowerCase() === accessKeyAddress.toLowerCase());
|
|
12
|
+
return entry?.keyAuthorization;
|
|
13
|
+
}
|
|
14
|
+
/** Generates a P256 key pair and access key account. */
|
|
15
|
+
export async function generate(options = {}) {
|
|
16
|
+
const { account } = options;
|
|
17
|
+
const keyPair = await WebCryptoP256.createKeyPair();
|
|
18
|
+
const accessKey = TempoAccount.fromWebCryptoP256(keyPair, account ? { access: account } : undefined);
|
|
19
|
+
return { accessKey, keyPair };
|
|
20
|
+
}
|
|
21
|
+
/** Removes an access key entry for the given account from the store. */
|
|
22
|
+
export function remove(account, options) {
|
|
23
|
+
if (account.source !== 'accessKey')
|
|
24
|
+
return;
|
|
25
|
+
const { store } = options;
|
|
26
|
+
const accessKeyAddress = account.accessKeyAddress;
|
|
27
|
+
store.setState((state) => ({
|
|
28
|
+
accessKeys: state.accessKeys.filter((a) => a.address?.toLowerCase() !== accessKeyAddress?.toLowerCase()),
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
/** Permanently removes the pending key authorization for an access key account. */
|
|
32
|
+
export function removePending(account, options) {
|
|
33
|
+
if (account.source !== 'accessKey')
|
|
34
|
+
return;
|
|
35
|
+
const { store } = options;
|
|
36
|
+
const accessKeyAddress = account.accessKeyAddress;
|
|
37
|
+
store.setState((state) => ({
|
|
38
|
+
accessKeys: state.accessKeys.map((a) => a.address.toLowerCase() === accessKeyAddress.toLowerCase()
|
|
39
|
+
? { ...a, keyAuthorization: undefined }
|
|
40
|
+
: a),
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
/** Removes an access key from the store. */
|
|
44
|
+
export function revoke(options) {
|
|
45
|
+
const { address, store } = options;
|
|
46
|
+
const { accessKeys } = store.getState();
|
|
47
|
+
store.setState({
|
|
48
|
+
accessKeys: accessKeys.filter((a) => a.access.toLowerCase() !== address.toLowerCase()),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Saves an access key to the store with its one-time key authorization. */
|
|
52
|
+
export function save(options) {
|
|
53
|
+
const { address, keyAuthorization, keyPair, store } = options;
|
|
54
|
+
store.setState((state) => ({
|
|
55
|
+
accessKeys: [
|
|
56
|
+
{
|
|
57
|
+
address: keyAuthorization.address,
|
|
58
|
+
access: address,
|
|
59
|
+
expiry: keyAuthorization.expiry ?? undefined,
|
|
60
|
+
keyAuthorization,
|
|
61
|
+
keyType: keyAuthorization.type,
|
|
62
|
+
limits: keyAuthorization.limits,
|
|
63
|
+
...(keyPair ? { keyPair } : {}),
|
|
64
|
+
},
|
|
65
|
+
...state.accessKeys,
|
|
66
|
+
],
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=AccessKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccessKey.js","sourceRoot":"","sources":["../../src/core/AccessKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,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,CAAC;AAWD,4EAA4E;AAC5E,MAAM,UAAU,IAAI,CAAC,OAAqB;IACxC,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IAE7D,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACzB,UAAU,EAAE;YACV;gBACE,OAAO,EAAE,gBAAgB,CAAC,OAAO;gBACjC,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,gBAAgB,CAAC,MAAM,IAAI,SAAS;gBAC5C,gBAAgB;gBAChB,OAAO,EAAE,gBAAgB,CAAC,IAAI;gBAC9B,MAAM,EAAE,gBAAgB,CAAC,MAAiE;gBAC1F,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChC;YACD,GAAG,KAAK,CAAC,UAAU;SACpB;KACF,CAAC,CAAC,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type WebCryptoP256 } from 'ox';
|
|
2
|
+
import { type KeyAuthorization } from 'ox/tempo';
|
|
3
|
+
import type { Hex } from 'viem';
|
|
4
|
+
import type { Address, JsonRpcAccount } from 'viem/accounts';
|
|
5
|
+
import { Account as TempoAccount } from 'viem/tempo';
|
|
6
|
+
import type { OneOf } from '../internal/types.js';
|
|
7
|
+
import type * as core_Store from './Store.js';
|
|
8
|
+
/** Account stored in the provider state. */
|
|
9
|
+
export type Store = {
|
|
10
|
+
/** Account address. */
|
|
11
|
+
address: Address;
|
|
12
|
+
} & OneOf<{} | Pick<TempoAccount.Account, 'keyType' | 'sign'> | {
|
|
13
|
+
keyType: 'secp256k1';
|
|
14
|
+
privateKey: Hex;
|
|
15
|
+
} | {
|
|
16
|
+
keyType: 'p256';
|
|
17
|
+
privateKey: Hex;
|
|
18
|
+
} | {
|
|
19
|
+
keyType: 'webAuthn';
|
|
20
|
+
credential: {
|
|
21
|
+
id: string;
|
|
22
|
+
publicKey: Hex;
|
|
23
|
+
rpId: string;
|
|
24
|
+
};
|
|
25
|
+
} | {
|
|
26
|
+
keyType: 'webCrypto';
|
|
27
|
+
keyPair: Awaited<ReturnType<typeof WebCryptoP256.createKeyPair>>;
|
|
28
|
+
} | {
|
|
29
|
+
keyType: 'webAuthn_headless';
|
|
30
|
+
privateKey: Hex;
|
|
31
|
+
rpId: string;
|
|
32
|
+
origin: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** Access key entry stored alongside accounts. */
|
|
35
|
+
export type AccessKey = {
|
|
36
|
+
/** Access key address. */
|
|
37
|
+
address: Address;
|
|
38
|
+
/** Owner of the access key. */
|
|
39
|
+
access: Address;
|
|
40
|
+
/** Unix timestamp when the access key expires. */
|
|
41
|
+
expiry?: number | undefined;
|
|
42
|
+
/** Signed key authorization to attach to the first transaction. Consumed on use. */
|
|
43
|
+
keyAuthorization?: KeyAuthorization.Signed | undefined;
|
|
44
|
+
/** The WebCrypto key pair backing the access key. Only present for locally-generated keys. */
|
|
45
|
+
keyPair?: Awaited<ReturnType<typeof WebCryptoP256.createKeyPair>> | undefined;
|
|
46
|
+
/** Key type. */
|
|
47
|
+
keyType: 'secp256k1' | 'p256' | 'webAuthn' | 'webCrypto';
|
|
48
|
+
/** TIP-20 spending limits for the access key. */
|
|
49
|
+
limits?: {
|
|
50
|
+
token: Address;
|
|
51
|
+
limit: bigint;
|
|
52
|
+
}[] | undefined;
|
|
53
|
+
};
|
|
54
|
+
/** Resolves a viem Account from the store by address (or active account). */
|
|
55
|
+
export declare function find(options: find.Options & {
|
|
56
|
+
signable: true;
|
|
57
|
+
}): TempoAccount.Account;
|
|
58
|
+
export declare function find(options: find.Options): TempoAccount.Account | JsonRpcAccount;
|
|
59
|
+
export declare namespace find {
|
|
60
|
+
type Options = {
|
|
61
|
+
/** Whether to resolve an access key for this account. @default true */
|
|
62
|
+
accessKey?: boolean | undefined;
|
|
63
|
+
/** Address to resolve. Defaults to the active account. */
|
|
64
|
+
address?: Address | undefined;
|
|
65
|
+
/** Whether to hydrate signing capability. @default false */
|
|
66
|
+
signable?: boolean | undefined;
|
|
67
|
+
/** Reactive state store. */
|
|
68
|
+
store: core_Store.Store;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Overloaded signature for `find` without `store` (pre-bound by the provider). */
|
|
72
|
+
export type Find = {
|
|
73
|
+
(options: Omit<find.Options, 'store'> & {
|
|
74
|
+
signable: true;
|
|
75
|
+
}): TempoAccount.Account;
|
|
76
|
+
(options?: Omit<find.Options, 'store'>): TempoAccount.Account | JsonRpcAccount;
|
|
77
|
+
};
|
|
78
|
+
/** Hydrates an access key entry to a viem Account. Only works for locally-generated keys with a `keyPair`. */
|
|
79
|
+
export declare function hydrateAccessKey(accessKey: AccessKey): TempoAccount.Account;
|
|
80
|
+
/** Hydrates a store account to a viem Account. */
|
|
81
|
+
export declare function hydrate(account: Store, options: {
|
|
82
|
+
signable: true;
|
|
83
|
+
}): TempoAccount.Account;
|
|
84
|
+
export declare function hydrate(account: Store, options?: hydrate.Options): TempoAccount.Account | JsonRpcAccount;
|
|
85
|
+
export declare namespace hydrate {
|
|
86
|
+
type Options = {
|
|
87
|
+
/** Whether to hydrate signing capability. @default false */
|
|
88
|
+
signable?: boolean | undefined;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=Account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../src/core/Account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,IAAI,CAAA;AACjD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,E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gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,YAAY,CAAC,OAAO,CAM3E;AAED,kDAAkD;AAClD,wBAAgB,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAAG,YAAY,CAAC,OAAO,CAAA;AAC1F,wBAAgB,OAAO,CACrB,OAAO,EAAE,KAAK,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,GACxB,YAAY,CAAC,OAAO,GAAG,cAAc,CAAA;AAgCxC,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,KAAK,OAAO,GAAG;QACb,4DAA4D;QAC5D,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAC/B,CAAA;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Provider } from 'ox';
|
|
2
|
+
import {} from 'ox/tempo';
|
|
3
|
+
import { Account as TempoAccount } from 'viem/tempo';
|
|
4
|
+
export function find(options) {
|
|
5
|
+
const { accessKey = true, address, signable = false, store } = options;
|
|
6
|
+
const { accessKeys, accounts, activeAccount } = store.getState();
|
|
7
|
+
const activeAddr = accounts[activeAccount]?.address;
|
|
8
|
+
const root = address
|
|
9
|
+
? accounts.find((a) => a.address === address)
|
|
10
|
+
: accounts.find((a) => a.address === activeAddr);
|
|
11
|
+
if (!root)
|
|
12
|
+
throw address
|
|
13
|
+
? new Provider.UnauthorizedError({ message: `Account "${address}" not found.` })
|
|
14
|
+
: new Provider.DisconnectedError({ message: 'No active account.' });
|
|
15
|
+
// When accessKey is requested, prefer a locally-signable access key for this address.
|
|
16
|
+
if (accessKey) {
|
|
17
|
+
const key = accessKeys.find((a) => a.access.toLowerCase() === root.address.toLowerCase() && a.keyPair);
|
|
18
|
+
if (key) {
|
|
19
|
+
// Remove expired access keys.
|
|
20
|
+
if (key.expiry && key.expiry < Date.now() / 1000)
|
|
21
|
+
store.setState({ accessKeys: accessKeys.filter((a) => a !== key) });
|
|
22
|
+
else
|
|
23
|
+
return hydrateAccessKey(key);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return hydrate(root, { signable });
|
|
27
|
+
}
|
|
28
|
+
/** Hydrates an access key entry to a viem Account. Only works for locally-generated keys with a `keyPair`. */
|
|
29
|
+
export function hydrateAccessKey(accessKey) {
|
|
30
|
+
if (!accessKey.keyPair)
|
|
31
|
+
throw new Provider.UnauthorizedError({
|
|
32
|
+
message: 'External access key cannot be hydrated for signing.',
|
|
33
|
+
});
|
|
34
|
+
return TempoAccount.fromWebCryptoP256(accessKey.keyPair, { access: accessKey.access });
|
|
35
|
+
}
|
|
36
|
+
export function hydrate(account, options = {}) {
|
|
37
|
+
const { signable = false } = options;
|
|
38
|
+
if (!signable)
|
|
39
|
+
return { address: account.address, type: 'json-rpc' };
|
|
40
|
+
if ('sign' in account && typeof account.sign === 'function')
|
|
41
|
+
return account;
|
|
42
|
+
if (!account.keyType)
|
|
43
|
+
throw new Provider.UnauthorizedError({ message: `Account "${account.address}" cannot sign.` });
|
|
44
|
+
switch (account.keyType) {
|
|
45
|
+
case 'secp256k1':
|
|
46
|
+
return TempoAccount.fromSecp256k1(account.privateKey);
|
|
47
|
+
case 'p256':
|
|
48
|
+
return TempoAccount.fromP256(account.privateKey);
|
|
49
|
+
case 'webCrypto':
|
|
50
|
+
return TempoAccount.fromWebCryptoP256(account.keyPair);
|
|
51
|
+
case 'webAuthn':
|
|
52
|
+
return TempoAccount.fromWebAuthnP256(account.credential, {
|
|
53
|
+
rpId: account.credential.rpId,
|
|
54
|
+
});
|
|
55
|
+
case 'webAuthn_headless':
|
|
56
|
+
return TempoAccount.fromHeadlessWebAuthn(account.privateKey, {
|
|
57
|
+
rpId: account.rpId,
|
|
58
|
+
origin: account.origin,
|
|
59
|
+
});
|
|
60
|
+
default:
|
|
61
|
+
throw new Provider.UnauthorizedError({ message: 'Unknown key type.' });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//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