@renown/sdk 6.2.2-dev.5 → 6.2.2-dev.51
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 +162 -1
- package/dist/{browser-key-storage-v4O-fjz0.js → browser-key-storage-e3RQsnLS.js} +1 -1
- package/dist/{browser-key-storage-v4O-fjz0.js.map → browser-key-storage-e3RQsnLS.js.map} +1 -1
- package/dist/constants-B7wOp9oo.js +79 -0
- package/dist/constants-B7wOp9oo.js.map +1 -0
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +2 -2
- package/dist/index-BF2qTv7d.d.ts +131 -0
- package/dist/index-BF2qTv7d.d.ts.map +1 -0
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -1
- package/dist/meta-CHgd9Qd0.js +31 -0
- package/dist/meta-CHgd9Qd0.js.map +1 -0
- package/dist/meta-D-5kvwx8.js +27 -0
- package/dist/meta-D-5kvwx8.js.map +1 -0
- package/dist/meta-DY5WCada.d.ts +19 -0
- package/dist/meta-DY5WCada.d.ts.map +1 -0
- package/dist/meta-DbqBJa4j.d.ts +19 -0
- package/dist/meta-DbqBJa4j.d.ts.map +1 -0
- package/dist/meta-DjoNJy1t.d.ts +16 -0
- package/dist/meta-DjoNJy1t.d.ts.map +1 -0
- package/dist/node.d.ts +11 -11
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +104 -12
- package/dist/node.js.map +1 -1
- package/dist/renown-builder-KOzzCXrQ.js +804 -0
- package/dist/renown-builder-KOzzCXrQ.js.map +1 -0
- package/dist/{signer-CgYhXTV7.js → signer-BpvojvCh.js} +13 -6
- package/dist/signer-BpvojvCh.js.map +1 -0
- package/dist/types-C_qc_62W.js +20 -0
- package/dist/types-C_qc_62W.js.map +1 -0
- package/dist/types-CxKG5UsV.d.ts +59 -0
- package/dist/types-CxKG5UsV.d.ts.map +1 -0
- package/dist/{signer-DYKGoYHB.d.ts → types-ocCFjR5j.d.ts} +128 -118
- package/dist/types-ocCFjR5j.d.ts.map +1 -0
- package/dist/{utils-C9ZgMs_C.d.ts → utils-DS2Ha4Bg.d.ts} +91 -96
- package/dist/utils-DS2Ha4Bg.d.ts.map +1 -0
- package/dist/wallet/index.d.ts +8 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +30 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/mock/factory.d.ts +9 -0
- package/dist/wallet/mock/factory.d.ts.map +1 -0
- package/dist/wallet/mock/factory.js +35 -0
- package/dist/wallet/mock/factory.js.map +1 -0
- package/dist/wallet/mock/index.d.ts +9 -0
- package/dist/wallet/mock/index.d.ts.map +1 -0
- package/dist/wallet/mock/index.js +16 -0
- package/dist/wallet/mock/index.js.map +1 -0
- package/dist/wallet/privy/factory.d.ts +58 -0
- package/dist/wallet/privy/factory.d.ts.map +1 -0
- package/dist/wallet/privy/factory.js +258 -0
- package/dist/wallet/privy/factory.js.map +1 -0
- package/dist/wallet/privy/index.d.ts +9 -0
- package/dist/wallet/privy/index.d.ts.map +1 -0
- package/dist/wallet/privy/index.js +16 -0
- package/dist/wallet/privy/index.js.map +1 -0
- package/dist/wallet/rainbow/factory.d.ts +7 -0
- package/dist/wallet/rainbow/factory.d.ts.map +1 -0
- package/dist/wallet/rainbow/factory.js +219 -0
- package/dist/wallet/rainbow/factory.js.map +1 -0
- package/dist/wallet/rainbow/index.d.ts +9 -0
- package/dist/wallet/rainbow/index.d.ts.map +1 -0
- package/dist/wallet/rainbow/index.js +21 -0
- package/dist/wallet/rainbow/index.js.map +1 -0
- package/package.json +76 -3
- package/dist/browser-key-storage-DSkDBAhU.d.ts +0 -14
- package/dist/browser-key-storage-DSkDBAhU.d.ts.map +0 -1
- package/dist/renown-builder-Sn_Y2Cb2.js +0 -496
- package/dist/renown-builder-Sn_Y2Cb2.js.map +0 -1
- package/dist/signer-CgYhXTV7.js.map +0 -1
- package/dist/signer-DYKGoYHB.d.ts.map +0 -1
- package/dist/utils-C9ZgMs_C.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -28,6 +28,16 @@ const renown = await new RenownBuilder("my-app")
|
|
|
28
28
|
- `withCrypto(crypto)` — Pre-built crypto instance
|
|
29
29
|
- `withKeyPairStorage(storage)` — Key pair storage (crypto is built from this)
|
|
30
30
|
- `withProfileFetcher(fetcher)` — Custom profile enrichment strategy
|
|
31
|
+
- `withChainId(chainId)` — Chain credentials are issued on (default `1`)
|
|
32
|
+
|
|
33
|
+
**The chain id is part of the user's identity.** The issuer DID is
|
|
34
|
+
`did:pkh:eip155:<chainId>:<address>`, so the same wallet on a different chain is a
|
|
35
|
+
different user. `signIn` therefore rejects a wallet session whose chain differs
|
|
36
|
+
from this one, and the bearer token is scoped to it too. When you pass a
|
|
37
|
+
pre-built crypto via `withCrypto()`, give it the same chain
|
|
38
|
+
(`RenownCryptoBuilder().withChainId(...)`) — the builder warns if the two
|
|
39
|
+
disagree. Keep the wallet adapters' `chains` in step, so the wallet UI prompts a
|
|
40
|
+
network switch instead of the user reaching a rejection at the end of the flow.
|
|
31
41
|
|
|
32
42
|
## Renown Instance
|
|
33
43
|
|
|
@@ -81,14 +91,165 @@ const { networkId, chainId, address } = parsePkhDid("did:pkh:eip155:1:0x...");
|
|
|
81
91
|
const result = await verifyAuthBearerToken(jwt); // false | AuthVerifiedCredential
|
|
82
92
|
```
|
|
83
93
|
|
|
94
|
+
## Wallet adapters (in-page sign-in)
|
|
95
|
+
|
|
96
|
+
`@renown/sdk/wallet` provides pluggable wallet adapters so a host app (e.g.
|
|
97
|
+
Connect) can sign a Renown credential **in-page**, without redirecting to the
|
|
98
|
+
Renown portal. Each adapter lives behind its own subexport and hands the host a
|
|
99
|
+
**descriptor** — eager metadata plus a lazy loader — so its wallet library is
|
|
100
|
+
fetched only when a login method is actually chosen.
|
|
101
|
+
|
|
102
|
+
**You pay for the adapters you import.** Importing `@renown/sdk/wallet/<id>`
|
|
103
|
+
loads no wallet library, but it does make that adapter's peer dependencies a
|
|
104
|
+
build-time requirement for your bundler. An app that never imports
|
|
105
|
+
`@renown/sdk/wallet/rainbow` does not need RainbowKit installed at all — no
|
|
106
|
+
bundler aliases, no stub modules.
|
|
107
|
+
|
|
108
|
+
| Subexport | Adapter | Peer dependencies to install |
|
|
109
|
+
| --- | --- | --- |
|
|
110
|
+
| `@renown/sdk/wallet/rainbow` | RainbowKit + wagmi (external wallets) | `wagmi`, `@rainbow-me/rainbowkit`, `@tanstack/react-query` |
|
|
111
|
+
| `@renown/sdk/wallet/privy` | Privy (embedded / social / email) | `@privy-io/react-auth` |
|
|
112
|
+
| `@renown/sdk/wallet/mock` | Headless test/dev signer (no UI) | none (`viem` is a direct dependency) |
|
|
113
|
+
|
|
114
|
+
Each subexport also has a `…/factory` sibling (e.g.
|
|
115
|
+
`@renown/sdk/wallet/privy/factory`) holding the `create<Id>Adapter` function.
|
|
116
|
+
That is the heavy half the descriptor's `load()` imports; you rarely need it
|
|
117
|
+
directly.
|
|
118
|
+
|
|
119
|
+
> **Host apps should not wire these adapters by hand.** Use the
|
|
120
|
+
> `RenownWalletProvider` + `useRenownLoginMethods` + `useRenownAuth` primitives
|
|
121
|
+
> from `@powerhousedao/reactor-browser/renown`, which handle the activator,
|
|
122
|
+
> lazy-loading, controller merging and login UI wiring. See that package's
|
|
123
|
+
> README ("Renown in-page sign-in"). `resolveAdapters` below is the low-level
|
|
124
|
+
> primitive those build on.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { resolveAdapters } from "@renown/sdk/wallet";
|
|
128
|
+
import { privyAdapter } from "@renown/sdk/wallet/privy";
|
|
129
|
+
import { rainbowAdapter } from "@renown/sdk/wallet/rainbow";
|
|
130
|
+
|
|
131
|
+
// Descriptors are cheap: metadata only, no wallet library loaded yet.
|
|
132
|
+
const descriptors = [
|
|
133
|
+
rainbowAdapter({ walletConnectProjectId: "..." }),
|
|
134
|
+
privyAdapter({ appId: "...", methods: ["google", "email"] }),
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
// This is where each adapter's library is actually fetched.
|
|
138
|
+
const adapters = await resolveAdapters(descriptors);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`resolveAdapters` keeps the adapters that loaded and logs the ones that didn't;
|
|
142
|
+
it rejects only if none load. Each resolved adapter exposes its `meta`, a
|
|
143
|
+
`Provider` (mount it around the app; it accepts a runtime `theme` of
|
|
144
|
+
`"light" | "dark" | { mode, accentColor?, accentColorForeground? }`) and a
|
|
145
|
+
controller with `connect(method?)`, `disconnect()`, and `getSession()`.
|
|
146
|
+
`connect()` resolves a `WalletSession` (`{ address, chainId, signTypedData }`);
|
|
147
|
+
pass it to `renown.signIn(session)` to write + log in the credential in-page.
|
|
148
|
+
|
|
149
|
+
Both adapters honour `mode` and `accentColor`. `accentColorForeground` is
|
|
150
|
+
RainbowKit-only — Privy derives its own contrast. Privy accepts hex only, so an
|
|
151
|
+
accent it cannot convert to hex (a named or `hsl()` color) is dropped rather than
|
|
152
|
+
forwarded; `rgb()`, which is what resolving a CSS token yields, converts fine.
|
|
153
|
+
|
|
154
|
+
**Login methods.** Rainbow supports `wallet`; Privy supports `wallet`, `google`,
|
|
155
|
+
`apple`, `email` (default `["google", "email"]`). Each adapter's config accepts
|
|
156
|
+
only the methods it can drive, so a typo is a compile error. Social/email flows
|
|
157
|
+
run inside Privy's own modal (OAuth uses a popup, keeping the page alive) so
|
|
158
|
+
sign-in completes in-page — no full-page redirect.
|
|
159
|
+
|
|
160
|
+
**Configuration.** Only public identifiers belong in client config: Privy's
|
|
161
|
+
`appId` (and optional `clientId`), and RainbowKit's `walletConnectProjectId`.
|
|
162
|
+
Never put a Privy **App Secret** in browser config — it is server-only.
|
|
163
|
+
|
|
164
|
+
`walletConnectProjectId` is optional, but treat it as required in practice: without
|
|
165
|
+
it the rainbow adapter offers only an installed browser wallet and the Safe App
|
|
166
|
+
iframe. Every other RainbowKit wallet connects over WalletConnect — `rainbowWallet`
|
|
167
|
+
always when its extension is absent, `metaMaskWallet` on desktop without the
|
|
168
|
+
extension — so those are omitted rather than offered and failing on the relay.
|
|
169
|
+
|
|
170
|
+
The rainbow adapter's `chains` (from `wagmi/chains`) defaults to Ethereum mainnet
|
|
171
|
+
alone, matching the chain credentials are issued on. Widen it only alongside
|
|
172
|
+
`withChainId`: a wallet on a chain outside the list has to switch networks to sign
|
|
173
|
+
in, and one that signs on a chain Renown does not issue on is rejected. The
|
|
174
|
+
adapter warns at config time if `chains` cannot produce the issuing chain.
|
|
175
|
+
|
|
84
176
|
## Node.js
|
|
85
177
|
|
|
86
|
-
For server-side usage, import from `@renown/sdk/node
|
|
178
|
+
For server-side usage, import from `@renown/sdk/node`.
|
|
179
|
+
|
|
180
|
+
**Building an instance (scripts / CLI).** The Node `RenownBuilder` uses file-based
|
|
181
|
+
storage. Its `build()` **blocks** on revalidating a stored credential against the
|
|
182
|
+
switchboard before resolving (so a short-lived process acts on fresh state); pass
|
|
183
|
+
`revalidate: "never"` to skip the network check.
|
|
87
184
|
|
|
88
185
|
```typescript
|
|
89
186
|
import { RenownBuilder } from "@renown/sdk/node";
|
|
187
|
+
|
|
188
|
+
const renown = await new RenownBuilder("my-cli", {
|
|
189
|
+
switchboardUrl: "https://switchboard.example/graphql",
|
|
190
|
+
}).build();
|
|
191
|
+
// renown.user is present only if the stored credential is still valid
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`renown.revalidate()` re-checks the current credential on demand and logs out if
|
|
195
|
+
it was revoked/expired; it is **fail-open** (a network error keeps the session).
|
|
196
|
+
On success it then calls `renown.refreshProfile()`.
|
|
197
|
+
|
|
198
|
+
`renown.refreshProfile()` re-reads profile attributes (`username`, `userImage`)
|
|
199
|
+
at the source and updates the store only if they changed, resolving `true` when
|
|
200
|
+
they did. It can never log anyone out, so the browser builder runs it on every
|
|
201
|
+
start — including when `revalidate: "never"` disables the credential check.
|
|
202
|
+
|
|
203
|
+
### Verifying a session cookie (SSR)
|
|
204
|
+
|
|
205
|
+
To gate server-rendered pages, store the bearer token from
|
|
206
|
+
`renown.getBearerToken()` — plus an optional `RenownSessionProfile` display hint
|
|
207
|
+
— in a cookie (name exported as `RENOWN_SESSION_COOKIE`), then verify it on the
|
|
208
|
+
server. The payload type `RenownSessionCookie` is exported from both entry
|
|
209
|
+
points; use it to type your route handler instead of redeclaring the shape:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import {
|
|
213
|
+
serializeRenownSessionCookie,
|
|
214
|
+
verifyRenownSession,
|
|
215
|
+
readSessionClaims,
|
|
216
|
+
} from "@renown/sdk/node";
|
|
217
|
+
|
|
218
|
+
// Build the cookie value (token + display hint) when setting the cookie. The
|
|
219
|
+
// documentId/username/userImage fields let verifySession rebuild `user.profile`.
|
|
220
|
+
const cookieValue = serializeRenownSessionCookie({
|
|
221
|
+
token,
|
|
222
|
+
profile: {
|
|
223
|
+
name: "alice.eth",
|
|
224
|
+
avatar: null,
|
|
225
|
+
documentId: "doc-123",
|
|
226
|
+
username: "alice.eth",
|
|
227
|
+
userImage: null,
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Verify the cookie value — checks the JWT (signature + expiry) and merges the
|
|
232
|
+
// display hint (unverified). verifyCredential:true also re-checks vs switchboard.
|
|
233
|
+
const session = await verifyRenownSession(cookieValue, {
|
|
234
|
+
switchboardUrl: "https://switchboard.example/graphql",
|
|
235
|
+
// verifyCredential: true, // default false = token-only, no network
|
|
236
|
+
});
|
|
237
|
+
if (session) {
|
|
238
|
+
// session.user (incl. display hint), session.appDid, session.expiresAt
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Cheap, signature-free decode for optimistic checks (e.g. a proxy redirect).
|
|
242
|
+
// NEVER trust this for access control.
|
|
243
|
+
const claims = readSessionClaims(cookieValue);
|
|
90
244
|
```
|
|
91
245
|
|
|
246
|
+
`verifyCredential` defaults to **`false`** (token-only, no network): the JWT is
|
|
247
|
+
signed and expiring, and the switchboard enforces the credential on every real
|
|
248
|
+
operation, so token-only is enough for optimistic SSR UI. Set it to `true` on
|
|
249
|
+
routes that render sensitive data to also catch revocation server-side. To
|
|
250
|
+
verify a bare bearer token (e.g. an `Authorization` header), use
|
|
251
|
+
`verifyAuthBearerToken` instead.
|
|
252
|
+
|
|
92
253
|
## License
|
|
93
254
|
|
|
94
255
|
AGPL-3.0-only
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-key-storage-
|
|
1
|
+
{"version":3,"file":"browser-key-storage-e3RQsnLS.js","names":["#db","#openDatabase","#useStore"],"sources":["../src/crypto/browser-key-storage.ts"],"sourcesContent":["import type { JsonWebKeyPairStorage, JwkKeyPair } from \"./types.js\";\n\nconst DEFAULT_DB_NAME = \"renownKeyDB\";\nconst STORE_NAME = \"keyPairs\";\nconst KEY = \"keyPair\";\n\nexport class BrowserKeyStorage implements JsonWebKeyPairStorage {\n #db: IDBDatabase;\n\n constructor(db: IDBDatabase) {\n this.#db = db;\n }\n\n static async create(\n dbName: string = DEFAULT_DB_NAME,\n ): Promise<BrowserKeyStorage> {\n const db = await BrowserKeyStorage.#openDatabase(dbName);\n return new BrowserKeyStorage(db);\n }\n\n static #openDatabase(dbName: string): Promise<IDBDatabase> {\n return new Promise((resolve, reject) => {\n const req = indexedDB.open(dbName);\n\n req.onupgradeneeded = (event) => {\n const db = (event.target as IDBOpenDBRequest).result;\n if (!db.objectStoreNames.contains(STORE_NAME)) {\n db.createObjectStore(STORE_NAME);\n }\n };\n\n req.onsuccess = () => {\n const db = req.result;\n if (!db.objectStoreNames.contains(STORE_NAME)) {\n const currentVersion = db.version;\n db.close();\n const upgradeReq = indexedDB.open(dbName, currentVersion + 1);\n upgradeReq.onupgradeneeded = (event) => {\n const upgradeDb = (event.target as IDBOpenDBRequest).result;\n if (!upgradeDb.objectStoreNames.contains(STORE_NAME)) {\n upgradeDb.createObjectStore(STORE_NAME);\n }\n };\n upgradeReq.onsuccess = () => resolve(upgradeReq.result);\n upgradeReq.onerror = () => reject(upgradeReq.error as Error);\n } else {\n resolve(db);\n }\n };\n\n req.onerror = () => reject(req.error as Error);\n });\n }\n\n #useStore(mode: IDBTransactionMode = \"readwrite\") {\n const transaction = this.#db.transaction(STORE_NAME, mode);\n return transaction.objectStore(STORE_NAME);\n }\n\n async saveKeyPair(keyPair: JwkKeyPair) {\n const store = this.#useStore();\n const request = store.put(keyPair, KEY);\n return new Promise<void>((resolve, reject) => {\n request.onsuccess = () => resolve();\n request.onerror = () => reject(new Error(\"Failed to save key pair\"));\n });\n }\n\n async loadKeyPair(): Promise<JwkKeyPair | undefined> {\n const store = this.#useStore(\"readonly\");\n const request = store.get(KEY);\n\n return new Promise<JwkKeyPair | undefined>((resolve, reject) => {\n request.onsuccess = () => {\n const keyPair = request.result as JwkKeyPair | undefined;\n resolve(keyPair);\n };\n request.onerror = () => reject(new Error(\"Failed to load key pair\"));\n });\n }\n\n async removeKeyPair(): Promise<void> {\n const store = this.#useStore();\n const request = store.delete(KEY);\n\n return new Promise<void>((resolve, reject) => {\n request.onsuccess = () => resolve();\n request.onerror = () => reject(new Error(\"Failed to remove key pair\"));\n });\n }\n}\n"],"mappings":";AAEA,MAAM,kBAAkB;AACxB,MAAM,aAAa;AACnB,MAAM,MAAM;AAEZ,IAAa,oBAAb,MAAa,kBAAmD;CAC9D;CAEA,YAAY,IAAiB;AAC3B,QAAA,KAAW;;CAGb,aAAa,OACX,SAAiB,iBACW;AAE5B,SAAO,IAAI,kBADA,MAAM,mBAAA,aAAgC,OAAO,CACxB;;CAGlC,QAAA,aAAqB,QAAsC;AACzD,SAAO,IAAI,SAAS,SAAS,WAAW;GACtC,MAAM,MAAM,UAAU,KAAK,OAAO;AAElC,OAAI,mBAAmB,UAAU;IAC/B,MAAM,KAAM,MAAM,OAA4B;AAC9C,QAAI,CAAC,GAAG,iBAAiB,SAAS,WAAW,CAC3C,IAAG,kBAAkB,WAAW;;AAIpC,OAAI,kBAAkB;IACpB,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#region src/constants.ts
|
|
2
|
+
const DEFAULT_RENOWN_URL = "https://www.renown.id";
|
|
3
|
+
const DEFAULT_RENOWN_NETWORK_ID = "eip155";
|
|
4
|
+
const DEFAULT_RENOWN_CHAIN_ID = "1";
|
|
5
|
+
/** Default cookie name for a server-readable Renown session (bearer token). */
|
|
6
|
+
const RENOWN_SESSION_COOKIE = "renown_session";
|
|
7
|
+
const DOMAIN_TYPE = [{
|
|
8
|
+
name: "version",
|
|
9
|
+
type: "string"
|
|
10
|
+
}, {
|
|
11
|
+
name: "chainId",
|
|
12
|
+
type: "uint256"
|
|
13
|
+
}];
|
|
14
|
+
const VERIFIABLE_CREDENTIAL_EIP712_TYPE = [
|
|
15
|
+
{
|
|
16
|
+
name: "@context",
|
|
17
|
+
type: "string[]"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "type",
|
|
21
|
+
type: "string[]"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "id",
|
|
25
|
+
type: "string"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "issuer",
|
|
29
|
+
type: "Issuer"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "credentialSubject",
|
|
33
|
+
type: "CredentialSubject"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "credentialSchema",
|
|
37
|
+
type: "CredentialSchema"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "issuanceDate",
|
|
41
|
+
type: "string"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "expirationDate",
|
|
45
|
+
type: "string"
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
const CREDENTIAL_SCHEMA_EIP712_TYPE = [{
|
|
49
|
+
name: "id",
|
|
50
|
+
type: "string"
|
|
51
|
+
}, {
|
|
52
|
+
name: "type",
|
|
53
|
+
type: "string"
|
|
54
|
+
}];
|
|
55
|
+
const CREDENTIAL_SUBJECT_TYPE = [{
|
|
56
|
+
name: "app",
|
|
57
|
+
type: "string"
|
|
58
|
+
}, {
|
|
59
|
+
name: "id",
|
|
60
|
+
type: "string"
|
|
61
|
+
}];
|
|
62
|
+
const ISSUER_TYPE = [{
|
|
63
|
+
name: "id",
|
|
64
|
+
type: "string"
|
|
65
|
+
}, {
|
|
66
|
+
name: "ethereumAddress",
|
|
67
|
+
type: "string"
|
|
68
|
+
}];
|
|
69
|
+
const CREDENTIAL_TYPES = {
|
|
70
|
+
EIP712Domain: DOMAIN_TYPE,
|
|
71
|
+
VerifiableCredential: VERIFIABLE_CREDENTIAL_EIP712_TYPE,
|
|
72
|
+
CredentialSchema: CREDENTIAL_SCHEMA_EIP712_TYPE,
|
|
73
|
+
CredentialSubject: CREDENTIAL_SUBJECT_TYPE,
|
|
74
|
+
Issuer: ISSUER_TYPE
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
export { DEFAULT_RENOWN_NETWORK_ID as a, ISSUER_TYPE as c, DEFAULT_RENOWN_CHAIN_ID as i, RENOWN_SESSION_COOKIE as l, CREDENTIAL_SUBJECT_TYPE as n, DEFAULT_RENOWN_URL as o, CREDENTIAL_TYPES as r, DOMAIN_TYPE as s, CREDENTIAL_SCHEMA_EIP712_TYPE as t, VERIFIABLE_CREDENTIAL_EIP712_TYPE as u };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=constants-B7wOp9oo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-B7wOp9oo.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_RENOWN_URL = \"https://www.renown.id\";\nexport const DEFAULT_RENOWN_NETWORK_ID = \"eip155\";\nexport const DEFAULT_RENOWN_CHAIN_ID = \"1\";\n\n/** Default cookie name for a server-readable Renown session (bearer token). */\nexport const RENOWN_SESSION_COOKIE = \"renown_session\";\n\nexport const DOMAIN_TYPE = [\n { name: \"version\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n] as const;\n\nexport const VERIFIABLE_CREDENTIAL_EIP712_TYPE = [\n { name: \"@context\", type: \"string[]\" },\n { name: \"type\", type: \"string[]\" },\n { name: \"id\", type: \"string\" },\n { name: \"issuer\", type: \"Issuer\" },\n { name: \"credentialSubject\", type: \"CredentialSubject\" },\n { name: \"credentialSchema\", type: \"CredentialSchema\" },\n { name: \"issuanceDate\", type: \"string\" },\n { name: \"expirationDate\", type: \"string\" },\n] as const;\n\nexport const CREDENTIAL_SCHEMA_EIP712_TYPE = [\n { name: \"id\", type: \"string\" },\n { name: \"type\", type: \"string\" },\n] as const;\n\nexport const CREDENTIAL_SUBJECT_TYPE = [\n { name: \"app\", type: \"string\" },\n { name: \"id\", type: \"string\" },\n] as const;\n\nexport const ISSUER_TYPE = [\n { name: \"id\", type: \"string\" },\n { name: \"ethereumAddress\", type: \"string\" },\n] as const;\n\nexport const CREDENTIAL_TYPES = {\n EIP712Domain: DOMAIN_TYPE,\n VerifiableCredential: VERIFIABLE_CREDENTIAL_EIP712_TYPE,\n CredentialSchema: CREDENTIAL_SCHEMA_EIP712_TYPE,\n CredentialSubject: CREDENTIAL_SUBJECT_TYPE,\n Issuer: ISSUER_TYPE,\n} as const;\n"],"mappings":";AAAA,MAAa,qBAAqB;AAClC,MAAa,4BAA4B;AACzC,MAAa,0BAA0B;;AAGvC,MAAa,wBAAwB;AAErC,MAAa,cAAc,CACzB;CAAE,MAAM;CAAW,MAAM;CAAU,EACnC;CAAE,MAAM;CAAW,MAAM;CAAW,CACrC;AAED,MAAa,oCAAoC;CAC/C;EAAE,MAAM;EAAY,MAAM;EAAY;CACtC;EAAE,MAAM;EAAQ,MAAM;EAAY;CAClC;EAAE,MAAM;EAAM,MAAM;EAAU;CAC9B;EAAE,MAAM;EAAU,MAAM;EAAU;CAClC;EAAE,MAAM;EAAqB,MAAM;EAAqB;CACxD;EAAE,MAAM;EAAoB,MAAM;EAAoB;CACtD;EAAE,MAAM;EAAgB,MAAM;EAAU;CACxC;EAAE,MAAM;EAAkB,MAAM;EAAU;CAC3C;AAED,MAAa,gCAAgC,CAC3C;CAAE,MAAM;CAAM,MAAM;CAAU,EAC9B;CAAE,MAAM;CAAQ,MAAM;CAAU,CACjC;AAED,MAAa,0BAA0B,CACrC;CAAE,MAAM;CAAO,MAAM;CAAU,EAC/B;CAAE,MAAM;CAAM,MAAM;CAAU,CAC/B;AAED,MAAa,cAAc,CACzB;CAAE,MAAM;CAAM,MAAM;CAAU,EAC9B;CAAE,MAAM;CAAmB,MAAM;CAAU,CAC5C;AAED,MAAa,mBAAmB;CAC9B,cAAc;CACd,sBAAsB;CACtB,kBAAkB;CAClB,mBAAmB;CACnB,QAAQ;CACT"}
|
package/dist/crypto.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { t as BrowserKeyStorage } from "./
|
|
1
|
+
import { a as JwkKeyPair, i as JsonWebKeyPairStorage, n as IConnectCrypto, r as IRenownCrypto, t as DID } from "./types-ocCFjR5j.js";
|
|
2
|
+
import { a as parseSignatureHashField, c as RenownCryptoBuilder, i as extractResultingHashFromSignature, l as ConnectCrypto, n as RenownCryptoSigner, o as signatureHasResultingHash, r as createSignatureVerifier, s as MemoryKeyStorage, t as BrowserKeyStorage, u as RenownCrypto } from "./index-BF2qTv7d.js";
|
|
3
3
|
export { BrowserKeyStorage, ConnectCrypto, DID, IConnectCrypto, IRenownCrypto, JsonWebKeyPairStorage, JwkKeyPair, MemoryKeyStorage, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, createSignatureVerifier, extractResultingHashFromSignature, parseSignatureHashField, signatureHasResultingHash };
|
package/dist/crypto.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as signatureHasResultingHash, c as ConnectCrypto, i as parseSignatureHashField, l as RenownCrypto, n as createSignatureVerifier, o as MemoryKeyStorage, r as extractResultingHashFromSignature, s as RenownCryptoBuilder, t as RenownCryptoSigner } from "./signer-
|
|
2
|
-
import { t as BrowserKeyStorage } from "./browser-key-storage-
|
|
1
|
+
import { a as signatureHasResultingHash, c as ConnectCrypto, i as parseSignatureHashField, l as RenownCrypto, n as createSignatureVerifier, o as MemoryKeyStorage, r as extractResultingHashFromSignature, s as RenownCryptoBuilder, t as RenownCryptoSigner } from "./signer-BpvojvCh.js";
|
|
2
|
+
import { t as BrowserKeyStorage } from "./browser-key-storage-e3RQsnLS.js";
|
|
3
3
|
export { BrowserKeyStorage, ConnectCrypto, MemoryKeyStorage, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, createSignatureVerifier, extractResultingHashFromSignature, parseSignatureHashField, signatureHasResultingHash };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { a as JwkKeyPair, i as JsonWebKeyPairStorage, l as CreateBearerTokenOptions, r as IRenownCrypto, t as DID, w as Issuer } from "./types-ocCFjR5j.js";
|
|
2
|
+
import { Action, AppActionSigner, ISigner, Signature, SignatureVerificationHandler, UserActionSigner } from "@powerhousedao/shared/document-model";
|
|
3
|
+
|
|
4
|
+
//#region src/crypto/renown-crypto.d.ts
|
|
5
|
+
declare class RenownCrypto implements IRenownCrypto {
|
|
6
|
+
#private;
|
|
7
|
+
readonly did: DID;
|
|
8
|
+
/** Chain id the bearer token is scoped to; keep it equal to the issuing Renown instance's. */
|
|
9
|
+
readonly chainId: number;
|
|
10
|
+
static algorithm: EcKeyAlgorithm;
|
|
11
|
+
static signAlgorithm: {
|
|
12
|
+
name: string;
|
|
13
|
+
namedCurve: string;
|
|
14
|
+
hash: string;
|
|
15
|
+
};
|
|
16
|
+
constructor(keyPairStorage: JsonWebKeyPairStorage, crypto: SubtleCrypto, keyPair: CryptoKeyPair, did: DID, chainId?: number);
|
|
17
|
+
get publicKey(): CryptoKey;
|
|
18
|
+
getBearerToken(address: string | undefined, options?: CreateBearerTokenOptions): Promise<string>;
|
|
19
|
+
removeDid(): Promise<void>;
|
|
20
|
+
sign(data: Uint8Array | string): Promise<Uint8Array>;
|
|
21
|
+
verify(data: Uint8Array, signature: Uint8Array): Promise<boolean>;
|
|
22
|
+
get issuer(): Issuer;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use RenownCrypto instead
|
|
26
|
+
*/
|
|
27
|
+
declare class ConnectCrypto extends RenownCrypto {}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/crypto/renown-crypto-builder.d.ts
|
|
30
|
+
declare class RenownCryptoBuilder {
|
|
31
|
+
#private;
|
|
32
|
+
private keyPairStorage?;
|
|
33
|
+
private subtleCrypto?;
|
|
34
|
+
private chainId?;
|
|
35
|
+
withKeyPairStorage(storage: JsonWebKeyPairStorage): this;
|
|
36
|
+
withSubtleCrypto(crypto: SubtleCrypto): this;
|
|
37
|
+
withChainId(chainId: number): this;
|
|
38
|
+
build(): Promise<RenownCrypto>;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/crypto/memory-key-storage.d.ts
|
|
42
|
+
declare class MemoryKeyStorage implements JsonWebKeyPairStorage {
|
|
43
|
+
private keyPair;
|
|
44
|
+
constructor(keyPair?: JwkKeyPair);
|
|
45
|
+
loadKeyPair(): Promise<JwkKeyPair | undefined>;
|
|
46
|
+
saveKeyPair(keyPair: JwkKeyPair): Promise<void>;
|
|
47
|
+
removeKeyPair(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/crypto/signer.d.ts
|
|
51
|
+
declare class RenownCryptoSigner implements ISigner {
|
|
52
|
+
private readonly crypto;
|
|
53
|
+
private readonly appName;
|
|
54
|
+
user?: UserActionSigner | undefined;
|
|
55
|
+
readonly app: AppActionSigner;
|
|
56
|
+
constructor(crypto: IRenownCrypto, appName: string, user?: UserActionSigner | undefined);
|
|
57
|
+
get publicKey(): CryptoKey;
|
|
58
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
59
|
+
verify(data: Uint8Array, signature: Uint8Array): Promise<void>;
|
|
60
|
+
signAction(action: Action, abortSignal?: AbortSignal): Promise<Signature>;
|
|
61
|
+
/**
|
|
62
|
+
* Signs an action including a predicted resulting state hash.
|
|
63
|
+
*
|
|
64
|
+
* The resulting hash is packed into the signature tuple's 4th element (index 3)
|
|
65
|
+
* using the format: `${prevStateHash}:${resultingStateHash}`
|
|
66
|
+
*
|
|
67
|
+
* This allows offline verification of documents without reducer logic:
|
|
68
|
+
* - Verifier can check that the signature is valid for the claimed resulting state
|
|
69
|
+
* - Verifier can compare claimed resulting state to actual operation.hash
|
|
70
|
+
*
|
|
71
|
+
* @param action - The action to sign
|
|
72
|
+
* @param resultingStateHash - The predicted hash of document state AFTER this action runs
|
|
73
|
+
* @param abortSignal - Optional abort signal
|
|
74
|
+
* @returns A Signature tuple with the resulting hash encoded in element [3]
|
|
75
|
+
*/
|
|
76
|
+
signActionWithResultingState(action: Action, resultingStateHash: string, abortSignal?: AbortSignal): Promise<Signature>;
|
|
77
|
+
/**
|
|
78
|
+
* Internal signing implementation shared by signAction and signActionWithResultingState.
|
|
79
|
+
*/
|
|
80
|
+
private _signAction;
|
|
81
|
+
private hashAction;
|
|
82
|
+
private buildSignatureMessage;
|
|
83
|
+
private arrayBufferToHex;
|
|
84
|
+
private arrayBufferToBase64;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a signature verification handler that verifies signatures using the Web Crypto API.
|
|
88
|
+
* The verification uses ECDSA with P-256 curve and SHA-256 hash, matching the RenownCrypto signing algorithm.
|
|
89
|
+
*/
|
|
90
|
+
declare function createSignatureVerifier(requireSignature?: boolean): SignatureVerificationHandler;
|
|
91
|
+
/**
|
|
92
|
+
* Parses the hash field (element [3]) from a signature tuple.
|
|
93
|
+
*
|
|
94
|
+
* Supports two formats:
|
|
95
|
+
* - Old format: just `prevStateHash` (no colon)
|
|
96
|
+
* - New format: `prevStateHash:resultingStateHash` (colon-separated)
|
|
97
|
+
*
|
|
98
|
+
* @param hashField - The 4th element of a Signature tuple
|
|
99
|
+
* @returns Object with prevStateHash and optional resultingStateHash
|
|
100
|
+
*/
|
|
101
|
+
declare function parseSignatureHashField(hashField: string): {
|
|
102
|
+
prevStateHash: string;
|
|
103
|
+
resultingStateHash: string | undefined;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Extracts the resulting state hash from a signature, if present.
|
|
107
|
+
*
|
|
108
|
+
* @param signature - A Signature tuple
|
|
109
|
+
* @returns The resulting state hash, or undefined if not present
|
|
110
|
+
*/
|
|
111
|
+
declare function extractResultingHashFromSignature(signature: Signature): string | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Checks if a signature includes a resulting state hash.
|
|
114
|
+
*
|
|
115
|
+
* @param signature - A Signature tuple
|
|
116
|
+
* @returns true if the signature includes a resulting state hash
|
|
117
|
+
*/
|
|
118
|
+
declare function signatureHasResultingHash(signature: Signature): boolean;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/crypto/browser-key-storage.d.ts
|
|
121
|
+
declare class BrowserKeyStorage implements JsonWebKeyPairStorage {
|
|
122
|
+
#private;
|
|
123
|
+
constructor(db: IDBDatabase);
|
|
124
|
+
static create(dbName?: string): Promise<BrowserKeyStorage>;
|
|
125
|
+
saveKeyPair(keyPair: JwkKeyPair): Promise<void>;
|
|
126
|
+
loadKeyPair(): Promise<JwkKeyPair | undefined>;
|
|
127
|
+
removeKeyPair(): Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { parseSignatureHashField as a, RenownCryptoBuilder as c, extractResultingHashFromSignature as i, ConnectCrypto as l, RenownCryptoSigner as n, signatureHasResultingHash as o, createSignatureVerifier as r, MemoryKeyStorage as s, BrowserKeyStorage as t, RenownCrypto as u };
|
|
131
|
+
//# sourceMappingURL=index-BF2qTv7d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BF2qTv7d.d.ts","names":[],"sources":["../src/crypto/renown-crypto.ts","../src/crypto/renown-crypto-builder.ts","../src/crypto/memory-key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A;EAAA,IAQZ,SAAA,CAAA,GAAS,SAAA;EAIP,IAAA,CAAK,IAAA,EAAM,UAAA,GAAa,OAAA,CAAQ,UAAA;EAIhC,MAAA,CAAO,IAAA,EAAM,UAAA,EAAY,SAAA,EAAW,UAAA,GAAa,OAAA;EAOjD,UAAA,CACJ,MAAA,EAAQ,MAAA,EACR,WAAA,GAAc,WAAA,GACb,OAAA,CAAQ,SAAA;EHNR;;;;;;;;;;;;;;;EG0BG,4BAAA,CACJ,MAAA,EAAQ,MAAA,EACR,kBAAA,UACA,WAAA,GAAc,WAAA,GACb,OAAA,CAAQ,SAAA;EHxDF;;;EAAA,QGiEK,WAAA;EAAA,QAiCA,UAAA;EAAA,QAYN,qBAAA;EAAA,QASA,gBAAA;EAAA,QAQA,mBAAA;AAAA;;;;;iBAcM,uBAAA,CACd,gBAAA,aACC,4BAAA;;;;;;;;;;;iBAgNa,uBAAA,CAAwB,SAAA;EACtC,aAAA;EACA,kBAAA;AAAA;;;;;;;iBAuBc,iCAAA,CACd,SAAA,EAAW,SAAA;;;;;;;iBAaG,yBAAA,CAA0B,SAAA,EAAW,SAAA;;;cCjZxC,iBAAA,YAA6B,qBAAA;EAAA;cAG5B,EAAA,EAAI,WAAA;EAAA,OAIH,MAAA,CACX,MAAA,YACC,OAAA,CAAQ,iBAAA;EA4CL,WAAA,CAAY,OAAA,EAAS,UAAA,GAAU,OAAA;EAS/B,WAAA,CAAA,GAAe,OAAA,CAAQ,UAAA;EAavB,aAAA,CAAA,GAAiB,OAAA;AAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { t as BrowserKeyStorage } from "./
|
|
3
|
-
import { C as
|
|
1
|
+
import { $ as IEventEmitter, A as LoginStatus, B as Service, C as InternalUser, D as JWTVerifyPolicies, E as JWTVerified, F as RenownEventEmitter, G as User, H as SignInParams, I as RenownEvents, J as VerifiedCredential, K as Verifiable, L as RenownProfile, M as PowerhouseVerifiableCredential, N as ProfileFetcher, O as JsonWebKey, P as Proof, R as RenownStorage, S as IVerifiableCredential, T as JWTPayload, U as Signer, V as ServiceEndpoint, W as Unsubscribe, X as W3CCredential, Y as VerifiedJWT, Z as BaseStorage, _ as IPowerhouseCredentialSubject, _t as DEFAULT_RENOWN_URL, a as JwkKeyPair, at as VerifiedAuthCredential, b as IRenown, bt as RENOWN_SESSION_COOKIE, c as ConditionWeightedThreshold, ct as fetchDelegationCredential, d as DIDDocument, dt as verifyCredentialSignature, et as BuildCredentialParams, f as DIDDocumentMetadata, ft as CREDENTIAL_SCHEMA_EIP712_TYPE, g as IAuthCredentialSubject, gt as DEFAULT_RENOWN_NETWORK_ID, h as EcdsaSignature, ht as DEFAULT_RENOWN_CHAIN_ID, i as JsonWebKeyPairStorage, it as SignCredentialTypedData, j as PKHDid, k as KeyCapabilitySection, l as CreateBearerTokenOptions, lt as recoverCredentialSigner, m as DIDResolutionResult, mt as CREDENTIAL_TYPES, n as IConnectCrypto, nt as CredentialMessage, o as AuthVerifiableCredential, ot as VerifyAuthCredentialOptions, p as DIDResolutionMetadata, pt as CREDENTIAL_SUBJECT_TYPE, q as VerificationMethod, r as IRenownCrypto, rt as FetchDelegationCredentialOptions, s as AuthVerifiedCredential, st as buildAndSignCredential, t as DID, tt as CredentialDomain, u as CredentialStatus, ut as verifyAuthCredential, v as IPowerhouseIssuerType, vt as DOMAIN_TYPE, w as Issuer, x as ISigner, xt as VERIFIABLE_CREDENTIAL_EIP712_TYPE, y as IProof, yt as ISSUER_TYPE, z as RenownStorageMap } from "./types-ocCFjR5j.js";
|
|
2
|
+
import { a as parseSignatureHashField, c as RenownCryptoBuilder, i as extractResultingHashFromSignature, l as ConnectCrypto, n as RenownCryptoSigner, o as signatureHasResultingHash, r as createSignatureVerifier, s as MemoryKeyStorage, t as BrowserKeyStorage, u as RenownCrypto } from "./index-BF2qTv7d.js";
|
|
3
|
+
import { C as SwitchboardClient, S as RenownMemoryStorage, _ as BaseRenownBuilder, a as getResolver, b as resolveSwitchboardEndpoint, d as RenownSessionProfile, g as fetchRenownProfile, i as createAuthBearerToken, n as VerifyAuthBearerTokenOptions, o as parsePkhDid, r as assertIsAuthCredential, s as verifyAuthBearerToken, t as ILogger, u as RenownSessionCookie, v as RenownBuilderOptions, x as Renown, y as ResolveSwitchboardEndpointOptions } from "./utils-DS2Ha4Bg.js";
|
|
4
4
|
|
|
5
5
|
//#region src/event/event.browser.d.ts
|
|
6
6
|
declare class BrowserEventEmitter<Events extends Record<string, unknown>> implements IEventEmitter<Events> {
|
|
@@ -22,13 +22,20 @@ declare class BrowserStorage<T extends Record<string, unknown> = Record<string,
|
|
|
22
22
|
//#region src/init.browser.d.ts
|
|
23
23
|
declare class BrowserRenownStorage extends BrowserStorage<RenownStorageMap> {}
|
|
24
24
|
declare class BrowserRenownEventEmitter extends BrowserEventEmitter<RenownEvents> {}
|
|
25
|
+
declare function readPersistedUser(basename?: string): User | undefined;
|
|
25
26
|
interface BrowserRenownBuilderOptions {
|
|
26
27
|
/** Base path for storage keys (e.g., "/app" for multi-tenant apps) */
|
|
27
28
|
basename?: string;
|
|
28
29
|
/** Renown server URL. Defaults to https://www.renown.id */
|
|
29
30
|
baseUrl?: string;
|
|
31
|
+
/** Switchboard GraphQL endpoint for the direct-to-reactor flow. */
|
|
32
|
+
switchboardUrl?: string;
|
|
30
33
|
/** IndexedDB database name for key storage. Defaults to "renownKeyDB" */
|
|
31
34
|
keyDbName?: string;
|
|
35
|
+
/** Re-check a stored credential on build (default "always"). */
|
|
36
|
+
revalidate?: "always" | "never";
|
|
37
|
+
/** Chain id credentials are issued on (default 1). It is part of the issuer DID, so `signIn` rejects a session from another chain. */
|
|
38
|
+
chainId?: number;
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* Browser-specific Renown builder with pre-configured defaults.
|
|
@@ -36,10 +43,6 @@ interface BrowserRenownBuilderOptions {
|
|
|
36
43
|
*/
|
|
37
44
|
declare class RenownBuilder extends BaseRenownBuilder {
|
|
38
45
|
#private;
|
|
39
|
-
/**
|
|
40
|
-
* @param appName - Application name used for signing context
|
|
41
|
-
* @param options - Browser-specific configuration options
|
|
42
|
-
*/
|
|
43
46
|
constructor(appName: string, options?: BrowserRenownBuilderOptions);
|
|
44
47
|
/**
|
|
45
48
|
* Set base path for storage keys (e.g., "/app" for multi-tenant apps).
|
|
@@ -65,5 +68,5 @@ declare class RenownBuilder extends BaseRenownBuilder {
|
|
|
65
68
|
*/
|
|
66
69
|
declare function initRenown(appName: string, options?: BrowserRenownBuilderOptions): Promise<Renown>;
|
|
67
70
|
//#endregion
|
|
68
|
-
export { AuthVerifiableCredential, AuthVerifiedCredential, BaseRenownBuilder, BrowserKeyStorage, BrowserRenownBuilderOptions, BrowserRenownEventEmitter, BrowserRenownStorage, BuildCredentialParams, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, ConditionWeightedThreshold, ConnectCrypto, CreateBearerTokenOptions, CredentialDomain, CredentialMessage, CredentialStatus, DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_NETWORK_ID, DEFAULT_RENOWN_URL, DID, DIDDocument, DIDDocumentMetadata, DIDResolutionMetadata, DIDResolutionResult, DOMAIN_TYPE, EcdsaSignature, FetchDelegationCredentialOptions, IAuthCredentialSubject, IConnectCrypto, ILogger, IPowerhouseCredentialSubject, IPowerhouseIssuerType, IProof, IRenown, IRenownCrypto, ISSUER_TYPE, ISigner, IVerifiableCredential, InternalUser, Issuer, JWTPayload, JWTVerified, JWTVerifyPolicies, JsonWebKey, JsonWebKeyPairStorage, JwkKeyPair, KeyCapabilitySection, LoginStatus, MemoryKeyStorage, PKHDid, PowerhouseVerifiableCredential, ProfileFetcher, Proof, Renown, RenownBuilder, RenownBuilderOptions, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, RenownEventEmitter, RenownEvents, RenownMemoryStorage, RenownProfile, RenownStorage, RenownStorageMap, Service, ServiceEndpoint, SignCredentialTypedData, Signer, Unsubscribe, User, VERIFIABLE_CREDENTIAL_EIP712_TYPE, Verifiable, VerificationMethod, VerifiedAuthCredential, VerifiedCredential, VerifiedJWT, VerifyAuthBearerTokenOptions, VerifyAuthCredentialOptions, W3CCredential, assertIsAuthCredential, buildAndSignCredential, createAuthBearerToken, createSignatureVerifier, extractResultingHashFromSignature, fetchDelegationCredential, fetchRenownProfile, getResolver, initRenown, parsePkhDid, parseSignatureHashField, recoverCredentialSigner, signatureHasResultingHash, verifyAuthBearerToken, verifyAuthCredential, verifyCredentialSignature };
|
|
71
|
+
export { AuthVerifiableCredential, AuthVerifiedCredential, BaseRenownBuilder, BrowserKeyStorage, BrowserRenownBuilderOptions, BrowserRenownEventEmitter, BrowserRenownStorage, BuildCredentialParams, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, ConditionWeightedThreshold, ConnectCrypto, CreateBearerTokenOptions, CredentialDomain, CredentialMessage, CredentialStatus, DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_NETWORK_ID, DEFAULT_RENOWN_URL, DID, DIDDocument, DIDDocumentMetadata, DIDResolutionMetadata, DIDResolutionResult, DOMAIN_TYPE, EcdsaSignature, FetchDelegationCredentialOptions, IAuthCredentialSubject, IConnectCrypto, ILogger, IPowerhouseCredentialSubject, IPowerhouseIssuerType, IProof, IRenown, IRenownCrypto, ISSUER_TYPE, ISigner, IVerifiableCredential, InternalUser, Issuer, JWTPayload, JWTVerified, JWTVerifyPolicies, JsonWebKey, JsonWebKeyPairStorage, JwkKeyPair, KeyCapabilitySection, LoginStatus, MemoryKeyStorage, PKHDid, PowerhouseVerifiableCredential, ProfileFetcher, Proof, RENOWN_SESSION_COOKIE, Renown, RenownBuilder, RenownBuilderOptions, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, RenownEventEmitter, RenownEvents, RenownMemoryStorage, RenownProfile, type RenownSessionCookie, type RenownSessionProfile, RenownStorage, RenownStorageMap, ResolveSwitchboardEndpointOptions, Service, ServiceEndpoint, SignCredentialTypedData, SignInParams, Signer, SwitchboardClient, Unsubscribe, User, VERIFIABLE_CREDENTIAL_EIP712_TYPE, Verifiable, VerificationMethod, VerifiedAuthCredential, VerifiedCredential, VerifiedJWT, VerifyAuthBearerTokenOptions, VerifyAuthCredentialOptions, W3CCredential, assertIsAuthCredential, buildAndSignCredential, createAuthBearerToken, createSignatureVerifier, extractResultingHashFromSignature, fetchDelegationCredential, fetchRenownProfile, getResolver, initRenown, parsePkhDid, parseSignatureHashField, readPersistedUser, recoverCredentialSigner, resolveSwitchboardEndpoint, signatureHasResultingHash, verifyAuthBearerToken, verifyAuthCredential, verifyCredentialSignature };
|
|
69
72
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/event/event.browser.ts","../src/storage/storage.browser.ts","../src/init.browser.ts"],"mappings":";;;;;cAQa,mBAAA,gBACI,MAAA,8BACJ,aAAA,CAAc,MAAA;EAAA;EAGzB,EAAA,iBAAmB,MAAA,CAAA,CACjB,KAAA,EAAO,CAAA,EACP,QAAA,GAAW,IAAA,EAAM,MAAA,CAAO,CAAA;EAc1B,IAAA,iBAAqB,MAAA,CAAA,CAAQ,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,MAAA,CAAO,CAAA;AAAA;;;cC3BzC,cAAA,WACD,MAAA,oBAA0B,MAAA,2BAC5B,WAAA,CAAY,CAAA;EAAA;mBACH,SAAA;cAEL,SAAA,UAAmB,QAAA;EAQ/B,GAAA,mBAAsB,CAAA,CAAA,CAAG,GAAA,EAAK,GAAA,GAAM,CAAA,CAAE,GAAA;EAQtC,GAAA,mBAAsB,CAAA,CAAA,CAAG,GAAA,EAAK,GAAA,EAAK,KAAA,GAAQ,CAAA,CAAE,GAAA;EAM7C,MAAA,CAAO,GAAA,QAAW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,CAAc,SAAA;EF/C+B;;;;EEwDvC,KAAA,CAAA,GAAS,OAAA,CAAQ,MAAA;AAAA;;;ADnFzB;;;;;iBC2GgB,UAAA,CACd,OAAA,UACA,OAAA,GAAS,2BAAA,GAAgC,OAAA,CAAA,MAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import { t as
|
|
1
|
+
import { a as DEFAULT_RENOWN_NETWORK_ID, c as ISSUER_TYPE, i as DEFAULT_RENOWN_CHAIN_ID, l as RENOWN_SESSION_COOKIE, n as CREDENTIAL_SUBJECT_TYPE, o as DEFAULT_RENOWN_URL, r as CREDENTIAL_TYPES, s as DOMAIN_TYPE, t as CREDENTIAL_SCHEMA_EIP712_TYPE, u as VERIFIABLE_CREDENTIAL_EIP712_TYPE } from "./constants-B7wOp9oo.js";
|
|
2
|
+
import { a as BaseStorage, c as recoverCredentialSigner, d as SwitchboardClient, f as resolveSwitchboardEndpoint, i as RenownMemoryStorage, l as verifyAuthCredential, n as fetchRenownProfile, o as buildAndSignCredential, r as Renown, s as fetchDelegationCredential, t as BaseRenownBuilder, u as verifyCredentialSignature } from "./renown-builder-KOzzCXrQ.js";
|
|
3
|
+
import { a as signatureHasResultingHash, c as ConnectCrypto, d as createAuthBearerToken, f as getResolver, i as parseSignatureHashField, l as RenownCrypto, m as verifyAuthBearerToken, n as createSignatureVerifier, o as MemoryKeyStorage, p as parsePkhDid, r as extractResultingHashFromSignature, s as RenownCryptoBuilder, t as RenownCryptoSigner, u as assertIsAuthCredential } from "./signer-BpvojvCh.js";
|
|
4
|
+
import { t as BrowserKeyStorage } from "./browser-key-storage-e3RQsnLS.js";
|
|
4
5
|
//#region src/event/event.browser.ts
|
|
5
6
|
var TypedCustomEvent = class extends CustomEvent {
|
|
6
7
|
constructor(type, detail) {
|
|
@@ -49,6 +50,14 @@ var BrowserStorage = class extends BaseStorage {
|
|
|
49
50
|
//#region src/init.browser.ts
|
|
50
51
|
var BrowserRenownStorage = class extends BrowserStorage {};
|
|
51
52
|
var BrowserRenownEventEmitter = class extends BrowserEventEmitter {};
|
|
53
|
+
function readPersistedUser(basename) {
|
|
54
|
+
if (typeof localStorage === "undefined") return void 0;
|
|
55
|
+
try {
|
|
56
|
+
return new BrowserStorage("renown", basename).get("user");
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
52
61
|
/**
|
|
53
62
|
* Browser-specific Renown builder with pre-configured defaults.
|
|
54
63
|
* Uses localStorage for user data and IndexedDB for key storage.
|
|
@@ -56,17 +65,17 @@ var BrowserRenownEventEmitter = class extends BrowserEventEmitter {};
|
|
|
56
65
|
var RenownBuilder = class extends BaseRenownBuilder {
|
|
57
66
|
#basename;
|
|
58
67
|
#keyDbName;
|
|
59
|
-
|
|
60
|
-
* @param appName - Application name used for signing context
|
|
61
|
-
* @param options - Browser-specific configuration options
|
|
62
|
-
*/
|
|
68
|
+
#revalidate;
|
|
63
69
|
constructor(appName, options = {}) {
|
|
64
70
|
super(appName);
|
|
65
71
|
this.#basename = options.basename;
|
|
66
72
|
this.#keyDbName = options.keyDbName;
|
|
73
|
+
this.#revalidate = options.revalidate ?? "always";
|
|
67
74
|
this.withStorage(new BrowserRenownStorage("renown", this.#basename));
|
|
68
75
|
this.withEventEmitter(new BrowserRenownEventEmitter());
|
|
69
76
|
if (options.baseUrl) this.withBaseUrl(options.baseUrl);
|
|
77
|
+
if (options.switchboardUrl) this.withSwitchboardUrl(options.switchboardUrl);
|
|
78
|
+
if (options.chainId !== void 0) this.withChainId(options.chainId);
|
|
70
79
|
}
|
|
71
80
|
/**
|
|
72
81
|
* Set base path for storage keys (e.g., "/app" for multi-tenant apps).
|
|
@@ -91,7 +100,10 @@ var RenownBuilder = class extends BaseRenownBuilder {
|
|
|
91
100
|
async build() {
|
|
92
101
|
const keyStorage = await BrowserKeyStorage.create(this.#keyDbName);
|
|
93
102
|
this.withKeyPairStorage(keyStorage);
|
|
94
|
-
|
|
103
|
+
const renown = await super.build();
|
|
104
|
+
if (renown.user) if (this.#revalidate === "always") renown.revalidate();
|
|
105
|
+
else renown.refreshProfile();
|
|
106
|
+
return renown;
|
|
95
107
|
}
|
|
96
108
|
};
|
|
97
109
|
/**
|
|
@@ -105,6 +117,6 @@ function initRenown(appName, options = {}) {
|
|
|
105
117
|
return new RenownBuilder(appName, options).build();
|
|
106
118
|
}
|
|
107
119
|
//#endregion
|
|
108
|
-
export { BaseRenownBuilder, BrowserKeyStorage, BrowserRenownEventEmitter, BrowserRenownStorage, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, ConnectCrypto, DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_NETWORK_ID, DEFAULT_RENOWN_URL, DOMAIN_TYPE, ISSUER_TYPE, MemoryKeyStorage, Renown, RenownBuilder, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, RenownMemoryStorage, VERIFIABLE_CREDENTIAL_EIP712_TYPE, assertIsAuthCredential, buildAndSignCredential, createAuthBearerToken, createSignatureVerifier, extractResultingHashFromSignature, fetchDelegationCredential, fetchRenownProfile, getResolver, initRenown, parsePkhDid, parseSignatureHashField, recoverCredentialSigner, signatureHasResultingHash, verifyAuthBearerToken, verifyAuthCredential, verifyCredentialSignature };
|
|
120
|
+
export { BaseRenownBuilder, BrowserKeyStorage, BrowserRenownEventEmitter, BrowserRenownStorage, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, ConnectCrypto, DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_NETWORK_ID, DEFAULT_RENOWN_URL, DOMAIN_TYPE, ISSUER_TYPE, MemoryKeyStorage, RENOWN_SESSION_COOKIE, Renown, RenownBuilder, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, RenownMemoryStorage, SwitchboardClient, VERIFIABLE_CREDENTIAL_EIP712_TYPE, assertIsAuthCredential, buildAndSignCredential, createAuthBearerToken, createSignatureVerifier, extractResultingHashFromSignature, fetchDelegationCredential, fetchRenownProfile, getResolver, initRenown, parsePkhDid, parseSignatureHashField, readPersistedUser, recoverCredentialSigner, resolveSwitchboardEndpoint, signatureHasResultingHash, verifyAuthBearerToken, verifyAuthCredential, verifyCredentialSignature };
|
|
109
121
|
|
|
110
122
|
//# sourceMappingURL=index.js.map
|