@renown/sdk 6.2.0-dev.5 → 6.2.0-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/dist/browser-key-storage-DSkDBAhU.d.ts +14 -0
- package/dist/browser-key-storage-DSkDBAhU.d.ts.map +1 -0
- package/dist/browser-key-storage-v4O-fjz0.js +68 -0
- package/dist/browser-key-storage-v4O-fjz0.js.map +1 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +3 -0
- package/dist/index.d.ts +3 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -66
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -1
- package/dist/node.js.map +1 -1
- package/dist/renown-builder-CQIpzrA6.js +433 -0
- package/dist/renown-builder-CQIpzrA6.js.map +1 -0
- package/dist/{utils-CfiesQfZ.d.ts → signer-DYKGoYHB.d.ts} +27 -194
- package/dist/signer-DYKGoYHB.d.ts.map +1 -0
- package/dist/{renown-builder-BvFud66V.js → signer-XkA-D7Qt.js} +2 -417
- package/dist/signer-XkA-D7Qt.js.map +1 -0
- package/dist/utils-D8C7f9Qs.d.ts +182 -0
- package/dist/utils-D8C7f9Qs.d.ts.map +1 -0
- package/package.json +26 -4
- package/dist/renown-builder-BvFud66V.js.map +0 -1
- package/dist/utils-CfiesQfZ.d.ts.map +0 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Resolver } from "did-resolver";
|
|
2
|
-
import { Hex, TypedDataDomain, TypedDataParameter } from "viem";
|
|
3
1
|
import { Action, AppActionSigner, ISigner, ISigner as ISigner$1, Signature, SignatureVerificationHandler, User, UserActionSigner } from "@powerhousedao/shared/document-model";
|
|
4
2
|
|
|
5
3
|
//#region src/constants.d.ts
|
|
@@ -115,31 +113,6 @@ declare const CREDENTIAL_TYPES: {
|
|
|
115
113
|
}];
|
|
116
114
|
};
|
|
117
115
|
//#endregion
|
|
118
|
-
//#region src/crypto/types.d.ts
|
|
119
|
-
type JwkKeyPair = {
|
|
120
|
-
publicKey: JsonWebKey;
|
|
121
|
-
privateKey: JsonWebKey;
|
|
122
|
-
};
|
|
123
|
-
interface JsonWebKeyPairStorage {
|
|
124
|
-
loadKeyPair(): Promise<JwkKeyPair | undefined>;
|
|
125
|
-
saveKeyPair(keyPair: JwkKeyPair): Promise<void>;
|
|
126
|
-
removeKeyPair(): Promise<void>;
|
|
127
|
-
}
|
|
128
|
-
type DID = `did:${string}`;
|
|
129
|
-
interface IRenownCrypto {
|
|
130
|
-
did: DID;
|
|
131
|
-
publicKey: CryptoKey;
|
|
132
|
-
removeDid(): Promise<void>;
|
|
133
|
-
sign: (data: Uint8Array) => Promise<Uint8Array>;
|
|
134
|
-
verify: (data: Uint8Array, signature: Uint8Array) => Promise<boolean>;
|
|
135
|
-
issuer: Issuer;
|
|
136
|
-
getBearerToken: (address: string | undefined, options?: CreateBearerTokenOptions) => Promise<string>;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* @deprecated Use IRenownCrypto instead
|
|
140
|
-
*/
|
|
141
|
-
interface IConnectCrypto extends IRenownCrypto {}
|
|
142
|
-
//#endregion
|
|
143
116
|
//#region src/event/types.d.ts
|
|
144
117
|
interface IEventEmitter<Events extends Record<string, unknown>> {
|
|
145
118
|
/**
|
|
@@ -437,6 +410,31 @@ interface CreateBearerTokenOptions {
|
|
|
437
410
|
aud?: string;
|
|
438
411
|
}
|
|
439
412
|
//#endregion
|
|
413
|
+
//#region src/crypto/types.d.ts
|
|
414
|
+
type JwkKeyPair = {
|
|
415
|
+
publicKey: JsonWebKey;
|
|
416
|
+
privateKey: JsonWebKey;
|
|
417
|
+
};
|
|
418
|
+
interface JsonWebKeyPairStorage {
|
|
419
|
+
loadKeyPair(): Promise<JwkKeyPair | undefined>;
|
|
420
|
+
saveKeyPair(keyPair: JwkKeyPair): Promise<void>;
|
|
421
|
+
removeKeyPair(): Promise<void>;
|
|
422
|
+
}
|
|
423
|
+
type DID = `did:${string}`;
|
|
424
|
+
interface IRenownCrypto {
|
|
425
|
+
did: DID;
|
|
426
|
+
publicKey: CryptoKey;
|
|
427
|
+
removeDid(): Promise<void>;
|
|
428
|
+
sign: (data: Uint8Array) => Promise<Uint8Array>;
|
|
429
|
+
verify: (data: Uint8Array, signature: Uint8Array) => Promise<boolean>;
|
|
430
|
+
issuer: Issuer;
|
|
431
|
+
getBearerToken: (address: string | undefined, options?: CreateBearerTokenOptions) => Promise<string>;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* @deprecated Use IRenownCrypto instead
|
|
435
|
+
*/
|
|
436
|
+
interface IConnectCrypto extends IRenownCrypto {}
|
|
437
|
+
//#endregion
|
|
440
438
|
//#region src/crypto/renown-crypto.d.ts
|
|
441
439
|
declare class RenownCrypto implements IRenownCrypto {
|
|
442
440
|
#private;
|
|
@@ -549,170 +547,5 @@ declare function extractResultingHashFromSignature(signature: Signature): string
|
|
|
549
547
|
*/
|
|
550
548
|
declare function signatureHasResultingHash(signature: Signature): boolean;
|
|
551
549
|
//#endregion
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
declare class Renown implements IRenown {
|
|
555
|
-
#private;
|
|
556
|
-
constructor(store: RenownStorage, eventEmitter: RenownEventEmitter, crypto: IRenownCrypto, appName: string, baseUrl?: string, profileFetcher?: ProfileFetcher);
|
|
557
|
-
get baseUrl(): string;
|
|
558
|
-
get user(): InternalUser | undefined;
|
|
559
|
-
get status(): LoginStatus;
|
|
560
|
-
get signer(): ISigner$1;
|
|
561
|
-
get crypto(): IRenownCrypto;
|
|
562
|
-
get did(): `did:${string}`;
|
|
563
|
-
get profileFetcher(): ProfileFetcher | undefined;
|
|
564
|
-
login(userDid: string): Promise<User$1>;
|
|
565
|
-
logout(): Promise<void>;
|
|
566
|
-
on<K extends keyof RenownEvents>(event: K, listener: (data: RenownEvents[K]) => void): () => void;
|
|
567
|
-
verifyBearerToken(token: string): Promise<false | AuthVerifiedCredential>;
|
|
568
|
-
getBearerToken(options: CreateBearerTokenOptions): Promise<string>;
|
|
569
|
-
}
|
|
570
|
-
//#endregion
|
|
571
|
-
//#region src/credential.d.ts
|
|
572
|
-
/** EIP-712 domain as signed by the credential issuer. */
|
|
573
|
-
type CredentialDomain = {
|
|
574
|
-
version: string;
|
|
575
|
-
chainId: number;
|
|
576
|
-
};
|
|
577
|
-
/** The credential body that is EIP-712 signed (everything except `proof`). */
|
|
578
|
-
type CredentialMessage = {
|
|
579
|
-
"@context": string[];
|
|
580
|
-
type: string[];
|
|
581
|
-
id: string;
|
|
582
|
-
issuer: {
|
|
583
|
-
id: string;
|
|
584
|
-
ethereumAddress: Hex;
|
|
585
|
-
};
|
|
586
|
-
credentialSubject: {
|
|
587
|
-
id: string;
|
|
588
|
-
app: string;
|
|
589
|
-
};
|
|
590
|
-
credentialSchema: {
|
|
591
|
-
id: string;
|
|
592
|
-
type: string;
|
|
593
|
-
};
|
|
594
|
-
issuanceDate: string;
|
|
595
|
-
expirationDate: string;
|
|
596
|
-
};
|
|
597
|
-
/** Typed-data signer; matches the loose shape used by wallet adapters. */
|
|
598
|
-
type SignCredentialTypedData = (args: {
|
|
599
|
-
domain: TypedDataDomain;
|
|
600
|
-
types: Record<string, readonly TypedDataParameter[]>;
|
|
601
|
-
primaryType: string;
|
|
602
|
-
message: Record<string, unknown>;
|
|
603
|
-
}) => Promise<Hex>;
|
|
604
|
-
interface BuildCredentialParams {
|
|
605
|
-
signTypedData: SignCredentialTypedData;
|
|
606
|
-
address: Hex;
|
|
607
|
-
chainId: number;
|
|
608
|
-
app: string;
|
|
609
|
-
/** Credential subject id: the app/client DID the credential delegates to. */
|
|
610
|
-
appId: string;
|
|
611
|
-
expiresInDays?: number;
|
|
612
|
-
}
|
|
613
|
-
/** Assemble a Renown delegation VC and sign it with the provided signer. */
|
|
614
|
-
declare function buildAndSignCredential(params: BuildCredentialParams): Promise<PowerhouseVerifiableCredential>;
|
|
615
|
-
/** Recover the address that signed a credential's EIP-712 proof. */
|
|
616
|
-
declare function recoverCredentialSigner(credential: PowerhouseVerifiableCredential): Promise<Hex>;
|
|
617
|
-
/** True when the proof was signed by the credential's declared issuer address. */
|
|
618
|
-
declare function verifyCredentialSignature(credential: PowerhouseVerifiableCredential): Promise<boolean>;
|
|
619
|
-
//#endregion
|
|
620
|
-
//#region src/renown-builder.d.ts
|
|
621
|
-
interface RenownBuilderOptions {
|
|
622
|
-
appName: string;
|
|
623
|
-
storage?: RenownStorage;
|
|
624
|
-
eventEmitter?: RenownEventEmitter;
|
|
625
|
-
crypto?: IRenownCrypto;
|
|
626
|
-
keyPairStorage?: JsonWebKeyPairStorage;
|
|
627
|
-
baseUrl?: string;
|
|
628
|
-
profileFetcher?: ProfileFetcher;
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* Base builder for creating Renown instances.
|
|
632
|
-
* Use platform-specific builders (RenownBuilder from init.browser.js or init.node.js)
|
|
633
|
-
* for pre-configured defaults.
|
|
634
|
-
*/
|
|
635
|
-
declare class BaseRenownBuilder {
|
|
636
|
-
#private;
|
|
637
|
-
/**
|
|
638
|
-
* @param appName - Application name used for signing context
|
|
639
|
-
*/
|
|
640
|
-
constructor(appName: string);
|
|
641
|
-
/**
|
|
642
|
-
* Set custom storage for user data persistence.
|
|
643
|
-
* Defaults to in-memory storage if not set.
|
|
644
|
-
*/
|
|
645
|
-
withStorage(storage: RenownStorage): this;
|
|
646
|
-
/**
|
|
647
|
-
* Set custom event emitter for user state changes.
|
|
648
|
-
* Defaults to in-memory event emitter if not set.
|
|
649
|
-
*/
|
|
650
|
-
withEventEmitter(eventEmitter: RenownEventEmitter): this;
|
|
651
|
-
/**
|
|
652
|
-
* Set a pre-built crypto instance.
|
|
653
|
-
* Either crypto or keyPairStorage must be provided.
|
|
654
|
-
*/
|
|
655
|
-
withCrypto(crypto: IRenownCrypto): this;
|
|
656
|
-
/**
|
|
657
|
-
* Set key pair storage for cryptographic keys.
|
|
658
|
-
* A crypto instance will be built from this storage.
|
|
659
|
-
* Either crypto or keyPairStorage must be provided.
|
|
660
|
-
*/
|
|
661
|
-
withKeyPairStorage(keyPairStorage: JsonWebKeyPairStorage): this;
|
|
662
|
-
/**
|
|
663
|
-
* Set the Renown server URL for credential verification.
|
|
664
|
-
* Defaults to https://www.renown.id
|
|
665
|
-
*/
|
|
666
|
-
withBaseUrl(baseUrl: string): this;
|
|
667
|
-
/**
|
|
668
|
-
* Set a profile fetcher strategy for enriching user data after login.
|
|
669
|
-
* The fetcher receives the authenticated user and the base URL,
|
|
670
|
-
* and returns a RenownProfile. Called in the background after each login.
|
|
671
|
-
* Defaults to fetchRenownProfile which calls the Renown API.
|
|
672
|
-
*/
|
|
673
|
-
withProfileFetcher(profileFetcher: ProfileFetcher): this;
|
|
674
|
-
/**
|
|
675
|
-
* Build and initialize the Renown instance.
|
|
676
|
-
* If a user is stored, attempts to re-authenticate them.
|
|
677
|
-
* @throws Error if neither crypto nor keyPairStorage is provided
|
|
678
|
-
*/
|
|
679
|
-
build(): Promise<Renown>;
|
|
680
|
-
/**
|
|
681
|
-
* Create a BaseRenownBuilder from options object for a more concise API
|
|
682
|
-
*/
|
|
683
|
-
static from(options: RenownBuilderOptions): BaseRenownBuilder;
|
|
684
|
-
}
|
|
685
|
-
//#endregion
|
|
686
|
-
//#region src/profile.d.ts
|
|
687
|
-
declare const fetchRenownProfile: ProfileFetcher;
|
|
688
|
-
//#endregion
|
|
689
|
-
//#region src/utils.d.ts
|
|
690
|
-
type ILogger = {
|
|
691
|
-
level: "verbose" | "debug" | "info" | "warn" | "error";
|
|
692
|
-
verbose: (message: string, ...replacements: any[]) => void;
|
|
693
|
-
debug: (message: string, ...replacements: any[]) => void;
|
|
694
|
-
info: (message: string, ...replacements: any[]) => void;
|
|
695
|
-
warn: (message: string, ...replacements: any[]) => void;
|
|
696
|
-
error: (message: string, ...replacements: any[]) => void;
|
|
697
|
-
};
|
|
698
|
-
/**
|
|
699
|
-
* Parse a DID:pkh string to extract network, chain ID, and address information
|
|
700
|
-
* @param did - The DID string in format "did:pkh:networkId:chainId:address"
|
|
701
|
-
* @returns Parsed DID information
|
|
702
|
-
* @throws Error if the DID format is invalid
|
|
703
|
-
*/
|
|
704
|
-
declare function parsePkhDid(did: string): PKHDid;
|
|
705
|
-
interface VerifyAuthBearerTokenOptions {
|
|
706
|
-
/** Expected `aud` claim. Required when verifying tokens that include an
|
|
707
|
-
* audience claim — did-jwt rejects them otherwise with
|
|
708
|
-
* `invalid_config: JWT audience is required but your app address has not
|
|
709
|
-
* been configured`. Tokens minted without `aud` are unaffected. */
|
|
710
|
-
audience?: string;
|
|
711
|
-
}
|
|
712
|
-
declare function verifyAuthBearerToken(jwt: string, options?: VerifyAuthBearerTokenOptions): Promise<false | AuthVerifiedCredential>;
|
|
713
|
-
declare function assertIsAuthCredential(credential: VerifiedCredential): asserts credential is AuthVerifiedCredential;
|
|
714
|
-
declare function createAuthBearerToken(chainId: number, networkId: string, address: string, issuer: Issuer, options?: CreateBearerTokenOptions): Promise<string>;
|
|
715
|
-
declare const getResolver: () => Resolver;
|
|
716
|
-
//#endregion
|
|
717
|
-
export { LoginStatus as $, AuthVerifiedCredential as A, DEFAULT_RENOWN_NETWORK_ID as At, IPowerhouseCredentialSubject as B, parseSignatureHashField as C, IRenownCrypto as Ct, ConnectCrypto as D, CREDENTIAL_SUBJECT_TYPE as Dt, RenownCryptoBuilder as E, CREDENTIAL_SCHEMA_EIP712_TYPE as Et, DIDDocumentMetadata as F, IVerifiableCredential as G, IProof as H, DIDResolutionMetadata as I, JWTPayload as J, InternalUser as K, DIDResolutionResult as L, CreateBearerTokenOptions as M, DOMAIN_TYPE as Mt, CredentialStatus as N, ISSUER_TYPE as Nt, RenownCrypto as O, CREDENTIAL_TYPES as Ot, DIDDocument as P, VERIFIABLE_CREDENTIAL_EIP712_TYPE as Pt, KeyCapabilitySection as Q, EcdsaSignature as R, extractResultingHashFromSignature as S, IConnectCrypto as St, MemoryKeyStorage as T, JwkKeyPair as Tt, IRenown as U, IPowerhouseIssuerType as V, ISigner$1 as W, JWTVerifyPolicies as X, JWTVerified as Y, JsonWebKey$1 as Z, verifyCredentialSignature as _, VerifiedJWT as _t, getResolver as a, RenownEvents as at, RenownCryptoSigner as b, IEventEmitter as bt, fetchRenownProfile as c, RenownStorageMap as ct, BuildCredentialParams as d, Signer as dt, PKHDid as et, CredentialDomain as f, Unsubscribe as ft, recoverCredentialSigner as g, VerifiedCredential as gt, buildAndSignCredential as h, VerificationMethod as ht, createAuthBearerToken as i, RenownEventEmitter as it, ConditionWeightedThreshold as j, DEFAULT_RENOWN_URL as jt, AuthVerifiableCredential as k, DEFAULT_RENOWN_CHAIN_ID as kt, BaseRenownBuilder as l, Service as lt, SignCredentialTypedData as m, Verifiable as mt, VerifyAuthBearerTokenOptions as n, ProfileFetcher as nt, parsePkhDid as o, RenownProfile as ot, CredentialMessage as p, User$1 as pt, Issuer as q, assertIsAuthCredential as r, Proof as rt, verifyAuthBearerToken as s, RenownStorage as st, ILogger as t, PowerhouseVerifiableCredential as tt, RenownBuilderOptions as u, ServiceEndpoint as ut, Renown as v, W3CCredential as vt, signatureHasResultingHash as w, JsonWebKeyPairStorage as wt, createSignatureVerifier as x, DID as xt, RenownMemoryStorage as y, BaseStorage as yt, IAuthCredentialSubject as z };
|
|
718
|
-
//# sourceMappingURL=utils-CfiesQfZ.d.ts.map
|
|
550
|
+
export { User$1 as $, ISigner$1 as A, PKHDid as B, DIDResolutionResult as C, IPowerhouseIssuerType as D, IPowerhouseCredentialSubject as E, JWTVerified as F, RenownEvents as G, ProfileFetcher as H, JWTVerifyPolicies as I, RenownStorageMap as J, RenownProfile as K, JsonWebKey$1 as L, InternalUser as M, Issuer as N, IProof as O, JWTPayload as P, Unsubscribe as Q, KeyCapabilitySection as R, DIDResolutionMetadata as S, IAuthCredentialSubject as T, Proof as U, PowerhouseVerifiableCredential as V, RenownEventEmitter as W, ServiceEndpoint as X, Service as Y, Signer as Z, ConditionWeightedThreshold as _, signatureHasResultingHash as a, BaseStorage as at, DIDDocument as b, ConnectCrypto as c, CREDENTIAL_SCHEMA_EIP712_TYPE as ct, IConnectCrypto as d, DEFAULT_RENOWN_CHAIN_ID as dt, Verifiable as et, IRenownCrypto as f, DEFAULT_RENOWN_NETWORK_ID as ft, AuthVerifiedCredential as g, VERIFIABLE_CREDENTIAL_EIP712_TYPE as gt, AuthVerifiableCredential as h, ISSUER_TYPE as ht, parseSignatureHashField as i, W3CCredential as it, IVerifiableCredential as j, IRenown as k, RenownCrypto as l, CREDENTIAL_SUBJECT_TYPE as lt, JwkKeyPair as m, DOMAIN_TYPE as mt, createSignatureVerifier as n, VerifiedCredential as nt, MemoryKeyStorage as o, MemoryStorage as ot, JsonWebKeyPairStorage as p, DEFAULT_RENOWN_URL as pt, RenownStorage as q, extractResultingHashFromSignature as r, VerifiedJWT as rt, RenownCryptoBuilder as s, IEventEmitter as st, RenownCryptoSigner as t, VerificationMethod as tt, DID as u, CREDENTIAL_TYPES as ut, CreateBearerTokenOptions as v, EcdsaSignature as w, DIDDocumentMetadata as x, CredentialStatus as y, LoginStatus as z };
|
|
551
|
+
//# sourceMappingURL=signer-DYKGoYHB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer-DYKGoYHB.d.ts","names":[],"sources":["../src/constants.ts","../src/event/types.ts","../src/storage/common.ts","../src/types.ts","../src/crypto/types.ts","../src/crypto/renown-crypto.ts","../src/crypto/renown-crypto-builder.ts","../src/crypto/memory-key-storage.ts","../src/crypto/signer.ts"],"mappings":";;;cAAa,kBAAA;AAAA,cACA,yBAAA;AAAA,cACA,uBAAA;AAAA,cAEA,WAAA;EAAA;;;;;;cAKA,iCAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;cAWA,6BAAA;EAAA;;;;;;cAKA,uBAAA;EAAA;;;;;;cAKA,WAAA;EAAA;;;;;;cAKA,gBAAA;EAAA;;;;;;;;;;;;;;;;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R,kBAAA,UACA,WAAA,GAAc,WAAA,GACb,OAAA,CAAQ,SAAA;ERvDH;;;EAAA,QQgEM,WAAA;EAAA,QAiCA,UAAA;EAAA,QAYN,qBAAA;EAAA,QASA,gBAAA;EAAA,QAQA,mBAAA;AAAA;;;;;iBAcM,uBAAA,CACd,gBAAA,aACC,4BAAA;;;;;;AR5IH;;;;;iBQ4VgB,uBAAA,CAAwB,SAAA;EACtC,aAAA;EACA,kBAAA;AAAA;;ARzVF;;;;;iBQgXgB,iCAAA,CACd,SAAA,EAAW,SAAA;;;;;AR5Wb;;iBQyXgB,yBAAA,CAA0B,SAAA,EAAW,SAAA"}
|
|
@@ -3,81 +3,6 @@ import { createVerifiableCredentialJwt, verifyCredential } from "did-jwt-vc";
|
|
|
3
3
|
import { Resolver } from "did-resolver";
|
|
4
4
|
import { getResolver } from "key-did-resolver";
|
|
5
5
|
import { encodeDIDFromPub, getPublicKey } from "@didtools/key-webcrypto";
|
|
6
|
-
import { recoverTypedDataAddress } from "viem";
|
|
7
|
-
//#region src/constants.ts
|
|
8
|
-
const DEFAULT_RENOWN_URL = "https://www.renown.id";
|
|
9
|
-
const DEFAULT_RENOWN_NETWORK_ID = "eip155";
|
|
10
|
-
const DEFAULT_RENOWN_CHAIN_ID = "1";
|
|
11
|
-
const DOMAIN_TYPE = [{
|
|
12
|
-
name: "version",
|
|
13
|
-
type: "string"
|
|
14
|
-
}, {
|
|
15
|
-
name: "chainId",
|
|
16
|
-
type: "uint256"
|
|
17
|
-
}];
|
|
18
|
-
const VERIFIABLE_CREDENTIAL_EIP712_TYPE = [
|
|
19
|
-
{
|
|
20
|
-
name: "@context",
|
|
21
|
-
type: "string[]"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: "type",
|
|
25
|
-
type: "string[]"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: "id",
|
|
29
|
-
type: "string"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: "issuer",
|
|
33
|
-
type: "Issuer"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: "credentialSubject",
|
|
37
|
-
type: "CredentialSubject"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: "credentialSchema",
|
|
41
|
-
type: "CredentialSchema"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: "issuanceDate",
|
|
45
|
-
type: "string"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: "expirationDate",
|
|
49
|
-
type: "string"
|
|
50
|
-
}
|
|
51
|
-
];
|
|
52
|
-
const CREDENTIAL_SCHEMA_EIP712_TYPE = [{
|
|
53
|
-
name: "id",
|
|
54
|
-
type: "string"
|
|
55
|
-
}, {
|
|
56
|
-
name: "type",
|
|
57
|
-
type: "string"
|
|
58
|
-
}];
|
|
59
|
-
const CREDENTIAL_SUBJECT_TYPE = [{
|
|
60
|
-
name: "app",
|
|
61
|
-
type: "string"
|
|
62
|
-
}, {
|
|
63
|
-
name: "id",
|
|
64
|
-
type: "string"
|
|
65
|
-
}];
|
|
66
|
-
const ISSUER_TYPE = [{
|
|
67
|
-
name: "id",
|
|
68
|
-
type: "string"
|
|
69
|
-
}, {
|
|
70
|
-
name: "ethereumAddress",
|
|
71
|
-
type: "string"
|
|
72
|
-
}];
|
|
73
|
-
const CREDENTIAL_TYPES = {
|
|
74
|
-
EIP712Domain: DOMAIN_TYPE,
|
|
75
|
-
VerifiableCredential: VERIFIABLE_CREDENTIAL_EIP712_TYPE,
|
|
76
|
-
CredentialSchema: CREDENTIAL_SCHEMA_EIP712_TYPE,
|
|
77
|
-
CredentialSubject: CREDENTIAL_SUBJECT_TYPE,
|
|
78
|
-
Issuer: ISSUER_TYPE
|
|
79
|
-
};
|
|
80
|
-
//#endregion
|
|
81
6
|
//#region src/utils.ts
|
|
82
7
|
/**
|
|
83
8
|
* Parse a DID:pkh string to extract network, chain ID, and address information
|
|
@@ -530,346 +455,6 @@ function signatureHasResultingHash(signature) {
|
|
|
530
455
|
return extractResultingHashFromSignature(signature) !== void 0;
|
|
531
456
|
}
|
|
532
457
|
//#endregion
|
|
533
|
-
|
|
534
|
-
var BaseStorage = class {};
|
|
535
|
-
var MemoryStorage = class extends BaseStorage {
|
|
536
|
-
data = /* @__PURE__ */ new Map();
|
|
537
|
-
get(key) {
|
|
538
|
-
return this.data.get(key);
|
|
539
|
-
}
|
|
540
|
-
set(key, value) {
|
|
541
|
-
if (value === void 0) this.data.delete(key);
|
|
542
|
-
else this.data.set(key, value);
|
|
543
|
-
}
|
|
544
|
-
delete(key) {
|
|
545
|
-
this.data.delete(key);
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
//#endregion
|
|
549
|
-
//#region src/credential.ts
|
|
550
|
-
/** Assemble a Renown delegation VC and sign it with the provided signer. */
|
|
551
|
-
async function buildAndSignCredential(params) {
|
|
552
|
-
const { signTypedData, address, chainId, app, appId, expiresInDays = 7 } = params;
|
|
553
|
-
const issuerId = `did:pkh:${DEFAULT_RENOWN_NETWORK_ID}:${chainId}:${address.toLowerCase()}`;
|
|
554
|
-
const credentialId = `urn:uuid:${globalThis.crypto.randomUUID()}`;
|
|
555
|
-
const now = /* @__PURE__ */ new Date();
|
|
556
|
-
const expirationDate = new Date(now.getTime() + expiresInDays * 24 * 60 * 60 * 1e3);
|
|
557
|
-
const message = {
|
|
558
|
-
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
|
559
|
-
type: ["VerifiableCredential", "RenownCredential"],
|
|
560
|
-
id: credentialId,
|
|
561
|
-
issuer: {
|
|
562
|
-
id: issuerId,
|
|
563
|
-
ethereumAddress: address
|
|
564
|
-
},
|
|
565
|
-
credentialSubject: {
|
|
566
|
-
id: appId,
|
|
567
|
-
app
|
|
568
|
-
},
|
|
569
|
-
credentialSchema: {
|
|
570
|
-
id: "https://renown.id/schemas/renown-credential/v1",
|
|
571
|
-
type: "JsonSchemaValidator2018"
|
|
572
|
-
},
|
|
573
|
-
issuanceDate: now.toISOString(),
|
|
574
|
-
expirationDate: expirationDate.toISOString()
|
|
575
|
-
};
|
|
576
|
-
const domain = {
|
|
577
|
-
version: "1",
|
|
578
|
-
chainId
|
|
579
|
-
};
|
|
580
|
-
const { EIP712Domain, ...signTypes } = CREDENTIAL_TYPES;
|
|
581
|
-
const signature = await signTypedData({
|
|
582
|
-
domain,
|
|
583
|
-
types: signTypes,
|
|
584
|
-
primaryType: "VerifiableCredential",
|
|
585
|
-
message
|
|
586
|
-
});
|
|
587
|
-
return {
|
|
588
|
-
...message,
|
|
589
|
-
proof: {
|
|
590
|
-
type: "EthereumEip712Signature2021",
|
|
591
|
-
created: message.issuanceDate,
|
|
592
|
-
verificationMethod: issuerId,
|
|
593
|
-
proofPurpose: "assertionMethod",
|
|
594
|
-
proofValue: signature,
|
|
595
|
-
ethereumAddress: address,
|
|
596
|
-
eip712: {
|
|
597
|
-
domain,
|
|
598
|
-
types: CREDENTIAL_TYPES,
|
|
599
|
-
primaryType: "VerifiableCredential"
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
/** Recover the address that signed a credential's EIP-712 proof. */
|
|
605
|
-
async function recoverCredentialSigner(credential) {
|
|
606
|
-
const { proof, ...message } = credential;
|
|
607
|
-
const { EIP712Domain, ...types } = CREDENTIAL_TYPES;
|
|
608
|
-
return recoverTypedDataAddress({
|
|
609
|
-
domain: proof.eip712.domain,
|
|
610
|
-
types,
|
|
611
|
-
primaryType: "VerifiableCredential",
|
|
612
|
-
message,
|
|
613
|
-
signature: proof.proofValue
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
/** True when the proof was signed by the credential's declared issuer address. */
|
|
617
|
-
async function verifyCredentialSignature(credential) {
|
|
618
|
-
try {
|
|
619
|
-
return (await recoverCredentialSigner(credential)).toLowerCase() === credential.issuer.ethereumAddress.toLowerCase();
|
|
620
|
-
} catch {
|
|
621
|
-
return false;
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
//#endregion
|
|
625
|
-
//#region src/common.ts
|
|
626
|
-
var RenownMemoryStorage = class extends MemoryStorage {};
|
|
627
|
-
var Renown = class {
|
|
628
|
-
#baseUrl;
|
|
629
|
-
#store;
|
|
630
|
-
#eventEmitter;
|
|
631
|
-
#appName;
|
|
632
|
-
#crypto;
|
|
633
|
-
#signer;
|
|
634
|
-
#profileFetcher;
|
|
635
|
-
#status = "initial";
|
|
636
|
-
constructor(store, eventEmitter, crypto, appName, baseUrl = DEFAULT_RENOWN_URL, profileFetcher) {
|
|
637
|
-
this.#store = store;
|
|
638
|
-
this.#eventEmitter = eventEmitter;
|
|
639
|
-
this.#baseUrl = baseUrl;
|
|
640
|
-
this.#crypto = crypto;
|
|
641
|
-
this.#appName = appName;
|
|
642
|
-
this.#profileFetcher = profileFetcher;
|
|
643
|
-
this.#signer = new RenownCryptoSigner(crypto, this.#appName, this.user);
|
|
644
|
-
this.on("user", (user) => {
|
|
645
|
-
this.#signer.user = user;
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
get baseUrl() {
|
|
649
|
-
return this.#baseUrl;
|
|
650
|
-
}
|
|
651
|
-
get user() {
|
|
652
|
-
return this.#store.get("user");
|
|
653
|
-
}
|
|
654
|
-
get status() {
|
|
655
|
-
return this.#status;
|
|
656
|
-
}
|
|
657
|
-
get signer() {
|
|
658
|
-
return this.#signer;
|
|
659
|
-
}
|
|
660
|
-
get crypto() {
|
|
661
|
-
return this.#crypto;
|
|
662
|
-
}
|
|
663
|
-
get did() {
|
|
664
|
-
return this.#crypto.did;
|
|
665
|
-
}
|
|
666
|
-
get profileFetcher() {
|
|
667
|
-
return this.#profileFetcher;
|
|
668
|
-
}
|
|
669
|
-
#updateStatus(status) {
|
|
670
|
-
this.#status = status;
|
|
671
|
-
this.#eventEmitter.emit("status", status);
|
|
672
|
-
}
|
|
673
|
-
#updateUser(user) {
|
|
674
|
-
if (user) this.#store.set("user", user);
|
|
675
|
-
else this.#store.delete("user");
|
|
676
|
-
this.#eventEmitter.emit("user", user);
|
|
677
|
-
}
|
|
678
|
-
async login(userDid) {
|
|
679
|
-
this.#updateStatus("checking");
|
|
680
|
-
try {
|
|
681
|
-
const result = parsePkhDid(userDid);
|
|
682
|
-
const credential = await this.#getCredential(result.address, result.chainId, this.#crypto.did);
|
|
683
|
-
if (!credential) {
|
|
684
|
-
this.#updateUser(void 0);
|
|
685
|
-
throw new Error("Credential not found");
|
|
686
|
-
}
|
|
687
|
-
if (!(credential.issuer.id === userDid && credential.credentialSubject.id === this.did)) throw new Error("Invalid credential");
|
|
688
|
-
if (credential.issuer.ethereumAddress.toLowerCase() !== result.address.toLowerCase() || credential.proof.eip712.domain.chainId !== result.chainId || !await verifyCredentialSignature(credential)) throw new Error("Invalid credential signature");
|
|
689
|
-
const user = {
|
|
690
|
-
...result,
|
|
691
|
-
address: credential.issuer.ethereumAddress,
|
|
692
|
-
did: userDid,
|
|
693
|
-
credential
|
|
694
|
-
};
|
|
695
|
-
this.#updateUser(user);
|
|
696
|
-
this.#updateStatus("authorized");
|
|
697
|
-
if (this.#profileFetcher) this.#profileFetcher(user, this.#baseUrl).then((profile) => {
|
|
698
|
-
if (profile && this.user?.address === user.address && this.user.chainId === user.chainId) this.#updateUser({
|
|
699
|
-
...this.user,
|
|
700
|
-
profile,
|
|
701
|
-
ens: {
|
|
702
|
-
name: profile.username ?? void 0,
|
|
703
|
-
avatarUrl: profile.userImage ?? void 0
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
}).catch(console.error);
|
|
707
|
-
return user;
|
|
708
|
-
} catch (error) {
|
|
709
|
-
this.#updateUser(void 0);
|
|
710
|
-
this.#updateStatus("not-authorized");
|
|
711
|
-
throw error;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
logout() {
|
|
715
|
-
this.#updateUser(void 0);
|
|
716
|
-
this.#updateStatus("initial");
|
|
717
|
-
return Promise.resolve();
|
|
718
|
-
}
|
|
719
|
-
on(event, listener) {
|
|
720
|
-
return this.#eventEmitter.on(event, listener);
|
|
721
|
-
}
|
|
722
|
-
async #getCredential(address, chainId, appDid) {
|
|
723
|
-
if (!this.#baseUrl) throw new Error("RENOWN_URL is not set");
|
|
724
|
-
const url = new URL(`/api/auth/credential?address=${encodeURIComponent(address)}&chainId=${encodeURIComponent(chainId)}&connectId=${encodeURIComponent(appDid)}&appId=${encodeURIComponent(appDid)}`, this.#baseUrl);
|
|
725
|
-
const response = await fetch(url, { method: "GET" });
|
|
726
|
-
if (response.ok) return (await response.json()).credential;
|
|
727
|
-
else throw new Error(`Failed to get credential: ${response.status}`);
|
|
728
|
-
}
|
|
729
|
-
async verifyBearerToken(token) {
|
|
730
|
-
return verifyAuthBearerToken(token);
|
|
731
|
-
}
|
|
732
|
-
async getBearerToken(options) {
|
|
733
|
-
if (!this.user) throw new Error("User not found");
|
|
734
|
-
return this.#crypto.getBearerToken(this.user.address, options);
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
//#endregion
|
|
738
|
-
//#region src/event/memory.ts
|
|
739
|
-
var MemoryEventEmitter = class {
|
|
740
|
-
#listeners = /* @__PURE__ */ new Map();
|
|
741
|
-
on(event, listener) {
|
|
742
|
-
if (!this.#listeners.has(event)) this.#listeners.set(event, /* @__PURE__ */ new Set());
|
|
743
|
-
this.#listeners.get(event).add(listener);
|
|
744
|
-
return () => {
|
|
745
|
-
this.#listeners.get(event)?.delete(listener);
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
emit(event, data) {
|
|
749
|
-
this.#listeners.get(event)?.forEach((listener) => listener(data));
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
//#endregion
|
|
753
|
-
//#region src/profile.ts
|
|
754
|
-
const fetchRenownProfile = async (user, baseUrl) => {
|
|
755
|
-
try {
|
|
756
|
-
const response = await fetch(`${baseUrl}/api/profile`, {
|
|
757
|
-
method: "POST",
|
|
758
|
-
headers: { "Content-Type": "application/json" },
|
|
759
|
-
body: JSON.stringify({ ethAddress: user.address })
|
|
760
|
-
});
|
|
761
|
-
if (!response.ok) return;
|
|
762
|
-
return (await response.json()).profile ?? void 0;
|
|
763
|
-
} catch {
|
|
764
|
-
return;
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
//#endregion
|
|
768
|
-
//#region src/renown-builder.ts
|
|
769
|
-
/**
|
|
770
|
-
* Base builder for creating Renown instances.
|
|
771
|
-
* Use platform-specific builders (RenownBuilder from init.browser.js or init.node.js)
|
|
772
|
-
* for pre-configured defaults.
|
|
773
|
-
*/
|
|
774
|
-
var BaseRenownBuilder = class BaseRenownBuilder {
|
|
775
|
-
#appName;
|
|
776
|
-
#storage;
|
|
777
|
-
#eventEmitter;
|
|
778
|
-
#crypto;
|
|
779
|
-
#keyPairStorage;
|
|
780
|
-
#baseUrl;
|
|
781
|
-
#profileFetcher;
|
|
782
|
-
/**
|
|
783
|
-
* @param appName - Application name used for signing context
|
|
784
|
-
*/
|
|
785
|
-
constructor(appName) {
|
|
786
|
-
this.#appName = appName;
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Set custom storage for user data persistence.
|
|
790
|
-
* Defaults to in-memory storage if not set.
|
|
791
|
-
*/
|
|
792
|
-
withStorage(storage) {
|
|
793
|
-
this.#storage = storage;
|
|
794
|
-
return this;
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Set custom event emitter for user state changes.
|
|
798
|
-
* Defaults to in-memory event emitter if not set.
|
|
799
|
-
*/
|
|
800
|
-
withEventEmitter(eventEmitter) {
|
|
801
|
-
this.#eventEmitter = eventEmitter;
|
|
802
|
-
return this;
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* Set a pre-built crypto instance.
|
|
806
|
-
* Either crypto or keyPairStorage must be provided.
|
|
807
|
-
*/
|
|
808
|
-
withCrypto(crypto) {
|
|
809
|
-
this.#crypto = crypto;
|
|
810
|
-
return this;
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Set key pair storage for cryptographic keys.
|
|
814
|
-
* A crypto instance will be built from this storage.
|
|
815
|
-
* Either crypto or keyPairStorage must be provided.
|
|
816
|
-
*/
|
|
817
|
-
withKeyPairStorage(keyPairStorage) {
|
|
818
|
-
this.#keyPairStorage = keyPairStorage;
|
|
819
|
-
return this;
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Set the Renown server URL for credential verification.
|
|
823
|
-
* Defaults to https://www.renown.id
|
|
824
|
-
*/
|
|
825
|
-
withBaseUrl(baseUrl) {
|
|
826
|
-
this.#baseUrl = baseUrl;
|
|
827
|
-
return this;
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Set a profile fetcher strategy for enriching user data after login.
|
|
831
|
-
* The fetcher receives the authenticated user and the base URL,
|
|
832
|
-
* and returns a RenownProfile. Called in the background after each login.
|
|
833
|
-
* Defaults to fetchRenownProfile which calls the Renown API.
|
|
834
|
-
*/
|
|
835
|
-
withProfileFetcher(profileFetcher) {
|
|
836
|
-
this.#profileFetcher = profileFetcher;
|
|
837
|
-
return this;
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* Build and initialize the Renown instance.
|
|
841
|
-
* If a user is stored, attempts to re-authenticate them.
|
|
842
|
-
* @throws Error if neither crypto nor keyPairStorage is provided
|
|
843
|
-
*/
|
|
844
|
-
async build() {
|
|
845
|
-
if (!this.#crypto && !this.#keyPairStorage) throw new Error("Either crypto or keyPairStorage is required. Use withCrypto() or withKeyPairStorage() to set one.");
|
|
846
|
-
const crypto = this.#crypto ?? await new RenownCryptoBuilder().withKeyPairStorage(this.#keyPairStorage).build();
|
|
847
|
-
const storage = this.#storage ?? new RenownMemoryStorage();
|
|
848
|
-
const eventEmitter = this.#eventEmitter ?? new MemoryEventEmitter();
|
|
849
|
-
const baseUrl = this.#baseUrl ?? "https://www.renown.id";
|
|
850
|
-
const renown = new Renown(storage, eventEmitter, crypto, this.#appName, baseUrl, this.#profileFetcher ?? fetchRenownProfile);
|
|
851
|
-
if (renown.user) try {
|
|
852
|
-
await renown.login(renown.user.did);
|
|
853
|
-
} catch (error) {
|
|
854
|
-
console.error("Failed to re-authenticate user:", error);
|
|
855
|
-
}
|
|
856
|
-
return renown;
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Create a BaseRenownBuilder from options object for a more concise API
|
|
860
|
-
*/
|
|
861
|
-
static from(options) {
|
|
862
|
-
const builder = new BaseRenownBuilder(options.appName);
|
|
863
|
-
if (options.storage) builder.withStorage(options.storage);
|
|
864
|
-
if (options.eventEmitter) builder.withEventEmitter(options.eventEmitter);
|
|
865
|
-
if (options.crypto) builder.withCrypto(options.crypto);
|
|
866
|
-
if (options.keyPairStorage) builder.withKeyPairStorage(options.keyPairStorage);
|
|
867
|
-
if (options.baseUrl) builder.withBaseUrl(options.baseUrl);
|
|
868
|
-
if (options.profileFetcher) builder.withProfileFetcher(options.profileFetcher);
|
|
869
|
-
return builder;
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
//#endregion
|
|
873
|
-
export { ISSUER_TYPE as A, CREDENTIAL_SCHEMA_EIP712_TYPE as C, DEFAULT_RENOWN_NETWORK_ID as D, DEFAULT_RENOWN_CHAIN_ID as E, DEFAULT_RENOWN_URL as O, verifyAuthBearerToken as S, CREDENTIAL_TYPES as T, RenownCrypto as _, buildAndSignCredential as a, getResolver$1 as b, BaseStorage as c, extractResultingHashFromSignature as d, parseSignatureHashField as f, ConnectCrypto as g, RenownCryptoBuilder as h, RenownMemoryStorage as i, VERIFIABLE_CREDENTIAL_EIP712_TYPE as j, DOMAIN_TYPE as k, RenownCryptoSigner as l, MemoryKeyStorage as m, fetchRenownProfile as n, recoverCredentialSigner as o, signatureHasResultingHash as p, Renown as r, verifyCredentialSignature as s, BaseRenownBuilder as t, createSignatureVerifier as u, assertIsAuthCredential as v, CREDENTIAL_SUBJECT_TYPE as w, parsePkhDid as x, createAuthBearerToken as y };
|
|
458
|
+
export { signatureHasResultingHash as a, ConnectCrypto as c, createAuthBearerToken as d, getResolver$1 as f, parseSignatureHashField as i, RenownCrypto as l, verifyAuthBearerToken as m, createSignatureVerifier as n, MemoryKeyStorage as o, parsePkhDid as p, extractResultingHashFromSignature as r, RenownCryptoBuilder as s, RenownCryptoSigner as t, assertIsAuthCredential as u };
|
|
874
459
|
|
|
875
|
-
//# sourceMappingURL=
|
|
460
|
+
//# sourceMappingURL=signer-XkA-D7Qt.js.map
|