@renown/sdk 6.2.2-dev.9 → 6.2.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 +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-BexAR53F.js +82 -0
- package/dist/constants-BexAR53F.js.map +1 -0
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +2 -2
- package/dist/index-BLIpkdF7.d.ts +131 -0
- package/dist/index-BLIpkdF7.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/local-credential-verifier-CU8hmFlR.js +907 -0
- package/dist/local-credential-verifier-CU8hmFlR.js.map +1 -0
- package/dist/meta-BesJP74N.d.ts +19 -0
- package/dist/meta-BesJP74N.d.ts.map +1 -0
- 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-bV7L-1yb.d.ts +19 -0
- package/dist/meta-bV7L-1yb.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/{signer-CgYhXTV7.js → signer-DrjINLqt.js} +13 -6
- package/dist/signer-DrjINLqt.js.map +1 -0
- package/dist/{signer-DYKGoYHB.d.ts → types-BGQKPoUr.d.ts} +170 -118
- package/dist/types-BGQKPoUr.d.ts.map +1 -0
- package/dist/types-C-hJrsQg.d.ts +59 -0
- package/dist/types-C-hJrsQg.d.ts.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-DInveFLz.d.ts +63 -0
- package/dist/types-DInveFLz.d.ts.map +1 -0
- package/dist/{utils-C9ZgMs_C.d.ts → utils-DtWREYeO.d.ts} +81 -94
- package/dist/utils-DtWREYeO.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 +79 -0
- package/dist/wallet/privy/factory.d.ts.map +1 -0
- package/dist/wallet/privy/factory.js +382 -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 +77 -4
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-credential-verifier-CU8hmFlR.js","names":["#endpoint","#transport","#post","#request","#legacyMutate","#store","#eventEmitter","#baseUrl","#crypto","#appName","#profileFetcher","#switchboard","#chainId","#signer","#status","#updateStatus","#getCredential","#updateUser","#completeLogin","#listeners","#appName","#storage","#eventEmitter","#crypto","#keyPairStorage","#baseUrl","#switchboardUrl","#chainId","#profileFetcher"],"sources":["../src/discovery.ts","../src/switchboard.ts","../src/credential.ts","../src/storage/common.ts","../src/common.ts","../src/event/memory.ts","../src/profile.ts","../src/renown-builder.ts","../src/local-credential-verifier.ts"],"sourcesContent":["export interface ResolveSwitchboardEndpointOptions {\n // Explicit Switchboard GraphQL endpoint. When set, used directly.\n switchboardUrl?: string;\n // Renown base URL to ask for a switchboard endpoint when none is explicit.\n baseUrl?: string;\n // Max time (ms) to wait for the discovery probe before falling back to REST.\n timeoutMs?: number;\n}\n\n// Legacy Renown instances accept the connection but never respond to the\n// discovery request; without a bound, `fetch` hangs and blocks startup.\nconst DEFAULT_DISCOVERY_TIMEOUT_MS = 3000;\n\n// Shape returned by the Renown app's `/api/switchboard` discovery endpoint.\ninterface DiscoveryResponse {\n endpoint?: string;\n}\n\n// Resolve the Switchboard GraphQL endpoint: explicit `switchboardUrl` wins,\n// else discover via `{baseUrl}/api/switchboard`; undefined means use REST.\nexport async function resolveSwitchboardEndpoint(\n options: ResolveSwitchboardEndpointOptions,\n): Promise<string | undefined> {\n const { switchboardUrl, baseUrl, timeoutMs } = options;\n\n if (switchboardUrl) {\n return switchboardUrl;\n }\n\n if (!baseUrl) {\n return undefined;\n }\n\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n timeoutMs ?? DEFAULT_DISCOVERY_TIMEOUT_MS,\n );\n\n try {\n const url = new URL(\"/api/switchboard\", baseUrl);\n const response = await fetch(url, {\n method: \"GET\",\n signal: controller.signal,\n });\n if (!response.ok) {\n return undefined;\n }\n const body = (await response.json()) as DiscoveryResponse;\n return body.endpoint || undefined;\n } catch {\n // Old Renown instances never answer (or lack the endpoint); the abort\n // timeout rejects here so we fall back to the REST flow instead of hanging.\n return undefined;\n } finally {\n clearTimeout(timeout);\n }\n}\n","import {\n createAction,\n type Action,\n} from \"@powerhousedao/shared/document-model\";\nimport { CREDENTIAL_TYPES } from \"./constants.js\";\nimport type {\n PowerhouseVerifiableCredential,\n ProfileFetcher,\n RenownProfile,\n} from \"./types.js\";\n\n/** Thrown by `signIn` when the instance has no switchboard to write the\n * credential to, so a host can fall back to the Renown redirect flow. */\nexport class MissingSwitchboardError extends Error {\n constructor() {\n super(\n \"signIn requires a switchboard endpoint. Set switchboardUrl or a discoverable baseUrl.\",\n );\n this.name = \"MissingSwitchboardError\";\n }\n\n /** `instanceof` fails across duplicate SDK copies, so match by name too. */\n static is(error: unknown): error is MissingSwitchboardError {\n return (\n error instanceof MissingSwitchboardError ||\n (error instanceof Error && error.name === \"MissingSwitchboardError\")\n );\n }\n}\n\n// Per-user drive convention shared with the Renown app: `renown-<address>`.\n// The read-model ignores driveId, but we pass it for parity.\nfunction userDriveId(address: string): string {\n return `renown-${address.toLowerCase()}`;\n}\n\n// Flat row returned by the `renownCredentials` read-model query.\ninterface ReadRenownCredential {\n documentId: string;\n credentialId: string;\n context: string[];\n type: string[];\n issuerId: string;\n issuerEthereumAddress: string;\n issuanceDate: string;\n expirationDate: string | null;\n credentialSubjectId: string | null;\n credentialSubjectApp: string;\n credentialStatusId: string | null;\n credentialStatusType: string | null;\n credentialSchemaId: string;\n credentialSchemaType: string;\n proofVerificationMethod: string;\n proofEthereumAddress: string;\n proofCreated: string;\n proofPurpose: string;\n proofType: string;\n proofValue: string;\n proofEip712Domain: string;\n proofEip712PrimaryType: string;\n revoked: boolean;\n}\n\n// Flat row returned by the `renownUsers` read-model query.\ninterface ReadRenownUser {\n documentId: string;\n username: string | null;\n ethAddress: string | null;\n userImage: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\nconst CREDENTIALS_QUERY = /* GraphQL */ `\n query RenownCredentials($input: RenownCredentialsInput!) {\n renownCredentials(input: $input) {\n documentId\n credentialId\n context\n type\n issuerId\n issuerEthereumAddress\n issuanceDate\n expirationDate\n credentialSubjectId\n credentialSubjectApp\n credentialStatusId\n credentialStatusType\n credentialSchemaId\n credentialSchemaType\n proofVerificationMethod\n proofEthereumAddress\n proofCreated\n proofPurpose\n proofType\n proofValue\n proofEip712Domain\n proofEip712PrimaryType\n revoked\n }\n }\n`;\n\nconst USERS_QUERY = /* GraphQL */ `\n query RenownUsers($input: RenownUsersInput!) {\n renownUsers(input: $input) {\n documentId\n username\n ethAddress\n userImage\n createdAt\n updatedAt\n }\n }\n`;\n\nconst CREATE_EMPTY_DOCUMENT_MUTATION = /* GraphQL */ `\n mutation CreateEmptyDocument(\n $documentType: String!\n $parentIdentifier: String\n ) {\n createEmptyDocument(\n documentType: $documentType\n parentIdentifier: $parentIdentifier\n ) {\n id\n }\n }\n`;\n\nconst MUTATE_DOCUMENT_MUTATION = /* GraphQL */ `\n mutation MutateDocument(\n $documentIdentifier: String!\n $actions: [ActionInput!]!\n ) {\n mutateDocument: execute(\n documentIdentifier: $documentIdentifier\n actions: $actions\n ) {\n id\n }\n }\n`;\n\n/* Switchboards older than 6.2.2-dev.54 have no `execute`; their `mutateDocument`\n takes the same envelopes as untyped JSON. Same selection, so one result shape. */\nconst LEGACY_MUTATE_DOCUMENT_MUTATION = /* GraphQL */ `\n mutation MutateDocument(\n $documentIdentifier: String!\n $actions: [JSONObject!]!\n ) {\n mutateDocument(documentIdentifier: $documentIdentifier, actions: $actions) {\n id\n }\n }\n`;\n\n// graphql-js validation failure for a field the server's schema lacks.\nfunction isUnknownExecuteField(error: unknown): boolean {\n return (\n error instanceof Error &&\n /Cannot query field \"execute\" on type \"Mutation\"/.test(error.message)\n );\n}\n\nconst RENOWN_CREDENTIAL_DOC_TYPE = \"powerhouse/renown-credential\";\nconst RENOWN_USER_DOC_TYPE = \"powerhouse/renown-user\";\n\n// Rebuild the nested EIP-712 verifiable credential from a flat read-model row.\nfunction reshapeCredential(\n row: ReadRenownCredential,\n): PowerhouseVerifiableCredential {\n // `proofEip712Domain` is stored as a JSON string ({ version, chainId }).\n const domain = JSON.parse(row.proofEip712Domain) as {\n version: string;\n chainId: number;\n };\n\n return {\n \"@context\": row.context,\n type: row.type,\n id: row.credentialId,\n issuer: {\n id: row.issuerId,\n ethereumAddress: row.issuerEthereumAddress as `0x${string}`,\n },\n credentialSubject: {\n id: row.credentialSubjectId ?? \"\",\n app: row.credentialSubjectApp,\n },\n credentialSchema: {\n id: row.credentialSchemaId,\n type: row.credentialSchemaType,\n },\n ...(row.credentialStatusId\n ? {\n credentialStatus: {\n id: row.credentialStatusId,\n type: row.credentialStatusType ?? \"\",\n },\n }\n : {}),\n issuanceDate: row.issuanceDate,\n expirationDate: row.expirationDate ?? \"\",\n proof: {\n type: row.proofType,\n created: row.proofCreated,\n verificationMethod: row.proofVerificationMethod,\n proofPurpose: row.proofPurpose,\n proofValue: row.proofValue,\n ethereumAddress: row.proofEthereumAddress as `0x${string}`,\n eip712: {\n domain,\n types: CREDENTIAL_TYPES,\n primaryType: \"VerifiableCredential\",\n },\n },\n };\n}\n\n// The chain id in a `did:pkh:<net>:<chainId>:<address>` issuer id.\nfunction issuerChainId(issuerId: string): string | undefined {\n return issuerId.split(\":\")[3];\n}\n\n// The address in a `did:pkh:<net>:<chainId>:<address>` issuer id.\nfunction issuerDidAddress(issuerId: string): string | undefined {\n return issuerId.split(\":\")[4];\n}\n\n// Re-check the delegation binding instead of trusting the read-model's\n// `did`/`ethAddress` filters, matching the REST path in `credential.ts`.\nfunction bindsTo(\n row: ReadRenownCredential,\n address: string,\n chainId: number,\n appDid: string,\n): boolean {\n const expected = address.toLowerCase();\n return (\n !row.revoked &&\n row.credentialSubjectId === appDid &&\n issuerChainId(row.issuerId) === String(chainId) &&\n issuerDidAddress(row.issuerId)?.toLowerCase() === expected &&\n row.issuerEthereumAddress.toLowerCase() === expected\n );\n}\n\n/** Runs a GraphQL document against a Switchboard and resolves its `data`;\n * throws on transport or GraphQL errors. */\nexport type SwitchboardRequestFn = (\n query: string,\n variables: Record<string, unknown>,\n) => Promise<unknown>;\n\n/** Where a SwitchboardClient reads from: an HTTP endpoint or a local executor. */\nexport type SwitchboardSource = string | SwitchboardRequestFn;\n\n// Reads and writes a Switchboard reactor's `renown-read-model` subgraph and\n// document mutations over GraphQL, replacing the Renown Next.js REST proxy.\nexport class SwitchboardClient {\n #endpoint: string | undefined;\n #transport: SwitchboardRequestFn;\n // Set once the switchboard has rejected `execute`, so later writes skip the probe.\n #legacyMutate = false;\n\n constructor(source: SwitchboardSource) {\n if (typeof source === \"string\") {\n this.#endpoint = source;\n this.#transport = (query, variables) =>\n this.#post(source, query, variables);\n } else {\n this.#transport = source;\n }\n }\n\n /** The HTTP endpoint, or undefined when reading through a local executor. */\n get endpoint(): string | undefined {\n return this.#endpoint;\n }\n\n async #post(\n endpoint: string,\n query: string,\n variables: Record<string, unknown>,\n ): Promise<unknown> {\n const response = await fetch(endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ query, variables }),\n });\n /* A validation failure comes back as 400 WITH a GraphQL error body, so read\n it before judging the status: the messages say what was wrong, the code\n only that something was. */\n const body = (await response.json().catch(() => undefined)) as\n | { data?: unknown; errors?: { message: string }[] }\n | undefined;\n if (body?.errors?.length) {\n throw new Error(body.errors.map((e) => e.message).join(\"; \"));\n }\n if (!response.ok || !body) {\n throw new Error(`Switchboard request failed: ${response.status}`);\n }\n // `#request` rejects an empty `data` for every transport, HTTP or local.\n return body.data;\n }\n\n async #request<T>(\n query: string,\n variables: Record<string, unknown>,\n ): Promise<T> {\n const data = await this.#transport(query, variables);\n if (!data) {\n throw new Error(\"Switchboard returned no data\");\n }\n return data as T;\n }\n\n // Fetch the active delegation credential for (address, chainId) that delegates\n // to `appDid`: re-check the binding, drop expired, return most recent.\n async getCredential(params: {\n address: string;\n chainId: number;\n appDid: string;\n }): Promise<PowerhouseVerifiableCredential | undefined> {\n const { address, chainId, appDid } = params;\n const { renownCredentials } = await this.#request<{\n renownCredentials: ReadRenownCredential[];\n }>(CREDENTIALS_QUERY, {\n input: {\n driveId: userDriveId(address),\n ethAddress: address.toLowerCase(),\n did: appDid,\n includeRevoked: false,\n },\n });\n\n const now = Date.now();\n const candidates = renownCredentials\n .filter((row) => bindsTo(row, address, chainId, appDid))\n .filter((row) => {\n if (!row.expirationDate) return true;\n const expiresAt = Date.parse(row.expirationDate);\n return !Number.isNaN(expiresAt) && expiresAt > now;\n })\n .sort((a, b) => Date.parse(b.issuanceDate) - Date.parse(a.issuanceDate));\n\n const mostRecent = candidates.at(0);\n return mostRecent ? reshapeCredential(mostRecent) : undefined;\n }\n\n // Look up a Renown profile by ethereum address via the `renownUsers` query.\n async getProfileByAddress(\n address: string,\n ): Promise<RenownProfile | undefined> {\n const { renownUsers } = await this.#request<{\n renownUsers: ReadRenownUser[];\n }>(USERS_QUERY, {\n input: {\n driveId: userDriveId(address),\n ethAddresses: [address.toLowerCase()],\n },\n });\n\n const user = renownUsers.at(0);\n if (!user) return undefined;\n return {\n documentId: user.documentId,\n username: user.username,\n ethAddress: user.ethAddress,\n userImage: user.userImage,\n createdAt: user.createdAt,\n updatedAt: user.updatedAt,\n };\n }\n\n // Create an empty document of the given type; returns its document id.\n async createEmptyDocument(\n documentType: string,\n parentIdentifier?: string,\n ): Promise<string> {\n const { createEmptyDocument } = await this.#request<{\n createEmptyDocument: { id: string };\n }>(CREATE_EMPTY_DOCUMENT_MUTATION, { documentType, parentIdentifier });\n return createEmptyDocument.id;\n }\n\n // Apply reactor action envelopes to a document; returns its document id.\n async mutateDocument(\n documentIdentifier: string,\n actions: Action[],\n ): Promise<string> {\n const variables = { documentIdentifier, actions };\n if (!this.#legacyMutate) {\n try {\n const { mutateDocument } = await this.#request<{\n mutateDocument: { id: string };\n }>(MUTATE_DOCUMENT_MUTATION, variables);\n return mutateDocument.id;\n } catch (error) {\n if (!isUnknownExecuteField(error)) throw error;\n this.#legacyMutate = true;\n }\n }\n const { mutateDocument } = await this.#request<{\n mutateDocument: { id: string };\n }>(LEGACY_MUTATE_DOCUMENT_MUTATION, variables);\n return mutateDocument.id;\n }\n\n // Issue a signed credential: create a renown-credential doc and INIT it.\n async issueCredential(\n credential: PowerhouseVerifiableCredential,\n parentIdentifier?: string,\n ): Promise<string> {\n const documentId = await this.createEmptyDocument(\n RENOWN_CREDENTIAL_DOC_TYPE,\n parentIdentifier,\n );\n const input: Record<string, unknown> = {\n id: credential.id,\n context: credential[\"@context\"],\n type: credential.type,\n issuer: {\n id: credential.issuer.id,\n ethereumAddress: credential.issuer.ethereumAddress,\n },\n credentialSubject: {\n id: credential.credentialSubject.id,\n app: credential.credentialSubject.app,\n },\n credentialSchema: {\n id: credential.credentialSchema.id,\n type: credential.credentialSchema.type,\n },\n issuanceDate: credential.issuanceDate,\n expirationDate: credential.expirationDate || undefined,\n proof: {\n type: credential.proof.type,\n created: credential.proof.created,\n verificationMethod: credential.proof.verificationMethod,\n proofPurpose: credential.proof.proofPurpose,\n proofValue: credential.proof.proofValue,\n ethereumAddress: credential.proof.ethereumAddress,\n eip712: {\n domain: {\n version: credential.proof.eip712.domain.version,\n chainId: credential.proof.eip712.domain.chainId,\n },\n primaryType: credential.proof.eip712.primaryType,\n },\n },\n };\n await this.mutateDocument(documentId, [createAction(\"INIT\", input)]);\n return documentId;\n }\n\n // Find the RenownUser for an address or create one; returns its document id.\n async findOrCreateUser(\n address: string,\n profile: { username?: string; userImage?: string } = {},\n ): Promise<string> {\n const updates: Action[] = [];\n if (profile.username !== undefined) {\n updates.push(\n createAction(\"SET_USERNAME\", { username: profile.username }),\n );\n }\n if (profile.userImage !== undefined) {\n updates.push(\n createAction(\"SET_USER_IMAGE\", { userImage: profile.userImage }),\n );\n }\n\n const existing = await this.getProfileByAddress(address);\n if (existing) {\n if (updates.length)\n await this.mutateDocument(existing.documentId, updates);\n return existing.documentId;\n }\n\n const documentId = await this.createEmptyDocument(RENOWN_USER_DOC_TYPE);\n await this.mutateDocument(documentId, [\n createAction(\"SET_ETH_ADDRESS\", { ethAddress: address }),\n ...updates,\n ]);\n return documentId;\n }\n\n // Revoke a credential by its document id.\n async revokeCredential(documentId: string, reason?: string): Promise<void> {\n await this.mutateDocument(documentId, [\n createAction(\"REVOKE\", {\n revokedAt: new Date().toISOString(),\n reason: reason ?? null,\n }),\n ]);\n }\n\n // A ProfileFetcher backed by this client; used as the default when the\n // direct-switchboard flow is active. The `baseUrl` argument is ignored.\n profileFetcher: ProfileFetcher = (user) =>\n this.getProfileByAddress(user.address).catch(() => undefined);\n}\n","import { recoverTypedDataAddress } from \"viem\";\nimport {\n CREDENTIAL_TYPES,\n DEFAULT_RENOWN_NETWORK_ID,\n DEFAULT_RENOWN_URL,\n} from \"./constants.js\";\nimport { resolveSwitchboardEndpoint } from \"./discovery.js\";\nimport {\n SwitchboardClient,\n type SwitchboardRequestFn,\n type SwitchboardSource,\n} from \"./switchboard.js\";\nimport type { IProof, PowerhouseVerifiableCredential } from \"./types.js\";\nimport { verifyAuthBearerToken } from \"./utils.js\";\n\n/* Local structural aliases (EIP-712 standard shapes) so renown's public .d.ts\n * never names viem — a viem type in the surface drags viem's whole closure in. */\ntype Hex = `0x${string}`;\ntype TypedDataDomain = {\n name?: string;\n version?: string;\n chainId?: number;\n verifyingContract?: Hex;\n salt?: Hex;\n};\ntype TypedDataParameter = { name: string; type: string };\n\n/** EIP-712 domain as signed by the credential issuer. */\nexport type CredentialDomain = {\n version: string;\n chainId: number;\n};\n\n/** The credential body that is EIP-712 signed (everything except `proof`). */\nexport type CredentialMessage = {\n \"@context\": string[];\n type: string[];\n id: string;\n issuer: { id: string; ethereumAddress: Hex };\n credentialSubject: { id: string; app: string };\n credentialSchema: { id: string; type: string };\n issuanceDate: string;\n expirationDate: string;\n};\n\n/** Typed-data signer; matches the loose shape used by wallet adapters. */\nexport type SignCredentialTypedData = (args: {\n domain: TypedDataDomain;\n types: Record<string, readonly TypedDataParameter[]>;\n primaryType: string;\n message: Record<string, unknown>;\n}) => Promise<Hex>;\n\nexport interface BuildCredentialParams {\n signTypedData: SignCredentialTypedData;\n address: Hex;\n chainId: number;\n app: string;\n /** Credential subject id: the app/client DID the credential delegates to. */\n appId: string;\n expiresInDays?: number;\n}\n\n/** Assemble a Renown delegation VC and sign it with the provided signer. */\nexport async function buildAndSignCredential(\n params: BuildCredentialParams,\n): Promise<PowerhouseVerifiableCredential> {\n const {\n signTypedData,\n address,\n chainId,\n app,\n appId,\n expiresInDays = 7,\n } = params;\n\n const issuerId = `did:pkh:${DEFAULT_RENOWN_NETWORK_ID}:${chainId}:${address.toLowerCase()}`;\n const credentialId = `urn:uuid:${globalThis.crypto.randomUUID()}`;\n const now = new Date();\n const expirationDate = new Date(\n now.getTime() + expiresInDays * 24 * 60 * 60 * 1000,\n );\n\n const message: CredentialMessage = {\n \"@context\": [\"https://www.w3.org/2018/credentials/v1\"],\n type: [\"VerifiableCredential\", \"RenownCredential\"],\n id: credentialId,\n issuer: { id: issuerId, ethereumAddress: address },\n credentialSubject: { id: appId, app },\n credentialSchema: {\n id: \"https://renown.id/schemas/renown-credential/v1\",\n type: \"JsonSchemaValidator2018\",\n },\n issuanceDate: now.toISOString(),\n expirationDate: expirationDate.toISOString(),\n };\n\n const domain: CredentialDomain = { version: \"1\", chainId };\n\n // viem and most wallet adapters reserve EIP712Domain and derive it from\n // `domain` — passing it explicitly makes them throw.\n const { EIP712Domain, ...signTypes } = CREDENTIAL_TYPES;\n void EIP712Domain;\n const signature = await signTypedData({\n domain,\n types: signTypes,\n primaryType: \"VerifiableCredential\",\n message,\n });\n\n return {\n ...message,\n proof: {\n type: \"EthereumEip712Signature2021\",\n created: message.issuanceDate,\n verificationMethod: issuerId,\n proofPurpose: \"assertionMethod\",\n proofValue: signature,\n ethereumAddress: address,\n eip712: {\n domain,\n types: CREDENTIAL_TYPES,\n primaryType: \"VerifiableCredential\",\n },\n },\n };\n}\n\n/** Recover the address that signed a credential's EIP-712 proof. */\nexport async function recoverCredentialSigner(\n credential: PowerhouseVerifiableCredential,\n): Promise<Hex> {\n const { proof, ...message } = credential;\n // Drop EIP712Domain so viem derives it from `domain`; viem ignores\n // message keys not present in the types, so the proof is excluded too.\n const { EIP712Domain, ...types } = CREDENTIAL_TYPES;\n void EIP712Domain;\n return recoverTypedDataAddress({\n domain: proof.eip712.domain,\n types,\n primaryType: \"VerifiableCredential\",\n message,\n signature: proof.proofValue as Hex,\n } as Parameters<typeof recoverTypedDataAddress>[0]);\n}\n\n/** True when the proof was signed by the credential's declared issuer address. */\nexport async function verifyCredentialSignature(\n credential: PowerhouseVerifiableCredential,\n): Promise<boolean> {\n try {\n const recovered = await recoverCredentialSigner(credential);\n return (\n recovered.toLowerCase() ===\n credential.issuer.ethereumAddress.toLowerCase()\n );\n } catch {\n // Malformed proof (bad hex, missing fields) is an invalid signature.\n return false;\n }\n}\n\n// The deployed Renown API may omit proof.eip712.domain; it's canonical\n// (version \"1\", the credential's chainId), so reconstruct it before verifying.\nfunction withEip712Domain(\n credential: PowerhouseVerifiableCredential,\n chainId: number,\n): PowerhouseVerifiableCredential {\n const eip712 = credential.proof.eip712 as\n | Partial<IProof[\"eip712\"]>\n | undefined;\n if (eip712?.domain) return credential;\n return {\n ...credential,\n proof: {\n ...credential.proof,\n eip712: {\n domain: { version: \"1\", chainId },\n types: CREDENTIAL_TYPES,\n primaryType: \"VerifiableCredential\",\n },\n },\n };\n}\n\nexport interface FetchDelegationCredentialOptions {\n /** Ethereum address that must have issued the credential. */\n address: string;\n /** Chain id the credential must be scoped to. */\n chainId: number;\n /** App/client DID the credential must delegate to (credentialSubject.id). */\n appDid: string;\n /** Renown service base URL. Defaults to DEFAULT_RENOWN_URL. */\n baseUrl?: string;\n /** Switchboard GraphQL endpoint; when reachable, read the reactor directly. */\n switchboardUrl?: string;\n /** In-process Switchboard reader; wins over any URL and skips discovery. */\n switchboardRequest?: SwitchboardRequestFn;\n /** Probe {baseUrl}/api/switchboard for an endpoint (default true). */\n discover?: boolean;\n /** Re-verify the EIP-712 proof signature (default true). */\n verifySignature?: boolean;\n}\n\n// Fetch + binding/expiry-validate the credential over the Renown REST API.\nasync function fetchDelegationCredentialRest(params: {\n address: string;\n chainId: number;\n appDid: string;\n baseUrl: string;\n}): Promise<PowerhouseVerifiableCredential | undefined> {\n const { address, chainId, appDid, baseUrl } = params;\n const url = new URL(\n `/api/auth/credential?address=${encodeURIComponent(address)}&chainId=${encodeURIComponent(chainId)}&connectId=${encodeURIComponent(appDid)}&appId=${encodeURIComponent(appDid)}`,\n baseUrl,\n );\n const response = await fetch(url, { method: \"GET\" });\n if (!response.ok) return undefined;\n const { credential } = (await response.json()) as {\n credential?: PowerhouseVerifiableCredential;\n };\n if (!credential) return undefined;\n\n // Binding: delegates to this app DID, issued by this address on this chain\n // (issuer.id = did:pkh:<networkId>:<chainId>:<address>).\n const [, , , issuerChainId, issuerAddress] = credential.issuer.id.split(\":\");\n if (\n credential.credentialSubject.id !== appDid ||\n issuerChainId !== String(chainId) ||\n issuerAddress.toLowerCase() !== address.toLowerCase() ||\n credential.issuer.ethereumAddress.toLowerCase() !== address.toLowerCase()\n ) {\n return undefined;\n }\n\n // Reject an expired credential (revocation drops it from the endpoint\n // instead); a malformed date (NaN) counts as invalid, not non-expiring.\n if (credential.expirationDate) {\n const expiresAt = Date.parse(credential.expirationDate);\n if (Number.isNaN(expiresAt) || expiresAt <= Date.now()) {\n return undefined;\n }\n }\n\n return credential;\n}\n\n// Optionally re-verify the EIP-712 proof; returns the credential or undefined.\nasync function finalizeCredential(\n credential: PowerhouseVerifiableCredential,\n chainId: number,\n verifySignature: boolean,\n): Promise<PowerhouseVerifiableCredential | undefined> {\n if (!verifySignature) return credential;\n const withDomain = withEip712Domain(credential, chainId);\n if (\n withDomain.proof.eip712.domain.chainId !== chainId ||\n !(await verifyCredentialSignature(withDomain))\n ) {\n return undefined;\n }\n return withDomain;\n}\n\n// Fetch the Renown delegation credential for (address, chainId) and validate it\n// delegates to `appDid`; returns it, or undefined if absent/invalid. No throw.\nexport async function fetchDelegationCredential(\n options: FetchDelegationCredentialOptions,\n): Promise<PowerhouseVerifiableCredential | undefined> {\n const {\n address,\n chainId,\n appDid,\n switchboardUrl,\n switchboardRequest,\n discover = true,\n verifySignature = true,\n } = options;\n const explicitBaseUrl = options.baseUrl;\n const baseUrl = explicitBaseUrl ?? DEFAULT_RENOWN_URL;\n try {\n // A local reader or explicit switchboardUrl is used directly; otherwise\n // discover from the base URL unless the caller already resolved it.\n const source: SwitchboardSource | undefined =\n switchboardRequest ??\n (switchboardUrl\n ? switchboardUrl\n : discover && explicitBaseUrl\n ? await resolveSwitchboardEndpoint({ baseUrl })\n : undefined);\n\n const credential = source\n ? await new SwitchboardClient(source).getCredential({\n address,\n chainId,\n appDid,\n })\n : await fetchDelegationCredentialRest({\n address,\n chainId,\n appDid,\n baseUrl,\n });\n\n if (!credential) return undefined;\n return await finalizeCredential(credential, chainId, verifySignature);\n } catch {\n return undefined;\n }\n}\n\nexport interface VerifiedAuthCredential {\n address: string;\n chainId: number;\n networkId: string;\n /** Owner identity: the pkh DID (did:pkh:<net>:<chainId>:<address>). */\n did: string;\n /** App/client DID the bearer token was issued by. */\n appDid: string;\n credential: PowerhouseVerifiableCredential;\n}\n\nexport interface VerifyAuthCredentialOptions {\n /** Expected `aud` claim on the bearer token. */\n audience?: string;\n /** Renown service base URL. */\n renownUrl?: string;\n /** Switchboard GraphQL endpoint; when reachable, read the reactor directly. */\n switchboardUrl?: string;\n /** In-process Switchboard reader; wins over any URL and skips discovery. */\n switchboardRequest?: SwitchboardRequestFn;\n /** Re-verify the credential's EIP-712 proof (default true). */\n verifySignature?: boolean;\n}\n\n// Verify a renown bearer token end to end: check the JWT, then fetch+verify the\n// matching credential. Resolves the owner identity, or undefined. No throw.\nexport async function verifyAuthCredential(\n jwt: string,\n options: VerifyAuthCredentialOptions = {},\n): Promise<VerifiedAuthCredential | undefined> {\n const verified = await verifyAuthBearerToken(jwt, {\n audience: options.audience,\n });\n if (!verified) return undefined;\n\n const { address, chainId, networkId } =\n verified.verifiableCredential.credentialSubject;\n const appDid = verified.issuer;\n const credential = await fetchDelegationCredential({\n address,\n chainId,\n appDid,\n baseUrl: options.renownUrl,\n switchboardUrl: options.switchboardUrl,\n switchboardRequest: options.switchboardRequest,\n verifySignature: options.verifySignature,\n });\n if (!credential) return undefined;\n\n return {\n address,\n chainId,\n networkId,\n did: credential.issuer.id,\n appDid,\n credential,\n };\n}\n","export interface IStorage<\n T extends Record<string, unknown> = Record<string, unknown>,\n Key extends keyof T = keyof T,\n> {\n get(key: Key): T[Key] | undefined;\n set(key: Key, value?: T[Key]): void;\n delete(key: Key): void;\n}\n\nexport abstract class BaseStorage<\n T extends Record<string, unknown> = Record<string, unknown>,\n Key extends keyof T = keyof T,\n> implements IStorage<T> {\n abstract get(key: Key): T[Key] | undefined;\n abstract set(key: Key, value?: T[Key]): void;\n abstract delete(key: Key): void;\n}\n\nexport class MemoryStorage<\n T extends Record<string, unknown> = Record<string, unknown>,\n Key extends keyof T = keyof T,\n> extends BaseStorage<T> {\n private readonly data = new Map<Key, T[Key]>();\n\n get(key: Key) {\n return this.data.get(key);\n }\n\n set(key: Key, value?: T[Key]): void {\n if (value === undefined) {\n this.data.delete(key);\n } else {\n this.data.set(key, value);\n }\n }\n\n delete(key: Key): void {\n this.data.delete(key);\n }\n}\n","import {\n CREDENTIAL_TYPES,\n DEFAULT_RENOWN_CHAIN_ID,\n DEFAULT_RENOWN_NETWORK_ID,\n DEFAULT_RENOWN_URL,\n} from \"./constants.js\";\nimport {\n buildAndSignCredential,\n verifyCredentialSignature,\n} from \"./credential.js\";\nimport { RenownCryptoSigner, type IRenownCrypto } from \"./crypto/index.js\";\nimport { MemoryStorage } from \"./storage/common.js\";\nimport {\n MissingSwitchboardError,\n type SwitchboardClient,\n} from \"./switchboard.js\";\nimport type {\n CreateBearerTokenOptions,\n IProof,\n IRenown,\n ISigner,\n LoginStatus,\n PKHDid,\n PowerhouseVerifiableCredential,\n ProfileFetcher,\n RenownEventEmitter,\n RenownEvents,\n RenownStorage,\n RenownStorageMap,\n SignInParams,\n User,\n UserActionSigner,\n} from \"./types.js\";\nimport { parsePkhDid, verifyAuthBearerToken } from \"./utils.js\";\nexport * from \"./constants.js\";\n\nexport class RenownMemoryStorage extends MemoryStorage<RenownStorageMap> {}\n\n/**\n * The acting identity an action's signature carries.\n *\n * `User` here is the whole session record — it also holds the DID, the\n * credential, the fetched profile and ENS info — while `UserActionSigner` is\n * what travels on a signed action, and it is deliberately just an address on a\n * chain. The reactor's `ReactorSignerUserInput` declares exactly these three\n * fields, and a GraphQL input object refuses a field it does not declare by\n * rejecting the WHOLE request, so handing the session record to the signer\n * makes every signed push fail before it reaches the reactor.\n *\n * Narrowed here rather than at the transport, because the session record has no\n * business being on an operation in the first place: it is stored on every\n * operation a local reactor writes, not only on the ones that go over a wire.\n *\n * The compiler cannot catch the difference — excess-property checks apply to\n * fresh object literals, never to a variable of a wider type — which is why\n * this is a function rather than a type annotation.\n */\nfunction toActionSigner(user: User | undefined): UserActionSigner | undefined {\n if (!user) return undefined;\n return {\n address: user.address,\n networkId: user.networkId,\n chainId: user.chainId,\n };\n}\n\nexport class Renown implements IRenown {\n #baseUrl: string;\n #store: RenownStorage;\n #eventEmitter: RenownEventEmitter;\n #appName: string;\n #crypto: IRenownCrypto;\n #signer: ISigner;\n #profileFetcher?: ProfileFetcher;\n #switchboard?: SwitchboardClient;\n #chainId: number;\n #status: LoginStatus = \"initial\";\n\n constructor(\n store: RenownStorage,\n eventEmitter: RenownEventEmitter,\n crypto: IRenownCrypto,\n appName: string,\n baseUrl = DEFAULT_RENOWN_URL,\n profileFetcher?: ProfileFetcher,\n switchboard?: SwitchboardClient,\n chainId = Number(DEFAULT_RENOWN_CHAIN_ID),\n ) {\n this.#store = store;\n this.#eventEmitter = eventEmitter;\n this.#baseUrl = baseUrl;\n this.#crypto = crypto;\n this.#appName = appName;\n this.#profileFetcher = profileFetcher;\n this.#switchboard = switchboard;\n this.#chainId = chainId;\n const restoredUser = this.user;\n this.#signer = new RenownCryptoSigner(\n crypto,\n this.#appName,\n toActionSigner(restoredUser),\n );\n\n // A restored, previously-verified user is an authorized session; otherwise\n // status stays \"initial\" after a reload while the user is present.\n if (restoredUser) {\n this.#status = \"authorized\";\n }\n\n this.on(\"user\", (user) => {\n this.#signer.user = toActionSigner(user);\n });\n }\n\n get baseUrl() {\n return this.#baseUrl;\n }\n\n /** Chain id this app issues credentials on; a session from another chain is rejected by {@link signIn}. */\n get chainId() {\n return this.#chainId;\n }\n\n get user() {\n return this.#store.get(\"user\");\n }\n\n get status() {\n return this.#status;\n }\n\n get signer() {\n return this.#signer;\n }\n\n get crypto() {\n return this.#crypto;\n }\n\n get did() {\n return this.#crypto.did;\n }\n\n get profileFetcher() {\n return this.#profileFetcher;\n }\n\n #updateStatus(status: LoginStatus) {\n this.#status = status;\n this.#eventEmitter.emit(\"status\", status);\n }\n\n #updateUser(user: User | undefined) {\n if (user) {\n this.#store.set(\"user\", user);\n } else {\n this.#store.delete(\"user\");\n }\n this.#eventEmitter.emit(\"user\", user);\n }\n\n async login(userDid: string): Promise<User> {\n this.#updateStatus(\"checking\");\n try {\n const result = parsePkhDid(userDid);\n const credential = await this.#getCredential(\n result.address,\n result.chainId,\n this.#crypto.did,\n );\n\n if (!credential) {\n this.#updateUser(undefined);\n throw new Error(\"Credential not found\");\n }\n\n return await this.#completeLogin(userDid, result, credential);\n } catch (error) {\n this.#updateUser(undefined);\n this.#updateStatus(\"not-authorized\");\n throw error;\n }\n }\n\n // Sign in without the Renown redirect: build + sign a delegation credential\n // with the caller's wallet signer, write it to the switchboard, then log in.\n async signIn(params: SignInParams): Promise<User> {\n if (!this.#switchboard) throw new MissingSwitchboardError();\n const {\n address,\n chainId,\n signTypedData,\n username,\n userImage,\n expiresInDays,\n } = params;\n\n // The chain id goes into the issuer DID and the EIP-712 domain, so signing on\n // another chain would mint a second identity for the same wallet.\n if (chainId !== this.#chainId) {\n throw new Error(\n `Renown signIn: wallet is on chain ${chainId}, but this app issues credentials on chain ${this.#chainId}. Switch networks and retry — signing here would create a separate identity for the same address.`,\n );\n }\n\n this.#updateStatus(\"checking\");\n try {\n const credential = await buildAndSignCredential({\n signTypedData,\n address,\n chainId,\n app: this.#appName,\n appId: this.did,\n expiresInDays,\n });\n\n await this.#switchboard.issueCredential(credential);\n await this.#switchboard.findOrCreateUser(address, {\n username,\n userImage,\n });\n\n const userDid = `did:pkh:${DEFAULT_RENOWN_NETWORK_ID}:${chainId}:${address.toLowerCase()}`;\n // Authenticate from the freshly signed credential — no read-back, which\n // avoids racing the read-model processor that indexes the write.\n return await this.#completeLogin(\n userDid,\n parsePkhDid(userDid),\n credential,\n );\n } catch (error) {\n this.#updateUser(undefined);\n this.#updateStatus(\"not-authorized\");\n throw error;\n }\n }\n\n // Verify a credential binds to userDid + this app key, set the user, and\n // start the background profile fetch. Throws if the credential is invalid.\n async #completeLogin(\n userDid: string,\n result: PKHDid,\n credential: PowerhouseVerifiableCredential,\n ): Promise<User> {\n if (\n !(\n credential.issuer.id === userDid &&\n credential.credentialSubject.id === this.did\n )\n ) {\n throw new Error(\"Invalid credential\");\n }\n\n // The API may return proof.eip712 without domain/types; the domain is\n // canonical (version \"1\", the chainId), so reconstruct it before verifying.\n const eip712 = credential.proof.eip712 as\n | Partial<IProof[\"eip712\"]>\n | undefined;\n const verifiableCredential: PowerhouseVerifiableCredential = eip712?.domain\n ? credential\n : {\n ...credential,\n proof: {\n ...credential.proof,\n eip712: {\n domain: { version: \"1\", chainId: result.chainId },\n types: CREDENTIAL_TYPES,\n primaryType: \"VerifiableCredential\",\n },\n },\n };\n\n // Verify the EIP-712 proof was signed by the DID's address on its chain.\n if (\n credential.issuer.ethereumAddress.toLowerCase() !==\n result.address.toLowerCase() ||\n verifiableCredential.proof.eip712.domain.chainId !== result.chainId ||\n !(await verifyCredentialSignature(verifiableCredential))\n ) {\n throw new Error(\"Invalid credential signature\");\n }\n\n const user: User = {\n ...result,\n address: credential.issuer.ethereumAddress,\n did: userDid,\n credential: verifiableCredential,\n };\n\n this.#updateUser(user);\n this.#updateStatus(\"authorized\");\n\n // Fetch profile data in the background if a fetcher is configured\n if (this.#profileFetcher) {\n this.#profileFetcher(user, this.#baseUrl)\n .then((profile) => {\n if (\n profile &&\n this.user?.address === user.address &&\n this.user.chainId === user.chainId\n ) {\n this.#updateUser({\n ...this.user,\n profile,\n ens: {\n name: profile.username ?? undefined,\n avatarUrl: profile.userImage ?? undefined,\n },\n });\n }\n })\n .catch(console.error);\n }\n\n return user;\n }\n\n logout() {\n this.#updateUser(undefined);\n this.#updateStatus(\"initial\");\n return Promise.resolve();\n }\n\n // Re-check the current user's credential at the source; logs out if it was\n // revoked or expired. Network errors keep the session (fail open).\n async revalidate(): Promise<boolean> {\n const user = this.user;\n if (!user) return false;\n try {\n const credential = await this.#getCredential(\n user.address,\n user.chainId,\n this.#crypto.did,\n );\n if (!credential) {\n await this.logout();\n return false;\n }\n await this.refreshProfile();\n return true;\n } catch {\n return true;\n }\n }\n\n // Re-read profile attributes at the source so a renamed user or changed avatar\n // shows up on the next load. Carries no logout risk, unlike revalidate().\n async refreshProfile(): Promise<boolean> {\n const user = this.user;\n if (!user || !this.#profileFetcher) return false;\n try {\n const profile = await this.#profileFetcher(user, this.#baseUrl);\n if (!profile) return false;\n // Asserted because narrowing from the pre-await read would otherwise hide\n // that a logout during the fetch can clear this.\n const current = this.user as User | undefined;\n if (\n !current ||\n current.address !== user.address ||\n current.chainId !== user.chainId\n ) {\n return false;\n }\n // Narrow `profile` first: the fetched payload is unvalidated JSON, so a\n // missing documentId must not make the undefined case compare equal.\n const unchanged =\n current.profile !== undefined &&\n current.profile.documentId === profile.documentId &&\n current.profile.username === profile.username &&\n current.profile.userImage === profile.userImage;\n if (unchanged) return false;\n this.#updateUser({\n ...current,\n profile,\n ens: {\n name: profile.username ?? undefined,\n avatarUrl: profile.userImage ?? undefined,\n },\n });\n return true;\n } catch {\n return false;\n }\n }\n\n on<K extends keyof RenownEvents>(\n event: K,\n listener: (data: RenownEvents[K]) => void,\n ): () => void {\n return this.#eventEmitter.on(event, listener);\n }\n\n async #getCredential(\n address: string,\n chainId: number,\n appDid: string,\n ): Promise<PowerhouseVerifiableCredential | undefined> {\n // Direct-switchboard flow: read the credential from the reactor subgraph.\n if (this.#switchboard) {\n return this.#switchboard.getCredential({ address, chainId, appDid });\n }\n if (!this.#baseUrl) {\n throw new Error(\"RENOWN_URL is not set\");\n }\n const url = new URL(\n `/api/auth/credential?address=${encodeURIComponent(address)}&chainId=${encodeURIComponent(chainId)}&connectId=${encodeURIComponent(appDid)}&appId=${encodeURIComponent(appDid)}`,\n this.#baseUrl,\n );\n const response = await fetch(url, {\n method: \"GET\",\n });\n if (response.ok) {\n const result = (await response.json()) as {\n credential: PowerhouseVerifiableCredential;\n };\n return result.credential;\n } else {\n throw new Error(`Failed to get credential: ${response.status}`);\n }\n }\n\n async verifyBearerToken(token: string) {\n return verifyAuthBearerToken(token);\n }\n\n async getBearerToken(options: CreateBearerTokenOptions) {\n if (!this.user) {\n throw new Error(\"User not found\");\n }\n return this.#crypto.getBearerToken(this.user.address, options);\n }\n}\n","import type { RenownEvents } from \"../types.js\";\nimport type { IEventEmitter } from \"./types.js\";\n\nexport class MemoryEventEmitter implements IEventEmitter<RenownEvents> {\n #listeners = new Map<keyof RenownEvents, Set<(data: unknown) => void>>();\n\n on<K extends keyof RenownEvents>(\n event: K,\n listener: (data: RenownEvents[K]) => void,\n ): () => void {\n if (!this.#listeners.has(event)) {\n this.#listeners.set(event, new Set());\n }\n this.#listeners.get(event)!.add(listener as (data: unknown) => void);\n return () => {\n this.#listeners.get(event)?.delete(listener as (data: unknown) => void);\n };\n }\n\n emit<K extends keyof RenownEvents>(event: K, data: RenownEvents[K]): void {\n this.#listeners.get(event)?.forEach((listener) => listener(data));\n }\n}\n","import type { ProfileFetcher, RenownProfile } from \"./types.js\";\n\nexport const fetchRenownProfile: ProfileFetcher = async (user, baseUrl) => {\n try {\n const response = await fetch(`${baseUrl.replace(/\\/+$/, \"\")}/api/profile`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n ethAddress: user.address,\n }),\n });\n\n if (!response.ok) {\n return undefined;\n }\n\n const result = (await response.json()) as {\n profile?: RenownProfile;\n };\n\n return result.profile ?? undefined;\n } catch {\n return undefined;\n }\n};\n","import { Renown, RenownMemoryStorage } from \"./common.js\";\nimport { DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_URL } from \"./constants.js\";\nimport { RenownCryptoBuilder } from \"./crypto/renown-crypto-builder.js\";\nimport type { IRenownCrypto, JsonWebKeyPairStorage } from \"./crypto/types.js\";\nimport { resolveSwitchboardEndpoint } from \"./discovery.js\";\nimport { MemoryEventEmitter } from \"./event/memory.js\";\nimport { fetchRenownProfile } from \"./profile.js\";\nimport { SwitchboardClient } from \"./switchboard.js\";\nimport type {\n ProfileFetcher,\n RenownEventEmitter,\n RenownStorage,\n} from \"./types.js\";\n\nexport interface RenownBuilderOptions {\n appName: string;\n storage?: RenownStorage;\n eventEmitter?: RenownEventEmitter;\n crypto?: IRenownCrypto;\n keyPairStorage?: JsonWebKeyPairStorage;\n baseUrl?: string;\n switchboardUrl?: string;\n profileFetcher?: ProfileFetcher;\n /** Chain id credentials are issued on (default 1). The issuer DID embeds it, so `signIn` rejects a wallet session from another chain. */\n chainId?: number;\n}\n\n/**\n * Base builder for creating Renown instances.\n * Use platform-specific builders (RenownBuilder from init.browser.js or init.node.js)\n * for pre-configured defaults.\n */\nexport class BaseRenownBuilder {\n #appName: string;\n #storage?: RenownStorage;\n #eventEmitter?: RenownEventEmitter;\n #crypto?: IRenownCrypto;\n #keyPairStorage?: JsonWebKeyPairStorage;\n #baseUrl?: string;\n #switchboardUrl?: string;\n #profileFetcher?: ProfileFetcher;\n #chainId?: number;\n\n /**\n * @param appName - Application name used for signing context\n */\n constructor(appName: string) {\n this.#appName = appName;\n }\n\n /**\n * Set custom storage for user data persistence.\n * Defaults to in-memory storage if not set.\n */\n withStorage(storage: RenownStorage): this {\n this.#storage = storage;\n return this;\n }\n\n /**\n * Set custom event emitter for user state changes.\n * Defaults to in-memory event emitter if not set.\n */\n withEventEmitter(eventEmitter: RenownEventEmitter): this {\n this.#eventEmitter = eventEmitter;\n return this;\n }\n\n /**\n * Set a pre-built crypto instance.\n * Either crypto or keyPairStorage must be provided.\n */\n withCrypto(crypto: IRenownCrypto): this {\n this.#crypto = crypto;\n return this;\n }\n\n /**\n * Set key pair storage for cryptographic keys.\n * A crypto instance will be built from this storage.\n * Either crypto or keyPairStorage must be provided.\n */\n withKeyPairStorage(keyPairStorage: JsonWebKeyPairStorage): this {\n this.#keyPairStorage = keyPairStorage;\n return this;\n }\n\n /**\n * Set the Renown server URL for credential verification.\n * Defaults to https://www.renown.id\n */\n withBaseUrl(baseUrl: string): this {\n this.#baseUrl = baseUrl;\n return this;\n }\n\n // Set the Switchboard GraphQL endpoint to read from the reactor directly.\n // When unset, the SDK discovers it from the base URL, else uses the REST flow.\n withSwitchboardUrl(switchboardUrl: string): this {\n this.#switchboardUrl = switchboardUrl;\n return this;\n }\n\n // Set the chain id credentials are issued on (default 1). It is part of the\n // issuer DID, so signIn rejects a wallet session from a different chain.\n withChainId(chainId: number): this {\n this.#chainId = chainId;\n return this;\n }\n\n /**\n * Set a profile fetcher strategy for enriching user data after login.\n * The fetcher receives the authenticated user and the base URL,\n * and returns a RenownProfile. Called in the background after each login.\n * Defaults to fetchRenownProfile which calls the Renown API.\n */\n withProfileFetcher(profileFetcher: ProfileFetcher): this {\n this.#profileFetcher = profileFetcher;\n return this;\n }\n\n /**\n * Build and initialize the Renown instance.\n * If a user is stored, attempts to re-authenticate them.\n * @throws Error if neither crypto nor keyPairStorage is provided\n */\n async build(): Promise<Renown> {\n if (!this.#crypto && !this.#keyPairStorage) {\n throw new Error(\n \"Either crypto or keyPairStorage is required. Use withCrypto() or withKeyPairStorage() to set one.\",\n );\n }\n\n const chainId = this.#chainId ?? Number(DEFAULT_RENOWN_CHAIN_ID);\n const crypto =\n this.#crypto ??\n (await new RenownCryptoBuilder()\n .withKeyPairStorage(this.#keyPairStorage!)\n .withChainId(chainId)\n .build());\n\n // A crypto supplied via withCrypto() carries its own chain; the bearer token\n // it mints would then disagree with the credentials issued here.\n if (crypto.chainId !== undefined && crypto.chainId !== chainId) {\n console.warn(\n `Renown: the supplied crypto signs bearer tokens for chain ${crypto.chainId}, but credentials are issued on chain ${chainId}.`,\n );\n }\n\n const storage = this.#storage ?? new RenownMemoryStorage();\n const eventEmitter = this.#eventEmitter ?? new MemoryEventEmitter();\n const baseUrl = this.#baseUrl ?? DEFAULT_RENOWN_URL;\n\n // Pick the transport once: direct-switchboard when an endpoint resolves,\n // else the REST flow. A custom profile fetcher always takes precedence.\n const switchboardEndpoint = await resolveSwitchboardEndpoint({\n switchboardUrl: this.#switchboardUrl,\n baseUrl,\n });\n const switchboard = switchboardEndpoint\n ? new SwitchboardClient(switchboardEndpoint)\n : undefined;\n const profileFetcher =\n this.#profileFetcher ??\n (switchboard ? switchboard.profileFetcher : fetchRenownProfile);\n\n const renown = new Renown(\n storage,\n eventEmitter,\n crypto,\n this.#appName,\n baseUrl,\n profileFetcher,\n switchboard,\n chainId,\n );\n\n // A stored user is loaded as-is for an instant, offline-safe start; callers\n // revalidate against the source separately via renown.revalidate().\n return renown;\n }\n\n /**\n * Create a BaseRenownBuilder from options object for a more concise API\n */\n static from(options: RenownBuilderOptions): BaseRenownBuilder {\n const builder = new BaseRenownBuilder(options.appName);\n\n if (options.storage) {\n builder.withStorage(options.storage);\n }\n if (options.eventEmitter) {\n builder.withEventEmitter(options.eventEmitter);\n }\n if (options.crypto) {\n builder.withCrypto(options.crypto);\n }\n if (options.keyPairStorage) {\n builder.withKeyPairStorage(options.keyPairStorage);\n }\n if (options.baseUrl) {\n builder.withBaseUrl(options.baseUrl);\n }\n if (options.switchboardUrl) {\n builder.withSwitchboardUrl(options.switchboardUrl);\n }\n if (options.profileFetcher) {\n builder.withProfileFetcher(options.profileFetcher);\n }\n if (options.chainId !== undefined) {\n builder.withChainId(options.chainId);\n }\n\n return builder;\n }\n}\n","import { fetchDelegationCredential } from \"./credential.js\";\nimport type { SwitchboardRequestFn } from \"./switchboard.js\";\n\n/** Confirms an authenticated signer's delegation credential is still live. */\nexport type CredentialCheck = (params: {\n address: string;\n chainId: number;\n appId: string;\n}) => Promise<boolean>;\n\nexport interface LocalCredentialVerifierOptions {\n /** Notified when the read itself fails; the check then fails closed. */\n onError?: (error: unknown) => void;\n}\n\n/** A credential check that reads a Switchboard's own renown read model through\n * `execute`, rather than any Renown or Switchboard over HTTP. */\nexport function createLocalCredentialVerifier(\n execute: SwitchboardRequestFn,\n options: LocalCredentialVerifierOptions = {},\n): CredentialCheck {\n // fetchDelegationCredential turns a read failure into \"no credential\" — the\n // right verdict, but silent; surface it before it is swallowed.\n const request: SwitchboardRequestFn = async (query, variables) => {\n try {\n return await execute(query, variables);\n } catch (error) {\n options.onError?.(error);\n throw error;\n }\n };\n\n return async ({ address, chainId, appId }) => {\n const credential = await fetchDelegationCredential({\n address,\n chainId,\n appDid: appId,\n switchboardRequest: request,\n });\n return credential !== undefined;\n };\n}\n"],"mappings":";;;;;AAWA,MAAM,+BAA+B;AASrC,eAAsB,2BACpB,SAC6B;CAC7B,MAAM,EAAE,gBAAgB,SAAS,cAAc;AAE/C,KAAI,eACF,QAAO;AAGT,KAAI,CAAC,QACH;CAGF,MAAM,aAAa,IAAI,iBAAiB;CACxC,MAAM,UAAU,iBACR,WAAW,OAAO,EACxB,aAAa,6BACd;AAED,KAAI;EACF,MAAM,MAAM,IAAI,IAAI,oBAAoB,QAAQ;EAChD,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,QAAQ;GACR,QAAQ,WAA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";
|
|
2
|
+
|
|
3
|
+
//#region src/wallet/mock/meta.d.ts
|
|
4
|
+
type MockLoginMethod = "wallet" | "google" | "apple" | "email";
|
|
5
|
+
declare const DEFAULT_MOCK_METHODS: LoginMethod[];
|
|
6
|
+
/** Config for the mock wallet adapter. TEST/DEV ONLY — signs with a local key; never enable in production. */
|
|
7
|
+
interface PHRenownMockAdapterConfig {
|
|
8
|
+
/** Signing key; defaults to the well-known Anvil test account #0. */
|
|
9
|
+
privateKey?: `0x${string}`;
|
|
10
|
+
/** Chain id reported in the session (default 1). */
|
|
11
|
+
chainId?: number;
|
|
12
|
+
/** Methods this adapter answers for; defaults to wallet + google + email. */
|
|
13
|
+
methods?: MockLoginMethod[];
|
|
14
|
+
}
|
|
15
|
+
declare function resolveMockMethods(methods?: string[]): LoginMethod[];
|
|
16
|
+
declare const mockAdapterMeta: Omit<WalletAdapterMeta, "supportedMethods">;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { resolveMockMethods as a, mockAdapterMeta as i, MockLoginMethod as n, PHRenownMockAdapterConfig as r, DEFAULT_MOCK_METHODS as t };
|
|
19
|
+
//# sourceMappingURL=meta-BesJP74N.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-BesJP74N.d.ts","names":[],"sources":["../src/wallet/mock/meta.ts"],"mappings":";;;KAEY,eAAA;AAAA,cAUC,oBAAA,EAAsB,WAAA;AAVnC;AAAA,UAiBiB,yBAAA;;EAEf,UAAA;EAnByB;EAqBzB,OAAA;EAPD;EASC,OAAA,GAAU,eAAA;AAAA;AAAA,iBAKI,kBAAA,CAAmB,OAAA,cAAqB,WAAA;AAAA,cAe3C,eAAA,EAAiB,IAAA,CAAK,iBAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as LoginMethod } from "./types-C_qc_62W.js";
|
|
2
|
+
//#region src/wallet/mock/meta.ts
|
|
3
|
+
const MOCK_SUPPORTED_METHODS = [
|
|
4
|
+
LoginMethod.WALLET,
|
|
5
|
+
LoginMethod.GOOGLE,
|
|
6
|
+
LoginMethod.APPLE,
|
|
7
|
+
LoginMethod.EMAIL
|
|
8
|
+
];
|
|
9
|
+
const DEFAULT_MOCK_METHODS = [
|
|
10
|
+
LoginMethod.WALLET,
|
|
11
|
+
LoginMethod.GOOGLE,
|
|
12
|
+
LoginMethod.EMAIL
|
|
13
|
+
];
|
|
14
|
+
function resolveMockMethods(methods) {
|
|
15
|
+
if (!methods || methods.length === 0) return [...DEFAULT_MOCK_METHODS];
|
|
16
|
+
const resolved = [];
|
|
17
|
+
for (const method of methods) {
|
|
18
|
+
const value = method;
|
|
19
|
+
if (!MOCK_SUPPORTED_METHODS.includes(value)) throw new Error(`MockAdapter cannot support login method "${method}"`);
|
|
20
|
+
resolved.push(value);
|
|
21
|
+
}
|
|
22
|
+
return resolved;
|
|
23
|
+
}
|
|
24
|
+
const mockAdapterMeta = {
|
|
25
|
+
id: "mock",
|
|
26
|
+
redirectReturnParams: []
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { mockAdapterMeta as n, resolveMockMethods as r, DEFAULT_MOCK_METHODS as t };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=meta-CHgd9Qd0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-CHgd9Qd0.js","names":[],"sources":["../src/wallet/mock/meta.ts"],"sourcesContent":["import { LoginMethod, type WalletAdapterMeta } from \"../types.js\";\n\nexport type MockLoginMethod = \"wallet\" | \"google\" | \"apple\" | \"email\";\n\nconst MOCK_SUPPORTED_METHODS: MockLoginMethod[] = [\n LoginMethod.WALLET,\n LoginMethod.GOOGLE,\n LoginMethod.APPLE,\n LoginMethod.EMAIL,\n];\n\n// Methods offered when config omits `methods`.\nexport const DEFAULT_MOCK_METHODS: LoginMethod[] = [\n LoginMethod.WALLET,\n LoginMethod.GOOGLE,\n LoginMethod.EMAIL,\n];\n\n/** Config for the mock wallet adapter. TEST/DEV ONLY — signs with a local key; never enable in production. */\nexport interface PHRenownMockAdapterConfig {\n /** Signing key; defaults to the well-known Anvil test account #0. */\n privateKey?: `0x${string}`;\n /** Chain id reported in the session (default 1). */\n chainId?: number;\n /** Methods this adapter answers for; defaults to wallet + google + email. */\n methods?: MockLoginMethod[];\n}\n\n// Resolve config `methods` to the supported set, falling back to the default.\n// Takes string[] because Connect's config arrives from JSON, unvalidated.\nexport function resolveMockMethods(methods?: string[]): LoginMethod[] {\n if (!methods || methods.length === 0) return [...DEFAULT_MOCK_METHODS];\n const resolved: LoginMethod[] = [];\n for (const method of methods) {\n const value = method as MockLoginMethod;\n if (!MOCK_SUPPORTED_METHODS.includes(value)) {\n throw new Error(`MockAdapter cannot support login method \"${method}\"`);\n }\n resolved.push(value);\n }\n return resolved;\n}\n\n// Dependency-free identity (see privy/meta.ts). The mock signer has no\n// full-page OAuth redirect.\nexport const mockAdapterMeta: Omit<WalletAdapterMeta, \"supportedMethods\"> = {\n id: \"mock\",\n redirectReturnParams: [],\n};\n"],"mappings":";;AAIA,MAAM,yBAA4C;CAChD,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACb;AAGD,MAAa,uBAAsC;CACjD,YAAY;CACZ,YAAY;CACZ,YAAY;CACb;AAcD,SAAgB,mBAAmB,SAAmC;AACpE,KAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,QAAO,CAAC,GAAG,qBAAqB;CACtE,MAAM,WAA0B,EAAE;AAClC,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,QAAQ;AACd,MAAI,CAAC,uBAAuB,SAAS,MAAM,CACzC,OAAM,IAAI,MAAM,4CAA4C,OAAO,GAAG;AAExE,WAAS,KAAK,MAAM;;AAEtB,QAAO;;AAKT,MAAa,kBAA+D;CAC1E,IAAI;CACJ,sBAAsB,EAAE;CACzB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as LoginMethod } from "./types-C_qc_62W.js";
|
|
2
|
+
//#region src/wallet/privy/meta.ts
|
|
3
|
+
const PRIVY_SUPPORTED_METHODS = [
|
|
4
|
+
LoginMethod.WALLET,
|
|
5
|
+
LoginMethod.GOOGLE,
|
|
6
|
+
LoginMethod.APPLE,
|
|
7
|
+
LoginMethod.EMAIL
|
|
8
|
+
];
|
|
9
|
+
const DEFAULT_PRIVY_METHODS = [LoginMethod.GOOGLE, LoginMethod.EMAIL];
|
|
10
|
+
function resolvePrivyMethods(methods) {
|
|
11
|
+
if (!methods || methods.length === 0) return [...DEFAULT_PRIVY_METHODS];
|
|
12
|
+
const resolved = [];
|
|
13
|
+
for (const method of methods) {
|
|
14
|
+
const value = method;
|
|
15
|
+
if (!PRIVY_SUPPORTED_METHODS.includes(value)) throw new Error(`PrivyAdapter cannot support login method "${method}"`);
|
|
16
|
+
resolved.push(value);
|
|
17
|
+
}
|
|
18
|
+
return resolved;
|
|
19
|
+
}
|
|
20
|
+
const privyAdapterMeta = {
|
|
21
|
+
id: "privy",
|
|
22
|
+
redirectReturnParams: ["privy_oauth_code", "privy_oauth_state"]
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { privyAdapterMeta as n, resolvePrivyMethods as r, DEFAULT_PRIVY_METHODS as t };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=meta-D-5kvwx8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-D-5kvwx8.js","names":[],"sources":["../src/wallet/privy/meta.ts"],"sourcesContent":["import { LoginMethod, type WalletAdapterMeta } from \"../types.js\";\n\n/** Structural subset of viem's `Chain`, so any `viem/chains` / `wagmi/chains` export fits regardless of the host's viem version. */\nexport interface PrivyChain {\n id: number;\n name: string;\n nativeCurrency: { name: string; symbol: string; decimals: number };\n rpcUrls: { default: { http: readonly string[] } };\n}\n\n// Login methods the Privy adapter can drive. adapter.ts maps each to a Privy\n// login-method id, so adding one here without mapping it fails to compile.\nexport type PrivyLoginMethod = \"wallet\" | \"google\" | \"apple\" | \"email\";\n\nexport const PRIVY_SUPPORTED_METHODS: PrivyLoginMethod[] = [\n LoginMethod.WALLET,\n LoginMethod.GOOGLE,\n LoginMethod.APPLE,\n LoginMethod.EMAIL,\n];\n\n// Methods offered when config omits `methods`.\nexport const DEFAULT_PRIVY_METHODS: LoginMethod[] = [\n LoginMethod.GOOGLE,\n LoginMethod.EMAIL,\n];\n\n// Config slice for the Privy adapter (mirrors connect.renown.adapters.privy).\nexport interface PHRenownPrivyAdapterConfig {\n appId: string;\n clientId?: string;\n /** Login methods to offer; defaults to [google, email]. */\n methods?: PrivyLoginMethod[];\n /** Chain Renown issues credentials on (e.g. `mainnet` from `viem/chains`). Pins the embedded wallet to it: a wallet on another chain is a different DID and is rejected. */\n chain?: PrivyChain;\n /** Privy `appearance.walletList`. Defaults to `[\"detected_ethereum_wallets\"]`: with external wallets disabled here (they go through the rainbow adapter), anything else makes Privy fetch the WalletConnect explorer listings (~163 KB) on mount. Set it only if you want those listings. */\n walletList?: string[];\n}\n\n// Resolve config `methods` to the supported set, falling back to the default.\n// Takes string[] because Connect's config arrives from JSON, unvalidated.\nexport function resolvePrivyMethods(methods?: string[]): LoginMethod[] {\n if (!methods || methods.length === 0) return [...DEFAULT_PRIVY_METHODS];\n const resolved: LoginMethod[] = [];\n for (const method of methods) {\n const value = method as PrivyLoginMethod;\n if (!PRIVY_SUPPORTED_METHODS.includes(value)) {\n throw new Error(`PrivyAdapter cannot support login method \"${method}\"`);\n }\n resolved.push(value);\n }\n return resolved;\n}\n\n// Dependency-free identity, safe to import eagerly (pulls no wallet library);\n// the heavy factory stays behind the dynamic import in ./index.ts.\nexport const privyAdapterMeta: Omit<WalletAdapterMeta, \"supportedMethods\"> = {\n id: \"privy\",\n redirectReturnParams: [\"privy_oauth_code\", \"privy_oauth_state\"],\n};\n"],"mappings":";;AAcA,MAAa,0BAA8C;CACzD,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACb;AAGD,MAAa,wBAAuC,CAClD,YAAY,QACZ,YAAY,MACb;AAgBD,SAAgB,oBAAoB,SAAmC;AACrE,KAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,QAAO,CAAC,GAAG,sBAAsB;CACvE,MAAM,WAA0B,EAAE;AAClC,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,QAAQ;AACd,MAAI,CAAC,wBAAwB,SAAS,MAAM,CAC1C,OAAM,IAAI,MAAM,6CAA6C,OAAO,GAAG;AAEzE,WAAS,KAAK,MAAM;;AAEtB,QAAO;;AAKT,MAAa,mBAAgE;CAC3E,IAAI;CACJ,sBAAsB,CAAC,oBAAoB,oBAAoB;CAChE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { o as WalletAdapterMeta, t as LoginMethod } from "./types-C-hJrsQg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wallet/rainbow/meta.d.ts
|
|
4
|
+
interface PHRenownChain {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
interface PHRenownRainbowAdapterConfig {
|
|
9
|
+
walletConnectProjectId?: string;
|
|
10
|
+
infuraProjectId?: string;
|
|
11
|
+
appName?: string;
|
|
12
|
+
chains?: readonly [PHRenownChain, ...PHRenownChain[]];
|
|
13
|
+
ssr?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const RAINBOW_METHODS: LoginMethod[];
|
|
16
|
+
declare const rainbowAdapterMeta: WalletAdapterMeta;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { rainbowAdapterMeta as i, PHRenownRainbowAdapterConfig as n, RAINBOW_METHODS as r, PHRenownChain as t };
|
|
19
|
+
//# sourceMappingURL=meta-bV7L-1yb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-bV7L-1yb.d.ts","names":[],"sources":["../src/wallet/rainbow/meta.ts"],"mappings":";;;UAIiB,aAAA;EACf,EAAA;EACA,IAAA;AAAA;AAAA,UAKe,4BAAA;EAGf,sBAAA;EACA,eAAA;EACA,OAAA;EAGA,MAAA,aAAmB,aAAA,KAAkB,aAAA;EAGrC,GAAA;AAAA;AAAA,cAGW,eAAA,EAAiB,WAAA;AAAA,cAIjB,kBAAA,EAAoB,iBAAA"}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { A as LoginStatus, B as Service, C as InternalUser, Ct as DOMAIN_TYPE, D as JWTVerifyPolicies, Dt as VERIFIABLE_CREDENTIAL_EIP712_TYPE, E as JWTVerified, Et as RENOWN_SESSION_COOKIE, F as RenownEventEmitter, G as User, H as SignInParams, I as RenownEvents, J as VerificationMethod, K as UserActionSigner, L as RenownProfile, M as PowerhouseVerifiableCredential, N as ProfileFetcher, O as JsonWebKey, P as Proof, Q as BaseStorage, R as RenownStorage, S as IVerifiableCredential, St as DEFAULT_RENOWN_URL, T as JWTPayload, Tt as RENOWN_READ_MODEL_SUBGRAPH, U as Signer, V as ServiceEndpoint, W as Unsubscribe, X as VerifiedJWT, Y as VerifiedCredential, Z as W3CCredential, _ as IPowerhouseCredentialSubject, _t as CREDENTIAL_SCHEMA_EIP712_TYPE, a as JwkKeyPair, at as SignCredentialTypedData, b as IRenown, bt as DEFAULT_RENOWN_CHAIN_ID, c as ConditionWeightedThreshold, ct as buildAndSignCredential, d as DIDDocument, dt as verifyAuthCredential, et as IEventEmitter, f as DIDDocumentMetadata, ft as verifyCredentialSignature, g as IAuthCredentialSubject, gt as SwitchboardSource, h as EcdsaSignature, ht as SwitchboardRequestFn, i as JsonWebKeyPairStorage, it as FetchDelegationCredentialOptions, j as PKHDid, k as KeyCapabilitySection, l as CreateBearerTokenOptions, lt as fetchDelegationCredential, m as DIDResolutionResult, mt as SwitchboardClient, n as IConnectCrypto, nt as CredentialDomain, o as AuthVerifiableCredential, ot as VerifiedAuthCredential, p as DIDResolutionMetadata, pt as MissingSwitchboardError, q as Verifiable, r as IRenownCrypto, rt as CredentialMessage, s as AuthVerifiedCredential, st as VerifyAuthCredentialOptions, t as DID, tt as BuildCredentialParams, u as CredentialStatus, ut as recoverCredentialSigner, v as IPowerhouseIssuerType, vt as CREDENTIAL_SUBJECT_TYPE, w as Issuer, wt as ISSUER_TYPE, x as ISigner, xt as DEFAULT_RENOWN_NETWORK_ID, y as IProof, yt as CREDENTIAL_TYPES, z as RenownStorageMap } from "./types-BGQKPoUr.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, u as RenownCrypto } from "./index-BLIpkdF7.js";
|
|
3
|
+
import { C as resolveSwitchboardEndpoint, S as ResolveSwitchboardEndpointOptions, T as RenownMemoryStorage, _ as CredentialCheck, a as getResolver, b as BaseRenownBuilder, c as RenownSession, d as RenownSessionProfile, f as VerifyRenownSessionOptions, g as fetchRenownProfile, h as verifyRenownSession, i as createAuthBearerToken, l as RenownSessionClaims, m as serializeRenownSessionCookie, n as VerifyAuthBearerTokenOptions, o as parsePkhDid, p as readSessionClaims, r as assertIsAuthCredential, s as verifyAuthBearerToken, t as ILogger, u as RenownSessionCookie, v as LocalCredentialVerifierOptions, w as Renown, x as RenownBuilderOptions, y as createLocalCredentialVerifier } from "./utils-DtWREYeO.js";
|
|
3
4
|
|
|
4
5
|
//#region src/crypto/node-key-storage.d.ts
|
|
5
6
|
declare const RENOWN_PRIVATE_KEY_ENV = "PH_RENOWN_PRIVATE_KEY";
|
|
@@ -53,17 +54,16 @@ interface NodeRenownBuilderOptions {
|
|
|
53
54
|
keyPath?: string;
|
|
54
55
|
/** Renown server URL. Defaults to https://www.renown.id */
|
|
55
56
|
baseUrl?: string;
|
|
57
|
+
/** Switchboard GraphQL endpoint for the direct-to-reactor flow. */
|
|
58
|
+
switchboardUrl?: string;
|
|
59
|
+
/** Re-check a stored credential on build (default "always"). */
|
|
60
|
+
revalidate?: "always" | "never";
|
|
56
61
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Node.js-specific Renown builder with pre-configured defaults.
|
|
59
|
-
* Uses file-based storage for both user data and key storage.
|
|
60
|
-
*/
|
|
62
|
+
/** Node.js Renown builder: file-based user + key storage. */
|
|
61
63
|
declare class RenownBuilder extends BaseRenownBuilder {
|
|
62
|
-
|
|
63
|
-
* @param appName - Application name used for signing context
|
|
64
|
-
* @param options - Node.js-specific configuration options
|
|
65
|
-
*/
|
|
64
|
+
#private;
|
|
66
65
|
constructor(appName: string, options?: NodeRenownBuilderOptions);
|
|
66
|
+
build(): Promise<Renown>;
|
|
67
67
|
}
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region src/login.node.d.ts
|
|
@@ -133,5 +133,5 @@ declare function parseExpiry(expiry: string): number;
|
|
|
133
133
|
*/
|
|
134
134
|
declare function formatExpiry(expiresIn: number): string;
|
|
135
135
|
//#endregion
|
|
136
|
-
export { AccessTokenResult, AuthStatusResult, AuthVerifiableCredential, AuthVerifiedCredential, BaseRenownBuilder, BrowserLoginOptions, BrowserLoginResult, BuildCredentialParams, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, ConditionWeightedThreshold, ConnectCrypto, CreateBearerTokenOptions, CredentialDomain, CredentialMessage, CredentialStatus, DEFAULT_KEYPAIR_PATH, DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_NETWORK_ID, DEFAULT_RENOWN_STORAGE_PATH, 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, NodeEventEmitter, NodeKeyStorage, NodeRenownBuilderOptions, NodeRenownEventEmitter, NodeRenownStorage, NodeStorage, PKHDid, PowerhouseVerifiableCredential, ProfileFetcher, Proof, RENOWN_PRIVATE_KEY_ENV, 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, browserLogin, buildAndSignCredential, createAuthBearerToken, createSignatureVerifier, extractResultingHashFromSignature, fetchDelegationCredential, fetchRenownProfile, formatExpiry, generateAccessToken, getAuthStatus, getResolver, openBrowser, parseExpiry, parsePkhDid, parseSignatureHashField, recoverCredentialSigner, signatureHasResultingHash, verifyAuthBearerToken, verifyAuthCredential, verifyCredentialSignature };
|
|
136
|
+
export { AccessTokenResult, AuthStatusResult, AuthVerifiableCredential, AuthVerifiedCredential, BaseRenownBuilder, BrowserLoginOptions, BrowserLoginResult, BuildCredentialParams, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, ConditionWeightedThreshold, ConnectCrypto, CreateBearerTokenOptions, CredentialCheck, CredentialDomain, CredentialMessage, CredentialStatus, DEFAULT_KEYPAIR_PATH, DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_NETWORK_ID, DEFAULT_RENOWN_STORAGE_PATH, 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, LocalCredentialVerifierOptions, LoginStatus, MemoryKeyStorage, MissingSwitchboardError, NodeEventEmitter, NodeKeyStorage, NodeRenownBuilderOptions, NodeRenownEventEmitter, NodeRenownStorage, NodeStorage, PKHDid, PowerhouseVerifiableCredential, ProfileFetcher, Proof, RENOWN_PRIVATE_KEY_ENV, RENOWN_READ_MODEL_SUBGRAPH, RENOWN_SESSION_COOKIE, Renown, RenownBuilder, RenownBuilderOptions, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, RenownEventEmitter, RenownEvents, RenownMemoryStorage, RenownProfile, RenownSession, RenownSessionClaims, RenownSessionCookie, RenownSessionProfile, RenownStorage, RenownStorageMap, ResolveSwitchboardEndpointOptions, Service, ServiceEndpoint, SignCredentialTypedData, SignInParams, Signer, SwitchboardClient, SwitchboardRequestFn, SwitchboardSource, Unsubscribe, User, UserActionSigner, VERIFIABLE_CREDENTIAL_EIP712_TYPE, Verifiable, VerificationMethod, VerifiedAuthCredential, VerifiedCredential, VerifiedJWT, VerifyAuthBearerTokenOptions, VerifyAuthCredentialOptions, VerifyRenownSessionOptions, W3CCredential, assertIsAuthCredential, browserLogin, buildAndSignCredential, createAuthBearerToken, createLocalCredentialVerifier, createSignatureVerifier, extractResultingHashFromSignature, fetchDelegationCredential, fetchRenownProfile, formatExpiry, generateAccessToken, getAuthStatus, getResolver, openBrowser, parseExpiry, parsePkhDid, parseSignatureHashField, readSessionClaims, recoverCredentialSigner, resolveSwitchboardEndpoint, serializeRenownSessionCookie, signatureHasResultingHash, verifyAuthBearerToken, verifyAuthCredential, verifyCredentialSignature, verifyRenownSession };
|
|
137
137
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","names":[],"sources":["../src/crypto/node-key-storage.ts","../src/event/event.node.ts","../src/storage/storage.node.ts","../src/init.node.ts","../src/login.node.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.d.ts","names":[],"sources":["../src/crypto/node-key-storage.ts","../src/event/event.node.ts","../src/storage/storage.node.ts","../src/init.node.ts","../src/login.node.ts"],"mappings":";;;;;cAWa,sBAAA;AAAA,cACA,oBAAA;;AADb;;;;;cASa,cAAA,YAA0B,qBAAA;EAAA;kBAKrB,oBAAA;EAAA,gBACA,sBAAA;cAGd,QAAA,WACA,OAAA;IAAW,UAAA;IAAqB,MAAA,GAAS,OAAA;EAAA;EAa3C,WAAA,CAAA,GAAe,OAAA,CAAQ,UAAA;EAyBjB,WAAA,CAAY,OAAA,EAAS,UAAA,GAAa,OAAA;EAWxC,aAAA,CAAA,GAAiB,OAAA;AAAA;;;cC5EN,gBAAA,gBACI,MAAA,8BACJ,aAAA,CAAc,MAAA;EAAA;;EAOzB,EAAA,iBAAmB,MAAA,CAAA,CACjB,KAAA,EAAO,CAAA,EACP,QAAA,GAAW,IAAA,EAAM,MAAA,CAAO,CAAA;EAQ1B,IAAA,iBAAqB,MAAA,CAAA,CAAQ,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,MAAA,CAAO,CAAA;AAAA;;;cClBzC,WAAA,WACD,MAAA,oBAA0B,MAAA,2BAC5B,WAAA,CAAY,CAAA;EAAA,iBACH,QAAA;cAEL,QAAA;EAAA,QAYJ,QAAA;EAAA,QAKA,SAAA;EAIR,GAAA,mBAAsB,CAAA,CAAA,CAAG,GAAA,EAAK,GAAA,GAAM,CAAA,CAAE,GAAA;EAKtC,GAAA,mBAAsB,CAAA,CAAA,CAAG,GAAA,EAAK,GAAA,EAAK,KAAA,GAAQ,CAAA,CAAE,GAAA;EAU7C,MAAA,CAAO,GAAA,QAAW,CA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
|
+
import { a as DEFAULT_RENOWN_NETWORK_ID, c as ISSUER_TYPE, d as VERIFIABLE_CREDENTIAL_EIP712_TYPE, i as DEFAULT_RENOWN_CHAIN_ID, l as RENOWN_READ_MODEL_SUBGRAPH, 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 RENOWN_SESSION_COOKIE } from "./constants-BexAR53F.js";
|
|
2
|
+
import { a as RenownMemoryStorage, c as fetchDelegationCredential, d as verifyCredentialSignature, f as MissingSwitchboardError, i as Renown, l as recoverCredentialSigner, m as resolveSwitchboardEndpoint, n as BaseRenownBuilder, o as BaseStorage, p as SwitchboardClient, r as fetchRenownProfile, s as buildAndSignCredential, t as createLocalCredentialVerifier, u as verifyAuthCredential } from "./local-credential-verifier-CU8hmFlR.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-DrjINLqt.js";
|
|
3
4
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
5
6
|
import { EventEmitter } from "node:events";
|
|
@@ -128,22 +129,23 @@ var NodeStorage = class extends BaseStorage {
|
|
|
128
129
|
var NodeRenownEventEmitter = class extends NodeEventEmitter {};
|
|
129
130
|
var NodeRenownStorage = class extends NodeStorage {};
|
|
130
131
|
const DEFAULT_RENOWN_STORAGE_PATH = "./.ph/.renown.json";
|
|
131
|
-
/**
|
|
132
|
-
* Node.js-specific Renown builder with pre-configured defaults.
|
|
133
|
-
* Uses file-based storage for both user data and key storage.
|
|
134
|
-
*/
|
|
132
|
+
/** Node.js Renown builder: file-based user + key storage. */
|
|
135
133
|
var RenownBuilder = class extends BaseRenownBuilder {
|
|
136
|
-
|
|
137
|
-
* @param appName - Application name used for signing context
|
|
138
|
-
* @param options - Node.js-specific configuration options
|
|
139
|
-
*/
|
|
134
|
+
#revalidate;
|
|
140
135
|
constructor(appName, options = {}) {
|
|
141
136
|
super(appName);
|
|
142
|
-
const { storagePath = DEFAULT_RENOWN_STORAGE_PATH, keyPath, baseUrl } = options;
|
|
137
|
+
const { storagePath = DEFAULT_RENOWN_STORAGE_PATH, keyPath, baseUrl, switchboardUrl, revalidate = "always" } = options;
|
|
138
|
+
this.#revalidate = revalidate;
|
|
143
139
|
this.withKeyPairStorage(new NodeKeyStorage(keyPath));
|
|
144
140
|
this.withStorage(new NodeRenownStorage(storagePath));
|
|
145
141
|
this.withEventEmitter(new NodeRenownEventEmitter());
|
|
146
142
|
if (baseUrl) this.withBaseUrl(baseUrl);
|
|
143
|
+
if (switchboardUrl) this.withSwitchboardUrl(switchboardUrl);
|
|
144
|
+
}
|
|
145
|
+
async build() {
|
|
146
|
+
const renown = await super.build();
|
|
147
|
+
if (this.#revalidate === "always" && renown.user) await renown.revalidate();
|
|
148
|
+
return renown;
|
|
147
149
|
}
|
|
148
150
|
};
|
|
149
151
|
//#endregion
|
|
@@ -301,6 +303,96 @@ function formatExpiry(expiresIn) {
|
|
|
301
303
|
return `${expiresIn} second${expiresIn !== 1 ? "s" : ""}`;
|
|
302
304
|
}
|
|
303
305
|
//#endregion
|
|
304
|
-
|
|
306
|
+
//#region src/session.ts
|
|
307
|
+
/** Serialize a session cookie value (token + optional display hint). */
|
|
308
|
+
function serializeRenownSessionCookie(value) {
|
|
309
|
+
return JSON.stringify(value);
|
|
310
|
+
}
|
|
311
|
+
function parseSessionCookie(value) {
|
|
312
|
+
try {
|
|
313
|
+
const parsed = JSON.parse(value);
|
|
314
|
+
if (parsed && typeof parsed === "object" && typeof parsed.token === "string") return parsed;
|
|
315
|
+
} catch {}
|
|
316
|
+
}
|
|
317
|
+
function readSessionClaims(value) {
|
|
318
|
+
const parsed = parseSessionCookie(value);
|
|
319
|
+
if (!parsed) return void 0;
|
|
320
|
+
const parts = parsed.token.split(".");
|
|
321
|
+
if (parts.length < 2) return void 0;
|
|
322
|
+
try {
|
|
323
|
+
const json = Buffer.from(parts[1], "base64url").toString("utf8");
|
|
324
|
+
const payload = JSON.parse(json);
|
|
325
|
+
const subject = payload.vc?.credentialSubject;
|
|
326
|
+
return {
|
|
327
|
+
address: subject?.address,
|
|
328
|
+
chainId: subject?.chainId,
|
|
329
|
+
networkId: subject?.networkId,
|
|
330
|
+
expiresAt: payload.exp
|
|
331
|
+
};
|
|
332
|
+
} catch {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
async function verifyRenownSession(value, options = {}) {
|
|
337
|
+
const { verifyCredential = false } = options;
|
|
338
|
+
const parsed = parseSessionCookie(value);
|
|
339
|
+
if (!parsed) return void 0;
|
|
340
|
+
const { token, profile } = parsed;
|
|
341
|
+
let session;
|
|
342
|
+
if (verifyCredential) {
|
|
343
|
+
const verified = await verifyAuthCredential(token, {
|
|
344
|
+
audience: options.audience,
|
|
345
|
+
renownUrl: options.renownUrl,
|
|
346
|
+
switchboardUrl: options.switchboardUrl
|
|
347
|
+
});
|
|
348
|
+
if (verified) session = {
|
|
349
|
+
user: {
|
|
350
|
+
address: verified.address,
|
|
351
|
+
chainId: verified.chainId,
|
|
352
|
+
networkId: verified.networkId,
|
|
353
|
+
did: verified.did,
|
|
354
|
+
credential: verified.credential
|
|
355
|
+
},
|
|
356
|
+
appDid: verified.appDid
|
|
357
|
+
};
|
|
358
|
+
} else {
|
|
359
|
+
const verified = await verifyAuthBearerToken(token, { audience: options.audience });
|
|
360
|
+
if (verified) {
|
|
361
|
+
const subject = verified.verifiableCredential.credentialSubject;
|
|
362
|
+
const did = `did:pkh:${subject.networkId}:${subject.chainId}:${subject.address.toLowerCase()}`;
|
|
363
|
+
session = {
|
|
364
|
+
user: {
|
|
365
|
+
address: subject.address,
|
|
366
|
+
chainId: subject.chainId,
|
|
367
|
+
networkId: subject.networkId,
|
|
368
|
+
did,
|
|
369
|
+
credential: void 0
|
|
370
|
+
},
|
|
371
|
+
appDid: verified.issuer,
|
|
372
|
+
expiresAt: verified.payload.exp
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (!session) return void 0;
|
|
377
|
+
if (profile) {
|
|
378
|
+
const name = profile.name ?? profile.username ?? void 0;
|
|
379
|
+
const avatarUrl = profile.avatar ?? profile.userImage ?? void 0;
|
|
380
|
+
const user = { ...session.user };
|
|
381
|
+
if (name || avatarUrl) user.ens = {
|
|
382
|
+
name,
|
|
383
|
+
avatarUrl
|
|
384
|
+
};
|
|
385
|
+
if (profile.documentId) user.profile = {
|
|
386
|
+
documentId: profile.documentId,
|
|
387
|
+
username: profile.username ?? null,
|
|
388
|
+
userImage: profile.userImage ?? null,
|
|
389
|
+
ethAddress: session.user.address
|
|
390
|
+
};
|
|
391
|
+
session.user = user;
|
|
392
|
+
}
|
|
393
|
+
return session;
|
|
394
|
+
}
|
|
395
|
+
//#endregion
|
|
396
|
+
export { BaseRenownBuilder, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, ConnectCrypto, DEFAULT_KEYPAIR_PATH, DEFAULT_RENOWN_CHAIN_ID, DEFAULT_RENOWN_NETWORK_ID, DEFAULT_RENOWN_STORAGE_PATH, DEFAULT_RENOWN_URL, DOMAIN_TYPE, ISSUER_TYPE, MemoryKeyStorage, MissingSwitchboardError, NodeEventEmitter, NodeKeyStorage, NodeRenownEventEmitter, NodeRenownStorage, NodeStorage, RENOWN_PRIVATE_KEY_ENV, RENOWN_READ_MODEL_SUBGRAPH, RENOWN_SESSION_COOKIE, Renown, RenownBuilder, RenownCrypto, RenownCryptoBuilder, RenownCryptoSigner, RenownMemoryStorage, SwitchboardClient, VERIFIABLE_CREDENTIAL_EIP712_TYPE, assertIsAuthCredential, browserLogin, buildAndSignCredential, createAuthBearerToken, createLocalCredentialVerifier, createSignatureVerifier, extractResultingHashFromSignature, fetchDelegationCredential, fetchRenownProfile, formatExpiry, generateAccessToken, getAuthStatus, getResolver, openBrowser, parseExpiry, parsePkhDid, parseSignatureHashField, readSessionClaims, recoverCredentialSigner, resolveSwitchboardEndpoint, serializeRenownSessionCookie, signatureHasResultingHash, verifyAuthBearerToken, verifyAuthCredential, verifyCredentialSignature, verifyRenownSession };
|
|
305
397
|
|
|
306
398
|
//# sourceMappingURL=node.js.map
|