@mithiraj/keystore-seed-vault 0.0.0-stage → 1.0.0-canary.2
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/README.md +233 -2
- package/dist/constants.d.ts +17 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +17 -0
- package/dist/constants.js.map +1 -0
- package/dist/engine.d.ts +41 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +235 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.d.ts +62 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +77 -0
- package/dist/errors.js.map +1 -0
- package/dist/extension.d.ts +41 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +76 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/shim.d.ts +53 -0
- package/dist/shim.d.ts.map +1 -0
- package/dist/shim.js +134 -0
- package/dist/shim.js.map +1 -0
- package/dist/store.d.ts +79 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +115 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +217 -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 +68 -4
package/README.md
CHANGED
|
@@ -1,3 +1,234 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mithiraj/keystore-seed-vault
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A keystore whose keys live in an external **Seed Vault**.
|
|
4
|
+
|
|
5
|
+
Private key material never enters JavaScript: the vault holds the keys, shows
|
|
6
|
+
the approval screen and produces every signature. This package is the
|
|
7
|
+
provider-facing side of that arrangement. It has no storage driver, no master
|
|
8
|
+
key and no local unlock prompt, and it does not depend on any vault vendor.
|
|
9
|
+
|
|
10
|
+
> [!NOTE]
|
|
11
|
+
> Experimental; canary releases are published to npm under the `next` tag
|
|
12
|
+
> (`npm i @mithiraj/keystore-seed-vault@next`). It **replaces** the
|
|
13
|
+
> local keystore on a provider; running it beside a local keystore is not
|
|
14
|
+
> supported yet (see [Replacement, not coexistence](#replacement-not-coexistence)).
|
|
15
|
+
> It targets the Wallet Provider canary; see
|
|
16
|
+
> [Migration notes](#migration-notes-wallet-provider-100) for what the 1.0.0
|
|
17
|
+
> keystore release changes.
|
|
18
|
+
|
|
19
|
+
## Layers
|
|
20
|
+
|
|
21
|
+
The package is built in four layers. Each one is usable without the one above it.
|
|
22
|
+
|
|
23
|
+
| Layer | Export | What it is |
|
|
24
|
+
| --------- | -------------------------------------------- | ------------------------------------------------------ |
|
|
25
|
+
| Binding | `SeedVaultBinding` | The vault integration. The only vendor-specific piece. |
|
|
26
|
+
| Shim | `withSubtleSeedVault`, `createSeedVaultShim` | A composable Subtle decorator over the binding. |
|
|
27
|
+
| Keystore | `createSeedVaultKeyStore` | A `KeyStoreAPI` built on the shim. |
|
|
28
|
+
| Extension | `WithSeedVaultKeyStore` | The Wallet Provider extension. |
|
|
29
|
+
|
|
30
|
+
## Pure keys
|
|
31
|
+
|
|
32
|
+
A vault key is recorded as a key and nothing else: an id, a type, an algorithm
|
|
33
|
+
and a public key.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
{
|
|
37
|
+
id: "seed-1/0",
|
|
38
|
+
type: "falcon-1024",
|
|
39
|
+
algorithm: "Falcon-1024",
|
|
40
|
+
keyUsages: ["sign", "verify"],
|
|
41
|
+
publicKey,
|
|
42
|
+
extractable: false,
|
|
43
|
+
metadata: { storage: "external", owner: "@mithiraj/keystore-seed-vault" },
|
|
44
|
+
version: 1,
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
There is no address on a key. An address belongs to an account, and accounts
|
|
49
|
+
are built on keys by an accounts extension, for example
|
|
50
|
+
[`@mithiraj/accounts-seed-vault-extension`](../../accounts/seed-vault-extension).
|
|
51
|
+
Other abstractions (identities, device-bound credentials) build on the same
|
|
52
|
+
keys without inheriting anything account-shaped.
|
|
53
|
+
|
|
54
|
+
## 1. Binding
|
|
55
|
+
|
|
56
|
+
Adapt the vault's native module to `SeedVaultBinding` and inject it. The
|
|
57
|
+
binding reports pure keys and signs with the key an `id` names.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import type { SeedVaultBinding } from "@mithiraj/keystore-seed-vault";
|
|
61
|
+
|
|
62
|
+
export const binding: SeedVaultBinding = {
|
|
63
|
+
// Connect, then list what this app is authorized to use.
|
|
64
|
+
async keys() {
|
|
65
|
+
await native.bind();
|
|
66
|
+
const seeds = await native.getAuthorizedSeeds();
|
|
67
|
+
return seeds.flatMap((seed) =>
|
|
68
|
+
seed.accounts.map((entry) => ({
|
|
69
|
+
id: `${seed.id}/${entry.index}`,
|
|
70
|
+
algorithm: "Falcon-1024" as const,
|
|
71
|
+
publicKey: base64.decode(entry.publicKey),
|
|
72
|
+
name: seed.name,
|
|
73
|
+
})),
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
// One call per signature: ask for approval, then sign.
|
|
77
|
+
async sign({ id, data, intent }) {
|
|
78
|
+
const locator = locatorFor(id); // whatever the native API addresses a key by
|
|
79
|
+
return intent === "transaction"
|
|
80
|
+
? native.signTransaction(locator, data)
|
|
81
|
+
: native.signBytes(locator, data);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
A vault whose own API addresses keys by something else (an on-chain address,
|
|
87
|
+
an auth token) keeps that translation inside the binding. A rejected request
|
|
88
|
+
either throws or resolves `null`; both surface as `SeedVaultRejectedError`.
|
|
89
|
+
|
|
90
|
+
Optional members:
|
|
91
|
+
|
|
92
|
+
- `signBatch` and `maxBatchSize`: sign several payloads with one key under a
|
|
93
|
+
single approval.
|
|
94
|
+
- `remove`: revoke this app's access to a key.
|
|
95
|
+
|
|
96
|
+
## 2. Shim
|
|
97
|
+
|
|
98
|
+
The shim works with any `SubtleCrypto`, with or without a keystore.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { createKeyHandle } from "@algorandfoundation/keystore-core";
|
|
102
|
+
import { withSubtleSeedVault } from "@mithiraj/keystore-seed-vault";
|
|
103
|
+
|
|
104
|
+
const subtle = withSubtleSeedVault(crypto.subtle, binding);
|
|
105
|
+
const handle = createKeyHandle("private", { name: "SeedVault" }, false, ["sign"]);
|
|
106
|
+
|
|
107
|
+
const signature = await subtle.sign({ name: "SeedVault", id: "seed-1/0" }, handle, message);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
It differs from the other keystore shims in one way. They receive key material
|
|
111
|
+
through the algorithm parameters for the duration of a call; this one receives
|
|
112
|
+
a locator (`id`) and the binding signs inside the vault. `generateKey`,
|
|
113
|
+
`importKey` and `exportKey` throw `MaterialAccessError` for `"SeedVault"`.
|
|
114
|
+
`verify` is not handled: verify with the key's own algorithm and public key.
|
|
115
|
+
|
|
116
|
+
`createSeedVaultShim(binding)` returns the same decorator as a tagged
|
|
117
|
+
`SubtleShim`.
|
|
118
|
+
|
|
119
|
+
## 3. Keystore
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { Store } from "@tanstack/store";
|
|
123
|
+
import { createSeedVaultKeyStore } from "@mithiraj/keystore-seed-vault";
|
|
124
|
+
|
|
125
|
+
const store = new Store({ keys: [], status: "idle" });
|
|
126
|
+
const keystore = createSeedVaultKeyStore({ binding, store, hooks });
|
|
127
|
+
|
|
128
|
+
await keystore.ready;
|
|
129
|
+
const [key] = store.state.keys;
|
|
130
|
+
const signature = await keystore.sign(key.id, message);
|
|
131
|
+
await keystore.verify(key.id, message, signature); // local, no vault request
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
| `KeyStoreAPI` | Seed Vault keystore |
|
|
135
|
+
| -------------------------------------------- | --------------------------------------------------------------- |
|
|
136
|
+
| `ready` | Lists the vault's keys and hydrates the store |
|
|
137
|
+
| `refresh()` | Lists them again, e.g. after the user authorized another seed |
|
|
138
|
+
| `sign` | Performed by the vault |
|
|
139
|
+
| `batchSign` | One vault approval per key; results keep the caller's order |
|
|
140
|
+
| `verify` | Local, against the public key |
|
|
141
|
+
| `export` | Public metadata only |
|
|
142
|
+
| `remove` | Through `binding.remove`, otherwise `SeedVaultUnsupportedError` |
|
|
143
|
+
| `generate`, `import` | `SeedVaultUnsupportedError` |
|
|
144
|
+
| `importSeed`, `deriveFromSeed`, `secrets`, … | Not present |
|
|
145
|
+
|
|
146
|
+
The `ctx` argument of `sign` and `batchSign` tells the vault what it is
|
|
147
|
+
signing, so it can show the matching approval screen:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
await keystore.sign(key.id, transaction, undefined, { intent: "transaction" });
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Verification uses the Subtle shims passed as `shims`. By default Falcon-1024 is
|
|
154
|
+
enabled when the optional `falcon-1024` peer dependency is installed; pass your
|
|
155
|
+
own array to use a platform-native binding.
|
|
156
|
+
|
|
157
|
+
When the vault cannot be reached, `ready` rejects with
|
|
158
|
+
`SeedVaultUnavailableError` and the store's `status` becomes `"unavailable"`.
|
|
159
|
+
Call `refresh()` to try again.
|
|
160
|
+
|
|
161
|
+
## 4. Extension
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { Provider } from "@algorandfoundation/wallet-provider";
|
|
165
|
+
import { WithSeedVaultKeyStore } from "@mithiraj/keystore-seed-vault";
|
|
166
|
+
|
|
167
|
+
const WalletProvider = Provider.withExtensions([WithSeedVaultKeyStore]);
|
|
168
|
+
const provider = new WalletProvider(
|
|
169
|
+
{ id: "my-wallet", name: "My Wallet" },
|
|
170
|
+
{ keystore: { store, hooks, binding } },
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
await provider.key.store.ready;
|
|
174
|
+
provider.keys; // the vault's keys
|
|
175
|
+
await provider.key.store.sign(provider.keys[0].id, message);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Replacement, not coexistence
|
|
179
|
+
|
|
180
|
+
`WithSeedVaultKeyStore` mounts the same surface as the local keystore
|
|
181
|
+
extension (`keys`, `status`, `algorithms`, `key.store`) and reads the same
|
|
182
|
+
`options.keystore` block. Extensions written against `provider.key.store`
|
|
183
|
+
therefore work unchanged, and a provider loads **one** keystore extension.
|
|
184
|
+
|
|
185
|
+
Loading it next to a local keystore is not supported. On the Wallet Provider
|
|
186
|
+
canary this repository builds against, the later extension silently shadows
|
|
187
|
+
the earlier one's `key.store`.
|
|
188
|
+
|
|
189
|
+
## Migration notes: Wallet Provider 1.0.0
|
|
190
|
+
|
|
191
|
+
This package targets the Wallet Provider canary (`1.0.0-canary.5`), like the
|
|
192
|
+
rest of the repository. The 1.0.0 keystore release will be bound to Wallet
|
|
193
|
+
Provider 1.0.0, and this package and its accounts bridge have to move with it.
|
|
194
|
+
What changes:
|
|
195
|
+
|
|
196
|
+
- **Extension signature.** `Extension` becomes
|
|
197
|
+
`(provider: NamespaceHost, options: ExtensionOptions) => T`, so
|
|
198
|
+
`WithSeedVaultKeyStore` and `WithAccountsSeedVault` no longer type-check with
|
|
199
|
+
their own parameter types. `options.keystore.binding` and
|
|
200
|
+
`options.accounts.seedVault` have to be registered on the `ExtensionOptions`
|
|
201
|
+
registry by declaration merging, next to the `keystore` and `accounts` blocks
|
|
202
|
+
their owning packages register.
|
|
203
|
+
- **Mounting.** Return `extendNamespace(provider, "key", { … })` instead of a
|
|
204
|
+
fresh `key` object, once the keystore core registers `key` on `Namespaces`.
|
|
205
|
+
A provider then rejects a second extension that returns `keys`, `status`,
|
|
206
|
+
`algorithms` or a new `key` with a `MountError` instead of shadowing the
|
|
207
|
+
first.
|
|
208
|
+
- **Coexistence becomes possible.** A vault mounted on its own branch survives
|
|
209
|
+
next to the local keystore (`provider.key` holds both `store` and the vault
|
|
210
|
+
branch). The branch name is a decision for the keystore core, which owns the
|
|
211
|
+
`key` namespace.
|
|
212
|
+
- **Ownership.** Records carry `metadata.owner` today. Wallet Provider 1.0.0
|
|
213
|
+
makes `owner` a top-level field of every entry (`Entity`), so it moves out of
|
|
214
|
+
`metadata`, `isSeedVaultKey` becomes `ownedBy(SEED_VAULT_OWNER)`, and the
|
|
215
|
+
package registers its metadata shape on `Owners`.
|
|
216
|
+
- **Shared store fields.** `hydrateKeys` already replaces only the records this
|
|
217
|
+
package owns. `status` and `algorithms` are still written for the whole
|
|
218
|
+
store, which is correct for a replacement and has to be merged before two
|
|
219
|
+
keystores share one store.
|
|
220
|
+
|
|
221
|
+
The test suites of this package and of the accounts bridge pass unchanged
|
|
222
|
+
against the Wallet Provider 1.0.0 runtime. The type-level changes above are
|
|
223
|
+
the blocking part.
|
|
224
|
+
|
|
225
|
+
## Errors
|
|
226
|
+
|
|
227
|
+
| Error | When |
|
|
228
|
+
| --------------------------- | ------------------------------------------------------------ |
|
|
229
|
+
| `SeedVaultUnavailableError` | The vault's keys could not be listed |
|
|
230
|
+
| `SeedVaultRejectedError` | The vault produced no signature (declined, dismissed) |
|
|
231
|
+
| `SeedVaultUnsupportedError` | The operation does not exist for vault keys |
|
|
232
|
+
| `KeyNotFoundError` | The id is unknown, or the record belongs to another keystore |
|
|
233
|
+
|
|
234
|
+
All of them extend the core `KeyStoreError`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Algorithm identifier used to route operations to the Seed Vault decorator
|
|
3
|
+
* (see {@link import("./shim.ts").withSubtleSeedVault}).
|
|
4
|
+
*/
|
|
5
|
+
export declare const SEED_VAULT_ALGORITHM = "SeedVault";
|
|
6
|
+
/**
|
|
7
|
+
* The name of this package, written to `metadata.owner` of every key record it
|
|
8
|
+
* hydrates. A package only signs with, refreshes and removes the records it
|
|
9
|
+
* owns, so keys written to the same store by another keystore are left alone.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SEED_VAULT_OWNER = "@mithiraj/keystore-seed-vault";
|
|
12
|
+
/**
|
|
13
|
+
* The `metadata.storage` value of a vault key: no material is held by any
|
|
14
|
+
* storage driver, every private-key operation is delegated to the vault.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SEED_VAULT_STORAGE = "external";
|
|
17
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,kCAAkC,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,kBAAkB,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Algorithm identifier used to route operations to the Seed Vault decorator
|
|
3
|
+
* (see {@link import("./shim.ts").withSubtleSeedVault}).
|
|
4
|
+
*/
|
|
5
|
+
export const SEED_VAULT_ALGORITHM = "SeedVault";
|
|
6
|
+
/**
|
|
7
|
+
* The name of this package, written to `metadata.owner` of every key record it
|
|
8
|
+
* hydrates. A package only signs with, refreshes and removes the records it
|
|
9
|
+
* owns, so keys written to the same store by another keystore are left alone.
|
|
10
|
+
*/
|
|
11
|
+
export const SEED_VAULT_OWNER = "@mithiraj/keystore-seed-vault";
|
|
12
|
+
/**
|
|
13
|
+
* The `metadata.storage` value of a vault key: no material is held by any
|
|
14
|
+
* storage driver, every private-key operation is delegated to the vault.
|
|
15
|
+
*/
|
|
16
|
+
export const SEED_VAULT_STORAGE = "external";
|
|
17
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC"}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CreateSeedVaultKeyStoreOptions, SeedVaultKeyStore } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a keystore whose keys live in an external Seed Vault.
|
|
4
|
+
*
|
|
5
|
+
* It fulfils the `KeyStoreAPI` without a storage driver: there is no material
|
|
6
|
+
* to seal, no master key and no local unlock prompt. The reactive `store`
|
|
7
|
+
* mirrors the public metadata of the keys the vault authorized, `sign` and
|
|
8
|
+
* `batchSign` are delegated to the vault through the
|
|
9
|
+
* {@link withSubtleSeedVault} shim, and `verify` runs locally against the
|
|
10
|
+
* public key. Records are pure keys: they carry no address or other data of a
|
|
11
|
+
* domain built on top of them.
|
|
12
|
+
*
|
|
13
|
+
* | Operation | Behaviour |
|
|
14
|
+
* |---|---|
|
|
15
|
+
* | `ready` | Lists the vault's keys and hydrates the store |
|
|
16
|
+
* | `refresh` | Lists them again |
|
|
17
|
+
* | `sign` / `batchSign` | Performed by the vault |
|
|
18
|
+
* | `verify` | Local, with the key's own algorithm; no vault request |
|
|
19
|
+
* | `export` | Public metadata only |
|
|
20
|
+
* | `remove` | Through the binding's `remove`, otherwise unsupported |
|
|
21
|
+
* | `generate` / `import` | Unsupported: keys are created inside the vault |
|
|
22
|
+
*
|
|
23
|
+
* @param options - {@link CreateSeedVaultKeyStoreOptions}.
|
|
24
|
+
* @returns A {@link SeedVaultKeyStore}.
|
|
25
|
+
* @throws {SeedVaultUnavailableError} From `ready`, `refresh` and every
|
|
26
|
+
* operation, when the vault's keys cannot be listed.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { Store } from "@tanstack/store";
|
|
31
|
+
*
|
|
32
|
+
* const store = new Store({ keys: [], status: "idle" });
|
|
33
|
+
* const keystore = createSeedVaultKeyStore({ binding, store });
|
|
34
|
+
* await keystore.ready;
|
|
35
|
+
* const [key] = store.state.keys;
|
|
36
|
+
* const signature = await keystore.sign(key.id, new TextEncoder().encode("hi"));
|
|
37
|
+
* const ok = await keystore.verify(key.id, new TextEncoder().encode("hi"), signature);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function createSeedVaultKeyStore(options: CreateSeedVaultKeyStoreOptions): SeedVaultKeyStore;
|
|
41
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EACV,8BAA8B,EAG9B,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAkBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,iBAAiB,CAuOnB"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { createFalconBinding, createKeyHandle, FALCON_ALGORITHM, InvalidKeyDataError, KeyNotFoundError, KeyStoreError, tagShim, withSubtleFalcon1024, } from "@algorandfoundation/keystore-core";
|
|
2
|
+
import { SEED_VAULT_ALGORITHM } from "./constants.js";
|
|
3
|
+
import { SeedVaultRejectedError, SeedVaultUnavailableError, SeedVaultUnsupportedError, } from "./errors.js";
|
|
4
|
+
import { withSubtleSeedVault } from "./shim.js";
|
|
5
|
+
import { getKey, hydrateKeys, removeKey, setStatus } from "./store.js";
|
|
6
|
+
/**
|
|
7
|
+
* Casts a `Uint8Array` to the strict `BufferSource` overload WebCrypto expects.
|
|
8
|
+
*/
|
|
9
|
+
function bs(bytes) {
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds the default verification shims: Falcon-1024 through the optional
|
|
14
|
+
* `falcon-1024` peer dependency, left out when it is not installed.
|
|
15
|
+
*/
|
|
16
|
+
async function createDefaultVerifyShims() {
|
|
17
|
+
const falcon = await createFalconBinding();
|
|
18
|
+
return falcon ? [tagShim(FALCON_ALGORITHM, (host) => withSubtleFalcon1024(host, falcon))] : [];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a keystore whose keys live in an external Seed Vault.
|
|
22
|
+
*
|
|
23
|
+
* It fulfils the `KeyStoreAPI` without a storage driver: there is no material
|
|
24
|
+
* to seal, no master key and no local unlock prompt. The reactive `store`
|
|
25
|
+
* mirrors the public metadata of the keys the vault authorized, `sign` and
|
|
26
|
+
* `batchSign` are delegated to the vault through the
|
|
27
|
+
* {@link withSubtleSeedVault} shim, and `verify` runs locally against the
|
|
28
|
+
* public key. Records are pure keys: they carry no address or other data of a
|
|
29
|
+
* domain built on top of them.
|
|
30
|
+
*
|
|
31
|
+
* | Operation | Behaviour |
|
|
32
|
+
* |---|---|
|
|
33
|
+
* | `ready` | Lists the vault's keys and hydrates the store |
|
|
34
|
+
* | `refresh` | Lists them again |
|
|
35
|
+
* | `sign` / `batchSign` | Performed by the vault |
|
|
36
|
+
* | `verify` | Local, with the key's own algorithm; no vault request |
|
|
37
|
+
* | `export` | Public metadata only |
|
|
38
|
+
* | `remove` | Through the binding's `remove`, otherwise unsupported |
|
|
39
|
+
* | `generate` / `import` | Unsupported: keys are created inside the vault |
|
|
40
|
+
*
|
|
41
|
+
* @param options - {@link CreateSeedVaultKeyStoreOptions}.
|
|
42
|
+
* @returns A {@link SeedVaultKeyStore}.
|
|
43
|
+
* @throws {SeedVaultUnavailableError} From `ready`, `refresh` and every
|
|
44
|
+
* operation, when the vault's keys cannot be listed.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { Store } from "@tanstack/store";
|
|
49
|
+
*
|
|
50
|
+
* const store = new Store({ keys: [], status: "idle" });
|
|
51
|
+
* const keystore = createSeedVaultKeyStore({ binding, store });
|
|
52
|
+
* await keystore.ready;
|
|
53
|
+
* const [key] = store.state.keys;
|
|
54
|
+
* const signature = await keystore.sign(key.id, new TextEncoder().encode("hi"));
|
|
55
|
+
* const ok = await keystore.verify(key.id, new TextEncoder().encode("hi"), signature);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function createSeedVaultKeyStore(options) {
|
|
59
|
+
const { binding, store } = options;
|
|
60
|
+
const host = options.subtle ?? globalThis.crypto.subtle;
|
|
61
|
+
// The verification shims may load an optional library lazily, so layering is
|
|
62
|
+
// async. Every operation awaits it (through `loading`) before using `subtle`.
|
|
63
|
+
let subtle = host;
|
|
64
|
+
const layered = (async () => {
|
|
65
|
+
const shimsOption = options.shims;
|
|
66
|
+
const shims = shimsOption === undefined
|
|
67
|
+
? await createDefaultVerifyShims()
|
|
68
|
+
: typeof shimsOption === "function"
|
|
69
|
+
? await shimsOption()
|
|
70
|
+
: shimsOption;
|
|
71
|
+
for (const shim of shims)
|
|
72
|
+
subtle = shim(subtle);
|
|
73
|
+
subtle = withSubtleSeedVault(subtle, binding);
|
|
74
|
+
})();
|
|
75
|
+
const load = async () => {
|
|
76
|
+
await layered;
|
|
77
|
+
let keys;
|
|
78
|
+
try {
|
|
79
|
+
keys = await binding.keys();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
setStatus({ store, status: "unavailable" });
|
|
83
|
+
if (error instanceof KeyStoreError)
|
|
84
|
+
throw error;
|
|
85
|
+
throw new SeedVaultUnavailableError(error instanceof Error ? error.message : String(error), error instanceof Error ? error : undefined);
|
|
86
|
+
}
|
|
87
|
+
hydrateKeys({ store, keys });
|
|
88
|
+
};
|
|
89
|
+
// The latest load. Operations await it, so a `refresh` after a failed first
|
|
90
|
+
// load recovers the keystore while `ready` keeps describing the first one.
|
|
91
|
+
let loading = load();
|
|
92
|
+
const ready = loading;
|
|
93
|
+
// The caller decides whether to await `ready`; an unobserved failure must not
|
|
94
|
+
// surface as an unhandled rejection (the status reports it instead).
|
|
95
|
+
ready.catch(() => undefined);
|
|
96
|
+
const requireKey = (id) => {
|
|
97
|
+
const key = getKey({ store, id });
|
|
98
|
+
if (!key)
|
|
99
|
+
throw new KeyNotFoundError(id);
|
|
100
|
+
return key;
|
|
101
|
+
};
|
|
102
|
+
const signWithVault = async (id, data, intent) => {
|
|
103
|
+
const handle = createKeyHandle("private", { name: SEED_VAULT_ALGORITHM }, false, ["sign"]);
|
|
104
|
+
const signature = await subtle.sign({ name: SEED_VAULT_ALGORITHM, id, intent }, handle, bs(data));
|
|
105
|
+
return new Uint8Array(signature);
|
|
106
|
+
};
|
|
107
|
+
const api = {
|
|
108
|
+
ready,
|
|
109
|
+
refresh() {
|
|
110
|
+
loading = load();
|
|
111
|
+
return loading;
|
|
112
|
+
},
|
|
113
|
+
async generate(_options) {
|
|
114
|
+
throw new SeedVaultUnsupportedError("generate");
|
|
115
|
+
},
|
|
116
|
+
async import(_data, _format) {
|
|
117
|
+
throw new SeedVaultUnsupportedError("import");
|
|
118
|
+
},
|
|
119
|
+
async export(id, _options) {
|
|
120
|
+
await loading;
|
|
121
|
+
return { ...requireKey(id) };
|
|
122
|
+
},
|
|
123
|
+
async remove(id) {
|
|
124
|
+
await loading;
|
|
125
|
+
const key = requireKey(id);
|
|
126
|
+
if (!binding.remove)
|
|
127
|
+
throw new SeedVaultUnsupportedError("remove");
|
|
128
|
+
setStatus({ store, status: "removing" });
|
|
129
|
+
try {
|
|
130
|
+
await binding.remove(key.id);
|
|
131
|
+
removeKey({ store, id: key.id });
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
setStatus({ store, status: "idle" });
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
async sign(id, data, _algorithm, ctx) {
|
|
138
|
+
await loading;
|
|
139
|
+
const key = requireKey(id);
|
|
140
|
+
setStatus({ store, status: "signing" });
|
|
141
|
+
try {
|
|
142
|
+
return await signWithVault(key.id, data, ctx?.intent ?? "bytes");
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
setStatus({ store, status: "idle" });
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
async verify(id, data, signature, _algorithm) {
|
|
149
|
+
await loading;
|
|
150
|
+
const key = requireKey(id);
|
|
151
|
+
if (!key.publicKey)
|
|
152
|
+
throw new InvalidKeyDataError("missing public key for verify");
|
|
153
|
+
setStatus({ store, status: "verifying" });
|
|
154
|
+
try {
|
|
155
|
+
if (key.type === "falcon-1024") {
|
|
156
|
+
const handle = createKeyHandle("public", { name: FALCON_ALGORITHM }, true, ["verify"]);
|
|
157
|
+
return await subtle.verify({ name: FALCON_ALGORITHM, publicKey: key.publicKey }, handle, bs(signature), bs(data));
|
|
158
|
+
}
|
|
159
|
+
const publicKey = await host.importKey("raw", bs(key.publicKey), { name: "Ed25519" }, true, ["verify"]);
|
|
160
|
+
return await host.verify({ name: "Ed25519" }, publicKey, bs(signature), bs(data));
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
setStatus({ store, status: "idle" });
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
async batchSign(ids, data, ctx) {
|
|
167
|
+
if (ids.length !== data.length) {
|
|
168
|
+
throw new InvalidKeyDataError("batchSign requires exactly one data item per key id");
|
|
169
|
+
}
|
|
170
|
+
await loading;
|
|
171
|
+
// A vault approval covers one key, so group the items by key (keeping
|
|
172
|
+
// each item's position) and resolve every key before asking for anything.
|
|
173
|
+
const groups = new Map();
|
|
174
|
+
ids.forEach((id, position) => {
|
|
175
|
+
const key = requireKey(id);
|
|
176
|
+
groups.set(key.id, [...(groups.get(key.id) ?? []), position]);
|
|
177
|
+
});
|
|
178
|
+
const intent = ctx?.intent ?? "bytes";
|
|
179
|
+
const signatures = Array.from({ length: ids.length });
|
|
180
|
+
setStatus({ store, status: "signing" });
|
|
181
|
+
try {
|
|
182
|
+
for (const [id, positions] of groups) {
|
|
183
|
+
if (!binding.signBatch || positions.length === 1) {
|
|
184
|
+
for (const position of positions) {
|
|
185
|
+
signatures[position] = await signWithVault(id, data[position], intent);
|
|
186
|
+
}
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const size = binding.maxBatchSize ?? positions.length;
|
|
190
|
+
if (!Number.isInteger(size) || size < 1) {
|
|
191
|
+
throw new InvalidKeyDataError("the binding's maxBatchSize must be a positive integer");
|
|
192
|
+
}
|
|
193
|
+
for (let start = 0; start < positions.length; start += size) {
|
|
194
|
+
const chunk = positions.slice(start, start + size);
|
|
195
|
+
const signed = await binding.signBatch({
|
|
196
|
+
id,
|
|
197
|
+
data: chunk.map((position) => data[position]),
|
|
198
|
+
intent,
|
|
199
|
+
});
|
|
200
|
+
if (!signed || signed.length !== chunk.length || signed.some((s) => !s)) {
|
|
201
|
+
throw new SeedVaultRejectedError(id);
|
|
202
|
+
}
|
|
203
|
+
chunk.forEach((position, index) => {
|
|
204
|
+
signatures[position] = Uint8Array.from(signed[index]);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return signatures;
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
setStatus({ store, status: "idle" });
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
// No hooks requested: return the bare keystore.
|
|
216
|
+
if (!options.hooks)
|
|
217
|
+
return api;
|
|
218
|
+
// Hooks were bound at creation. Wrap each operation so `before`/`after`/
|
|
219
|
+
// `error` hooks can intercept it, and expose the collection as
|
|
220
|
+
// `keystore.hooks`. The operation ids match the core engine's.
|
|
221
|
+
const hooks = options.hooks;
|
|
222
|
+
const run = hooks;
|
|
223
|
+
const intercept = (name, method) => (...args) => run(name, () => method.apply(api, args), { args });
|
|
224
|
+
const wrapped = { ...api, hooks };
|
|
225
|
+
wrapped.refresh = intercept("refresh", api.refresh.bind(api));
|
|
226
|
+
wrapped.generate = intercept("generate", api.generate.bind(api));
|
|
227
|
+
wrapped.import = intercept("import", api.import.bind(api));
|
|
228
|
+
wrapped.export = intercept("export", api.export.bind(api));
|
|
229
|
+
wrapped.remove = intercept("remove", api.remove.bind(api));
|
|
230
|
+
wrapped.sign = intercept("sign", api.sign.bind(api));
|
|
231
|
+
wrapped.verify = intercept("verify", api.verify.bind(api));
|
|
232
|
+
wrapped.batchSign = intercept("batchSign", api.batchSign.bind(api));
|
|
233
|
+
return wrapped;
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,eAAe,EAEf,gBAAgB,EAEhB,mBAAmB,EAKnB,gBAAgB,EAChB,aAAa,EAEb,OAAO,EACP,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAQvE;;GAEG;AACH,SAAS,EAAE,CAAC,KAAiB;IAC3B,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,wBAAwB;IACrC,MAAM,MAAM,GAAG,MAAM,mBAAmB,EAAE,CAAC;IAC3C,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACjG,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAuC;IAEvC,MAAM,EAAE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C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,SAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAErE,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { KeyStoreError } from "@algorandfoundation/keystore-core";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when the vault cannot be reached or queried: it is not
|
|
4
|
+
* installed, the app is not authorized, or the binding failed to list keys.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* try {
|
|
9
|
+
* await keystore.ready;
|
|
10
|
+
* } catch (error) {
|
|
11
|
+
* if (error instanceof SeedVaultUnavailableError) showInstallPrompt();
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class SeedVaultUnavailableError extends KeyStoreError {
|
|
16
|
+
/**
|
|
17
|
+
* @param reason - A description of why the vault is unavailable.
|
|
18
|
+
* @param cause - The underlying error raised by the binding, if any.
|
|
19
|
+
*/
|
|
20
|
+
constructor(reason: string, cause?: Error);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown when the vault did not produce a signature: the user declined
|
|
24
|
+
* the request, or the request was dismissed or superseded.
|
|
25
|
+
*
|
|
26
|
+
* A binding either throws this error itself or resolves `null`/`undefined`,
|
|
27
|
+
* which the shim converts into this error.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* try {
|
|
32
|
+
* await keystore.sign(id, data);
|
|
33
|
+
* } catch (error) {
|
|
34
|
+
* if (error instanceof SeedVaultRejectedError) return; // the user said no
|
|
35
|
+
* throw error;
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class SeedVaultRejectedError extends KeyStoreError {
|
|
40
|
+
/**
|
|
41
|
+
* @param keyId - The ID of the key the request was made for.
|
|
42
|
+
* @param cause - The underlying error raised by the binding, if any.
|
|
43
|
+
*/
|
|
44
|
+
constructor(keyId: string, cause?: Error);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown for a keystore operation the vault does not offer. Keys are
|
|
48
|
+
* created, imported and derived inside the vault, never through the keystore.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* await keystore.generate(options); // rejects with SeedVaultUnsupportedError
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare class SeedVaultUnsupportedError extends KeyStoreError {
|
|
56
|
+
/**
|
|
57
|
+
* @param operation - The name of the unsupported operation (e.g. `"generate"`).
|
|
58
|
+
* @param cause - The underlying error that caused this error, if any.
|
|
59
|
+
*/
|
|
60
|
+
constructor(operation: string, cause?: Error);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE;;;;;;;;;;;;GAYG;AACH,qBAAa,yBAA0B,SAAQ,aAAa;IAC1D;;;OAGG;gBACS,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM1C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,sBAAuB,SAAQ,aAAa;IACvD;;;OAGG;gBACS,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAMzC;AAED;;;;;;;;GAQG;AACH,qBAAa,yBAA0B,SAAQ,aAAa;IAC1D;;;OAGG;gBACS,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAU7C"}
|