@idos-network/issuer 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.test.ts +11 -18
- package/src/services/credential.service.ts +19 -12
- package/src/services/user.service.ts +7 -2
package/dist/index.d.mts
CHANGED
|
@@ -8,10 +8,7 @@ import "@idos-network/utils/blob-gateway";
|
|
|
8
8
|
type DelegatedWriteGrantParams = DelegatedWriteGrantBaseParams & {
|
|
9
9
|
signature: string;
|
|
10
10
|
};
|
|
11
|
-
type CredentialByDelegatedWriteGrantBaseParams = Omit<BuildPreliminaryIDOSCredentialArgs, "issuerSigningSecretKey" | "
|
|
12
|
-
originalContentUri?: string;
|
|
13
|
-
copyContentUri?: string;
|
|
14
|
-
};
|
|
11
|
+
type CredentialByDelegatedWriteGrantBaseParams = Omit<BuildPreliminaryIDOSCredentialArgs, "issuerSigningSecretKey" | "broaderMessageFor">;
|
|
15
12
|
//#endregion
|
|
16
13
|
//#region src/services/user.service.d.ts
|
|
17
14
|
type CreateProfileReqParams = Omit<idOSUser$1, "id"> & {
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/services/credential.service.ts","../src/services/user.service.ts","../src/index.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/services/credential.service.ts","../src/services/user.service.ts","../src/index.ts"],"mappings":";;;;;;;KA4BY,4BAA4B;EACtC;;KAGU,4CAA4C,KACtD;;;KCnBU,yBAAyB,KAAK;EACxC;;KAGU,wBAAwB,KAAK;EACvC;;KAGU,wBAAwB,KAAK;EACvC;;;;KCYG;EACH;EACA;EACA;EACA,gBAAgB;;qBAGL;;SAIE,KAAK,QAAQ,qBAAqB,QAAQ;UAqB/C;EAMR,WAAiB,sBAAsB;EAIvC,kBAAwB,QAAQ,yBAAyB,QAAQ;EAIjE,uBAA6B,QAAQ,wBAAwB,QAAQ;EAIrE,iBAAuB,QAAQ,wBAAwB;EAIvD,WACE,MAAM,wBACN,QAAQ,wBACP,SAAS,UAAU;EAItB,QAAc,aAAa,QAAQ;EAInC,kCAAwC,QAAQ,0BAA0B;EAI1E,sCACE,kBAAkB,2CAClB,qBAAqB,2BACrB,6BAA6B,aAC5B;IACD,oBAAoB,KAAK;IACzB,gBAAgB,KAAK;;EASvB,uBACE,uBACA,sBACC,QAAQ;EAIX,6BAAmC,sBAAsB;EAIzD,oBAA0B,aAAa,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createKgwAuthenticatedBlobGateway as e,createNodeKwilClient as t,createServerKwilSigner as n}from"@idos-network/kwil-infra";import{buildPreliminaryIDOSCredential as r,mapPreliminaryToIDOSCredential as i}from"@idos-network/credentials/utils";import{addUserAsInserter as a,addWalletMessage as o,createPreliminaryCredentialsByDwg as s,
|
|
1
|
+
import{createKgwAuthenticatedBlobGateway as e,createNodeKwilClient as t,createServerKwilSigner as n}from"@idos-network/kwil-infra";import{buildPreliminaryIDOSCredential as r,mapPreliminaryToIDOSCredential as i}from"@idos-network/credentials/utils";import{addUserAsInserter as a,addWalletMessage as o,createPreliminaryCredentialsByDwg as s,credentialBroaderMessage as c,dwgMessage as l,editPublicNotesAsIssuer as u,getCredentialShared as d,getSiblingCredentialId as f,getUserAsInserter as p,hasProfile as m,toDelegatedWriteGrantBaseParams as h,upsertWalletAsInserter as g}from"@idos-network/kwil-infra/actions";import{hexEncodeSha256Hash as _}from"@idos-network/utils/codecs";var v=process.env.NODE_ENV===`production`,y=`Invariant failed`;function b(e,t){if(!e){if(v)throw Error(y);var n=typeof t==`function`?t():t,r=n?`${y}: ${n}`:y;throw Error(r)}}var x=class{#e;#t;#n;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}async requestDelegatedWriteGrantMessage(e){return l(this.#e,e).then(e=>{if(!e)throw Error(`dwg_message returned no rows`);return e.message})}async createCredentialByDelegatedWriteGrant(e,t,n){let a=(e,n)=>c(this.#e,{public_notes_signature:e,content_uri:n,recipient_wallet:t.ownerWalletIdentifier}).then(e=>e.message),o={...await r({...e,broaderMessageFor:a,issuerSigningSecretKey:this.#t.secretKey}),id:crypto.randomUUID()},l=_(e.plaintextContent),u={...await r({...e,publicNotes:``,recipientEncryptionPublicKey:n,broaderMessageFor:a,issuerSigningSecretKey:this.#t.secretKey}),id:crypto.randomUUID()};b(o.contentUri!==u.contentUri,`Original and copy credentials must use distinct content URIs`);let d=crypto.randomUUID(),f={request_id:d,issuer_auth_public_key:o.issuerAuthPublicKey,original_encryptor_public_key:o.encryptorPublicKey,original_id:o.id,original_content_uri:o.contentUri,original_content_size:o.contentSize,original_public_notes:o.publicNotes,original_public_notes_signature:o.publicNotesSignature,original_broader_signature:o.broaderSignature,copy_encryptor_public_key:u.encryptorPublicKey,copy_id:u.id,copy_content_uri:u.contentUri,copy_content_size:u.contentSize,copy_public_notes_signature:u.publicNotesSignature,copy_broader_signature:u.broaderSignature,content_hash:l,dwg_owner:t.ownerWalletIdentifier,dwg_grantee:t.consumerWalletIdentifier,dwg_issuer_public_key:t.issuerPublicKey,dwg_id:t.id,dwg_access_grant_timelock:t.accessGrantTimelock,dwg_not_before:t.notUsableBefore,dwg_not_after:t.notUsableAfter,dwg_signature:t.signature};return await s(this.#e,f),await this.#n.uploadCredentialBlobs({requestId:d,credentialIds:[o.id,u.id],original:o.encryptedContent,copy:u.encryptedContent}),{originalCredential:i(o),copyCredential:i(u)}}async editCredentialAsIssuer(e,t){let n={public_notes_id:e,public_notes:t};return await u(this.#e,n),n}async getCredentialIdByContentHash(e){let t=await f(this.#e,{content_hash:e}).then(e=>e?.id);return b(t,"Required `idOSCredential` id not found"),t}async getCredentialShared(e){return await d(this.#e,{id:e}).then(e=>e[0])??null}},S=class{#e;constructor(e){this.#e=e}#t(e){return e.id||=crypto.randomUUID(),e}async hasProfile(e){return m(this.#e,{address:e}).then(e=>{if(!e)throw Error(`has_profile returned no rows`);return e.has_profile})}async createUserProfile(e){let t=this.#t(e);return await a(this.#e,t),t}async upsertWalletAsInserter(e){let t=this.#t(e);return await g(this.#e,t),t}async addWalletMessage(e){return(await o(this.#e,e)).message}async getUser(e){let t=await p(this.#e,this.#t(e));if(!t)throw Error(`get_user_as_inserter returned no rows`);return t}async createUser(e,t){let n=e.id??crypto.randomUUID(),r=t.id??crypto.randomUUID(),i={...e,id:n},a=await this.createUserProfile(i),o={...t,user_id:n,id:r};return[a,await this.upsertWalletAsInserter(o)]}},C=class r{#e;#t;static async init(i){let a=await t({nodeUrl:i.nodeUrl,chainId:i.chainId}),[o]=await n(i.signingKeyPair);a.setSigner(o);let s=e({url:i.blobGatewayUrl??i.nodeUrl,kwilClient:a,signer:o}),c=new x(a,i.signingKeyPair,s),l=new S(a);return new r(c,l)}constructor(e,t){this.#e=e,this.#t=t}async hasProfile(e){return this.#t.hasProfile(e)}async createUserProfile(e){return this.#t.createUserProfile(e)}async upsertWalletAsInserter(e){return this.#t.upsertWalletAsInserter(e)}async addWalletMessage(e){return this.#t.addWalletMessage(e)}async createUser(e,t){return this.#t.createUser(e,t)}async getUser(e){return this.#t.getUser({id:e})}async requestDelegatedWriteGrantMessage(e){return this.#e.requestDelegatedWriteGrantMessage(e)}async createCredentialByDelegatedWriteGrant(e,t,n){return this.#e.createCredentialByDelegatedWriteGrant(e,t,n)}async editCredentialAsIssuer(e,t){return this.#e.editCredentialAsIssuer(e,t)}async getCredentialIdByContentHash(e){return this.#e.getCredentialIdByContentHash(e)}async getCredentialShared(e){return this.#e.getCredentialShared(e)}};export{C as idOSIssuer,h as toDelegatedWriteGrantBaseParams};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["_hasProfile","_upsertWalletAsInserter","_addWalletMessage"],"sources":["../../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js","../src/services/credential.service.ts","../src/services/user.service.ts","../src/index.ts"],"sourcesContent":["var isProduction = process.env.NODE_ENV === 'production';\nvar prefix = 'Invariant failed';\nfunction invariant(condition, message) {\n if (condition) {\n return;\n }\n if (isProduction) {\n throw new Error(prefix);\n }\n var provided = typeof message === 'function' ? message() : message;\n var value = provided ? \"\".concat(prefix, \": \").concat(provided) : prefix;\n throw new Error(value);\n}\n\nexport { invariant as default };\n","import type { idOSCredential, idOSCredentialRecord } from \"@idos-network/credentials/types\";\nimport type { KwilActionClient } from \"@idos-network/kwil-infra\";\n\nimport {\n buildPreliminaryIDOSCredential,\n BuildPreliminaryIDOSCredentialArgs,\n mapPreliminaryToIDOSCredential,\n PreliminaryIDOSCredential,\n} from \"@idos-network/credentials/utils\";\nimport {\n type CreatePreliminaryCredentialsByDwgInput,\n createPreliminaryCredentialsByDwg,\n dwgMessage,\n type EditPublicNotesAsIssuerInput,\n editPublicNotesAsIssuer,\n getCredentialShared,\n getSiblingCredentialId,\n type idOSDelegatedWriteGrant,\n type DelegatedWriteGrantBaseParams,\n} from \"@idos-network/kwil-infra/actions\";\nimport { BlobGateway } from \"@idos-network/utils/blob-gateway\";\nimport { hexEncodeSha256Hash } from \"@idos-network/utils/codecs\";\nimport invariant from \"tiny-invariant\";\nimport nacl from \"tweetnacl\";\n\nexport type { DelegatedWriteGrantBaseParams };\n\nexport type DelegatedWriteGrantParams = DelegatedWriteGrantBaseParams & {\n signature: string;\n};\n\nexport type CredentialByDelegatedWriteGrantBaseParams = Omit<\n BuildPreliminaryIDOSCredentialArgs,\n \"issuerSigningSecretKey\" | \"contentUri\"\n> & {\n originalContentUri?: string;\n copyContentUri?: string;\n};\n\nexport class CredentialService {\n readonly #kwilClient: KwilActionClient;\n readonly #signingKeyPair: nacl.SignKeyPair;\n readonly #blobGateway: BlobGateway;\n\n constructor(\n kwilClient: KwilActionClient,\n signingKeyPair: nacl.SignKeyPair,\n blobGateway: BlobGateway,\n ) {\n this.#kwilClient = kwilClient;\n this.#signingKeyPair = signingKeyPair;\n this.#blobGateway = blobGateway;\n }\n\n async requestDelegatedWriteGrantMessage(params: idOSDelegatedWriteGrant): Promise<string> {\n return dwgMessage(this.#kwilClient, params).then((res) => res.message);\n }\n\n async createCredentialByDelegatedWriteGrant(\n credentialParams: CredentialByDelegatedWriteGrantBaseParams,\n delegatedWriteGrant: DelegatedWriteGrantParams,\n consumerEncryptionPublicKey: Uint8Array,\n ): Promise<{\n originalCredential: Omit<idOSCredential, \"user_id\">;\n copyCredential: Omit<idOSCredential, \"user_id\">;\n }> {\n const { originalContentUri, copyContentUri, ...sharedCredentialParams } = credentialParams;\n const originalCredential: PreliminaryIDOSCredential = {\n ...(await buildPreliminaryIDOSCredential({\n ...sharedCredentialParams,\n contentUri: originalContentUri,\n issuerSigningSecretKey: this.#signingKeyPair.secretKey,\n })),\n id: crypto.randomUUID(),\n };\n\n const contentHash = hexEncodeSha256Hash(credentialParams.plaintextContent);\n\n const copyCredential: PreliminaryIDOSCredential = {\n ...(await buildPreliminaryIDOSCredential({\n ...sharedCredentialParams,\n contentUri: copyContentUri,\n publicNotes: \"\",\n recipientEncryptionPublicKey: consumerEncryptionPublicKey,\n issuerSigningSecretKey: this.#signingKeyPair.secretKey,\n })),\n id: crypto.randomUUID(),\n };\n\n invariant(\n originalCredential.contentUri !== copyCredential.contentUri,\n \"Original and copy credentials must use distinct content URIs\",\n );\n\n const requestId = crypto.randomUUID();\n const payload: CreatePreliminaryCredentialsByDwgInput = {\n request_id: requestId,\n issuer_auth_public_key: originalCredential.issuerAuthPublicKey,\n original_encryptor_public_key: originalCredential.encryptorPublicKey,\n original_id: originalCredential.id,\n original_content_uri: originalCredential.contentUri,\n original_content_size: originalCredential.contentSize,\n original_public_notes: originalCredential.publicNotes,\n original_public_notes_signature: originalCredential.publicNotesSignature,\n original_broader_signature: originalCredential.broaderSignature,\n copy_encryptor_public_key: copyCredential.encryptorPublicKey,\n copy_id: copyCredential.id,\n copy_content_uri: copyCredential.contentUri,\n copy_content_size: copyCredential.contentSize,\n copy_public_notes_signature: copyCredential.publicNotesSignature,\n copy_broader_signature: copyCredential.broaderSignature,\n content_hash: contentHash,\n dwg_owner: delegatedWriteGrant.ownerWalletIdentifier,\n dwg_grantee: delegatedWriteGrant.consumerWalletIdentifier,\n dwg_issuer_public_key: delegatedWriteGrant.issuerPublicKey,\n dwg_id: delegatedWriteGrant.id,\n dwg_access_grant_timelock: delegatedWriteGrant.accessGrantTimelock,\n dwg_not_before: delegatedWriteGrant.notUsableBefore,\n dwg_not_after: delegatedWriteGrant.notUsableAfter,\n dwg_signature: delegatedWriteGrant.signature,\n };\n\n await createPreliminaryCredentialsByDwg(this.#kwilClient, payload);\n\n await this.#blobGateway.uploadCredentialBlobs({\n requestId,\n original: originalCredential.encryptedContent,\n copy: copyCredential.encryptedContent,\n });\n\n return {\n originalCredential: mapPreliminaryToIDOSCredential(originalCredential),\n copyCredential: mapPreliminaryToIDOSCredential(copyCredential),\n };\n }\n\n async editCredentialAsIssuer(\n publicNotesId: string,\n publicNotes: string,\n ): Promise<EditPublicNotesAsIssuerInput | null> {\n const payload = {\n public_notes_id: publicNotesId,\n public_notes: publicNotes,\n };\n\n await editPublicNotesAsIssuer(this.#kwilClient, payload);\n\n return payload;\n }\n\n async getCredentialIdByContentHash(contentHash: string): Promise<string | null> {\n const id = await getSiblingCredentialId(this.#kwilClient, { content_hash: contentHash }).then(\n (res) => res.id,\n );\n\n invariant(id, \"Required `idOSCredential` id not found\");\n\n return id;\n }\n\n async getCredentialShared(id: string): Promise<idOSCredentialRecord | null> {\n const result = await getCredentialShared(this.#kwilClient, { id }).then((res) => res[0]);\n\n return result ?? null;\n }\n}\n","import type { KwilActionClient } from \"@idos-network/kwil-infra\";\n\nimport {\n hasProfile as _hasProfile,\n upsertWalletAsInserter as _upsertWalletAsInserter,\n addUserAsInserter,\n addWalletMessage as _addWalletMessage,\n type AddWalletMessageInput,\n type GetUserAsInserterInput,\n getUserAsInserter,\n type idOSUser,\n type idOSWallet,\n} from \"@idos-network/kwil-infra/actions\";\n\nexport type CreateProfileReqParams = Omit<idOSUser, \"id\"> & {\n id?: string;\n};\n\nexport type UpsertWalletReqParams = Omit<idOSWallet, \"id\"> & {\n id?: string;\n};\n\nexport type CreateWalletReqParams = Omit<UpsertWalletReqParams, \"user_id\"> & {\n id?: string;\n};\n\nexport class UserService {\n readonly #kwilClient: KwilActionClient;\n\n constructor(kwilClient: KwilActionClient) {\n this.#kwilClient = kwilClient;\n }\n\n #ensureEntityId<T extends { id?: string }>(entity: T): T & { id: string } {\n if (!entity.id) {\n (entity as T & { id: string }).id = crypto.randomUUID();\n }\n return entity as T & { id: string };\n }\n\n async hasProfile(address: string): Promise<boolean> {\n return _hasProfile(this.#kwilClient, { address }).then((res) => res.has_profile);\n }\n\n async createUserProfile(params: CreateProfileReqParams): Promise<idOSUser> {\n const payload = this.#ensureEntityId(params);\n await addUserAsInserter(this.#kwilClient, payload);\n return payload;\n }\n\n async upsertWalletAsInserter(params: UpsertWalletReqParams): Promise<idOSWallet> {\n const payload = this.#ensureEntityId(params);\n await _upsertWalletAsInserter(this.#kwilClient, payload);\n return payload;\n }\n\n async addWalletMessage(params: AddWalletMessageInput): Promise<string> {\n const result = await _addWalletMessage(this.#kwilClient, params);\n return result.message;\n }\n\n /// Useful to understand if a user id already exists.\n async getUser(params: GetUserAsInserterInput): Promise<idOSUser> {\n return getUserAsInserter(this.#kwilClient, this.#ensureEntityId(params));\n }\n\n async createUser(\n user: CreateProfileReqParams,\n wallet: CreateWalletReqParams,\n ): Promise<[idOSUser, idOSWallet]> {\n const user_id = user.id ?? crypto.randomUUID();\n const wallet_id = wallet.id ?? crypto.randomUUID();\n\n const userReqParams = {\n ...user,\n id: user_id,\n };\n\n const userResponse = await this.createUserProfile(userReqParams);\n\n const walletReqParams = {\n ...wallet,\n user_id,\n id: wallet_id,\n };\n\n const walletResponse = await this.upsertWalletAsInserter(walletReqParams);\n\n return [userResponse, walletResponse];\n }\n}\n","import type {\n AvailableIssuerType,\n idOSCredential,\n idOSCredentialRecord,\n} from \"@idos-network/credentials/types\";\nimport type {\n AddWalletMessageInput,\n EditPublicNotesAsIssuerInput,\n idOSDelegatedWriteGrant,\n idOSGrant,\n idOSUser,\n idOSUserAttribute,\n idOSWallet,\n} from \"@idos-network/kwil-infra/actions\";\nimport type { SignKeyPair } from \"tweetnacl\";\n\nimport {\n createKgwAuthenticatedBlobGateway,\n createNodeKwilClient,\n createServerKwilSigner,\n} from \"@idos-network/kwil-infra\";\n\nimport {\n CredentialService,\n type CredentialByDelegatedWriteGrantBaseParams,\n type DelegatedWriteGrantBaseParams,\n type DelegatedWriteGrantParams,\n} from \"./services/credential.service\";\nimport {\n type CreateProfileReqParams,\n type CreateWalletReqParams,\n type UpsertWalletReqParams,\n UserService,\n} from \"./services/user.service\";\n\ntype CreateIssuerParams = {\n chainId?: string;\n nodeUrl: string;\n blobGatewayUrl?: string;\n signingKeyPair: SignKeyPair;\n};\n\nexport class idOSIssuer {\n readonly #credentialService: CredentialService;\n readonly #userService: UserService;\n\n static async init(params: CreateIssuerParams): Promise<idOSIssuer> {\n const kwilClient = await createNodeKwilClient({\n nodeUrl: params.nodeUrl,\n chainId: params.chainId,\n });\n\n const [signer] = await createServerKwilSigner(params.signingKeyPair);\n kwilClient.setSigner(signer);\n\n const blobGateway = createKgwAuthenticatedBlobGateway({\n url: params.blobGatewayUrl ?? params.nodeUrl,\n kwilClient,\n signer,\n });\n\n const credentialService = new CredentialService(kwilClient, params.signingKeyPair, blobGateway);\n const userService = new UserService(kwilClient);\n\n return new idOSIssuer(credentialService, userService);\n }\n\n private constructor(credentialService: CredentialService, userService: UserService) {\n this.#credentialService = credentialService;\n this.#userService = userService;\n }\n\n // User Service facade methods\n async hasProfile(userAddress: string): Promise<boolean> {\n return this.#userService.hasProfile(userAddress);\n }\n\n async createUserProfile(params: CreateProfileReqParams): Promise<idOSUser> {\n return this.#userService.createUserProfile(params);\n }\n\n async upsertWalletAsInserter(params: UpsertWalletReqParams): Promise<idOSWallet> {\n return this.#userService.upsertWalletAsInserter(params);\n }\n\n async addWalletMessage(params: AddWalletMessageInput): Promise<string> {\n return this.#userService.addWalletMessage(params);\n }\n\n async createUser(\n user: CreateProfileReqParams,\n wallet: CreateWalletReqParams,\n ): Promise<[idOSUser, idOSWallet]> {\n return this.#userService.createUser(user, wallet);\n }\n\n async getUser(id: string): Promise<idOSUser> {\n return this.#userService.getUser({ id });\n }\n\n async requestDelegatedWriteGrantMessage(params: idOSDelegatedWriteGrant): Promise<string> {\n return this.#credentialService.requestDelegatedWriteGrantMessage(params);\n }\n\n async createCredentialByDelegatedWriteGrant(\n credentialParams: CredentialByDelegatedWriteGrantBaseParams,\n delegatedWriteGrant: DelegatedWriteGrantParams,\n consumerEncryptionPublicKey: Uint8Array,\n ): Promise<{\n originalCredential: Omit<idOSCredential, \"user_id\">;\n copyCredential: Omit<idOSCredential, \"user_id\">;\n }> {\n return this.#credentialService.createCredentialByDelegatedWriteGrant(\n credentialParams,\n delegatedWriteGrant,\n consumerEncryptionPublicKey,\n );\n }\n\n async editCredentialAsIssuer(\n publicNotesId: string,\n publicNotes: string,\n ): Promise<EditPublicNotesAsIssuerInput | null> {\n return this.#credentialService.editCredentialAsIssuer(publicNotesId, publicNotes);\n }\n\n async getCredentialIdByContentHash(contentHash: string): Promise<string | null> {\n return this.#credentialService.getCredentialIdByContentHash(contentHash);\n }\n\n async getCredentialShared(id: string): Promise<idOSCredentialRecord | null> {\n return this.#credentialService.getCredentialShared(id);\n }\n}\n\nexport type {\n idOSCredential,\n idOSGrant,\n idOSUser,\n idOSUserAttribute,\n idOSDelegatedWriteGrant,\n idOSWallet,\n AvailableIssuerType,\n CredentialByDelegatedWriteGrantBaseParams,\n DelegatedWriteGrantBaseParams,\n DelegatedWriteGrantParams,\n};\n\nexport { toDelegatedWriteGrantBaseParams } from \"@idos-network/kwil-infra/actions\";\n"],"x_google_ignoreList":[0],"mappings":"qoBAAA,IAAI,EAAe,QAAQ,IAAI,WAAa,aACxC,EAAS,mBACb,SAAS,EAAU,EAAW,EAAS,CAC/B,MAGJ,IAAI,EACA,MAAU,MAAM,CAAM,EAE1B,IAAI,EAAW,OAAO,GAAY,WAAa,EAAQ,EAAI,EACvD,EAAQ,EAAW,GAAU,MAAqB,IAAY,EAClE,MAAU,MAAM,CAAK,CAJK,CAK9B,CC2BA,IAAa,EAAb,KAA+B,CAC7B,GACA,GACA,GAEA,YACE,EACA,EACA,EACA,CACA,KAAK,GAAc,EACnB,KAAK,GAAkB,EACvB,KAAK,GAAe,CACtB,CAEA,MAAM,kCAAkC,EAAkD,CACxF,OAAO,EAAW,KAAK,GAAa,CAAM,CAAC,CAAC,KAAM,GAAQ,EAAI,OAAO,CACvE,CAEA,MAAM,sCACJ,EACA,EACA,EAIC,CACD,GAAM,CAAE,qBAAoB,iBAAgB,GAAG,GAA2B,EACpE,EAAgD,CACpD,GAAI,MAAM,EAA+B,CACvC,GAAG,EACH,WAAY,EACZ,uBAAwB,KAAK,GAAgB,SAC/C,CAAC,EACD,GAAI,OAAO,WAAW,CACxB,EAEM,EAAc,EAAoB,EAAiB,gBAAgB,EAEnE,EAA4C,CAChD,GAAI,MAAM,EAA+B,CACvC,GAAG,EACH,WAAY,EACZ,YAAa,GACb,6BAA8B,EAC9B,uBAAwB,KAAK,GAAgB,SAC/C,CAAC,EACD,GAAI,OAAO,WAAW,CACxB,EAEA,EACE,EAAmB,aAAe,EAAe,WACjD,8DACF,EAEA,IAAM,EAAY,OAAO,WAAW,EAC9B,EAAkD,CACtD,WAAY,EACZ,uBAAwB,EAAmB,oBAC3C,8BAA+B,EAAmB,mBAClD,YAAa,EAAmB,GAChC,qBAAsB,EAAmB,WACzC,sBAAuB,EAAmB,YAC1C,sBAAuB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,CAClF,KAAK,GAAqB,EAC1B,KAAK,GAAe,CACtB,CAGA,MAAM,WAAW,EAAuC,CACtD,OAAO,KAAK,GAAa,WAAW,CAAW,CACjD,CAEA,MAAM,kBAAkB,EAAmD,CACzE,OAAO,KAAK,GAAa,kBAAkB,CAAM,CACnD,CAEA,MAAM,uBAAuB,EAAoD,CAC/E,OAAO,KAAK,GAAa,uBAAuB,CAAM,CACxD,CAEA,MAAM,iBAAiB,EAAgD,CACrE,OAAO,KAAK,GAAa,iBAAiB,CAAM,CAClD,CAEA,MAAM,WACJ,EACA,EACiC,CACjC,OAAO,KAAK,GAAa,WAAW,EAAM,CAAM,CAClD,CAEA,MAAM,QAAQ,EAA+B,CAC3C,OAAO,KAAK,GAAa,QAAQ,CAAE,IAAG,CAAC,CACzC,CAEA,MAAM,kCAAkC,EAAkD,CACxF,OAAO,KAAK,GAAmB,kCAAkC,CAAM,CACzE,CAEA,MAAM,sCACJ,EACA,EACA,EAIC,CACD,OAAO,KAAK,GAAmB,sCAC7B,EACA,EACA,CACF,CACF,CAEA,MAAM,uBACJ,EACA,EAC8C,CAC9C,OAAO,KAAK,GAAmB,uBAAuB,EAAe,CAAW,CAClF,CAEA,MAAM,6BAA6B,EAA6C,CAC9E,OAAO,KAAK,GAAmB,6BAA6B,CAAW,CACzE,CAEA,MAAM,oBAAoB,EAAkD,CAC1E,OAAO,KAAK,GAAmB,oBAAoB,CAAE,CACvD,CACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["_hasProfile","_upsertWalletAsInserter","_addWalletMessage"],"sources":["../../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js","../src/services/credential.service.ts","../src/services/user.service.ts","../src/index.ts"],"sourcesContent":["var isProduction = process.env.NODE_ENV === 'production';\nvar prefix = 'Invariant failed';\nfunction invariant(condition, message) {\n if (condition) {\n return;\n }\n if (isProduction) {\n throw new Error(prefix);\n }\n var provided = typeof message === 'function' ? message() : message;\n var value = provided ? \"\".concat(prefix, \": \").concat(provided) : prefix;\n throw new Error(value);\n}\n\nexport { invariant as default };\n","import type { idOSCredential, idOSCredentialRecord } from \"@idos-network/credentials/types\";\nimport type { KwilActionClient } from \"@idos-network/kwil-infra\";\n\nimport {\n buildPreliminaryIDOSCredential,\n BuildPreliminaryIDOSCredentialArgs,\n mapPreliminaryToIDOSCredential,\n PreliminaryIDOSCredential,\n} from \"@idos-network/credentials/utils\";\nimport {\n type CreatePreliminaryCredentialsByDwgInput,\n createPreliminaryCredentialsByDwg,\n credentialBroaderMessage,\n dwgMessage,\n type EditPublicNotesAsIssuerInput,\n editPublicNotesAsIssuer,\n getCredentialShared,\n getSiblingCredentialId,\n type idOSDelegatedWriteGrant,\n type DelegatedWriteGrantBaseParams,\n} from \"@idos-network/kwil-infra/actions\";\nimport { BlobGateway } from \"@idos-network/utils/blob-gateway\";\nimport { hexEncodeSha256Hash } from \"@idos-network/utils/codecs\";\nimport invariant from \"tiny-invariant\";\nimport nacl from \"tweetnacl\";\n\nexport type { DelegatedWriteGrantBaseParams };\n\nexport type DelegatedWriteGrantParams = DelegatedWriteGrantBaseParams & {\n signature: string;\n};\n\nexport type CredentialByDelegatedWriteGrantBaseParams = Omit<\n BuildPreliminaryIDOSCredentialArgs,\n \"issuerSigningSecretKey\" | \"broaderMessageFor\"\n>;\n\nexport class CredentialService {\n readonly #kwilClient: KwilActionClient;\n readonly #signingKeyPair: nacl.SignKeyPair;\n readonly #blobGateway: BlobGateway;\n\n constructor(\n kwilClient: KwilActionClient,\n signingKeyPair: nacl.SignKeyPair,\n blobGateway: BlobGateway,\n ) {\n this.#kwilClient = kwilClient;\n this.#signingKeyPair = signingKeyPair;\n this.#blobGateway = blobGateway;\n }\n\n async requestDelegatedWriteGrantMessage(params: idOSDelegatedWriteGrant): Promise<string> {\n return dwgMessage(this.#kwilClient, params).then((res) => {\n if (!res) throw new Error(\"dwg_message returned no rows\");\n return res.message;\n });\n }\n\n async createCredentialByDelegatedWriteGrant(\n credentialParams: CredentialByDelegatedWriteGrantBaseParams,\n delegatedWriteGrant: DelegatedWriteGrantParams,\n consumerEncryptionPublicKey: Uint8Array,\n ): Promise<{\n originalCredential: Omit<idOSCredential, \"user_id\">;\n copyCredential: Omit<idOSCredential, \"user_id\">;\n }> {\n const broaderMessageFor = (publicNotesSignature: string, contentUri: string) =>\n credentialBroaderMessage(this.#kwilClient, {\n public_notes_signature: publicNotesSignature,\n content_uri: contentUri,\n recipient_wallet: delegatedWriteGrant.ownerWalletIdentifier,\n }).then((row) => row.message);\n const originalCredential: PreliminaryIDOSCredential = {\n ...(await buildPreliminaryIDOSCredential({\n ...credentialParams,\n broaderMessageFor,\n issuerSigningSecretKey: this.#signingKeyPair.secretKey,\n })),\n id: crypto.randomUUID(),\n };\n\n const contentHash = hexEncodeSha256Hash(credentialParams.plaintextContent);\n\n const copyCredential: PreliminaryIDOSCredential = {\n ...(await buildPreliminaryIDOSCredential({\n ...credentialParams,\n publicNotes: \"\",\n recipientEncryptionPublicKey: consumerEncryptionPublicKey,\n broaderMessageFor,\n issuerSigningSecretKey: this.#signingKeyPair.secretKey,\n })),\n id: crypto.randomUUID(),\n };\n\n invariant(\n originalCredential.contentUri !== copyCredential.contentUri,\n \"Original and copy credentials must use distinct content URIs\",\n );\n\n const requestId = crypto.randomUUID();\n const payload: CreatePreliminaryCredentialsByDwgInput = {\n request_id: requestId,\n issuer_auth_public_key: originalCredential.issuerAuthPublicKey,\n original_encryptor_public_key: originalCredential.encryptorPublicKey,\n original_id: originalCredential.id,\n original_content_uri: originalCredential.contentUri,\n original_content_size: originalCredential.contentSize,\n original_public_notes: originalCredential.publicNotes,\n original_public_notes_signature: originalCredential.publicNotesSignature,\n original_broader_signature: originalCredential.broaderSignature,\n copy_encryptor_public_key: copyCredential.encryptorPublicKey,\n copy_id: copyCredential.id,\n copy_content_uri: copyCredential.contentUri,\n copy_content_size: copyCredential.contentSize,\n copy_public_notes_signature: copyCredential.publicNotesSignature,\n copy_broader_signature: copyCredential.broaderSignature,\n content_hash: contentHash,\n dwg_owner: delegatedWriteGrant.ownerWalletIdentifier,\n dwg_grantee: delegatedWriteGrant.consumerWalletIdentifier,\n dwg_issuer_public_key: delegatedWriteGrant.issuerPublicKey,\n dwg_id: delegatedWriteGrant.id,\n dwg_access_grant_timelock: delegatedWriteGrant.accessGrantTimelock,\n dwg_not_before: delegatedWriteGrant.notUsableBefore,\n dwg_not_after: delegatedWriteGrant.notUsableAfter,\n dwg_signature: delegatedWriteGrant.signature,\n };\n\n await createPreliminaryCredentialsByDwg(this.#kwilClient, payload);\n\n await this.#blobGateway.uploadCredentialBlobs({\n requestId,\n credentialIds: [originalCredential.id, copyCredential.id],\n original: originalCredential.encryptedContent,\n copy: copyCredential.encryptedContent,\n });\n\n return {\n originalCredential: mapPreliminaryToIDOSCredential(originalCredential),\n copyCredential: mapPreliminaryToIDOSCredential(copyCredential),\n };\n }\n\n async editCredentialAsIssuer(\n publicNotesId: string,\n publicNotes: string,\n ): Promise<EditPublicNotesAsIssuerInput | null> {\n const payload = {\n public_notes_id: publicNotesId,\n public_notes: publicNotes,\n };\n\n await editPublicNotesAsIssuer(this.#kwilClient, payload);\n\n return payload;\n }\n\n async getCredentialIdByContentHash(contentHash: string): Promise<string | null> {\n const id = await getSiblingCredentialId(this.#kwilClient, { content_hash: contentHash }).then(\n (res) => res?.id,\n );\n\n invariant(id, \"Required `idOSCredential` id not found\");\n\n return id;\n }\n\n async getCredentialShared(id: string): Promise<idOSCredentialRecord | null> {\n const result = await getCredentialShared(this.#kwilClient, { id }).then((res) => res[0]);\n\n return result ?? null;\n }\n}\n","import type { KwilActionClient } from \"@idos-network/kwil-infra\";\n\nimport {\n hasProfile as _hasProfile,\n upsertWalletAsInserter as _upsertWalletAsInserter,\n addUserAsInserter,\n addWalletMessage as _addWalletMessage,\n type AddWalletMessageInput,\n type GetUserAsInserterInput,\n getUserAsInserter,\n type idOSUser,\n type idOSWallet,\n} from \"@idos-network/kwil-infra/actions\";\n\nexport type CreateProfileReqParams = Omit<idOSUser, \"id\"> & {\n id?: string;\n};\n\nexport type UpsertWalletReqParams = Omit<idOSWallet, \"id\"> & {\n id?: string;\n};\n\nexport type CreateWalletReqParams = Omit<UpsertWalletReqParams, \"user_id\"> & {\n id?: string;\n};\n\nexport class UserService {\n readonly #kwilClient: KwilActionClient;\n\n constructor(kwilClient: KwilActionClient) {\n this.#kwilClient = kwilClient;\n }\n\n #ensureEntityId<T extends { id?: string }>(entity: T): T & { id: string } {\n if (!entity.id) {\n (entity as T & { id: string }).id = crypto.randomUUID();\n }\n return entity as T & { id: string };\n }\n\n async hasProfile(address: string): Promise<boolean> {\n return _hasProfile(this.#kwilClient, { address }).then((res) => {\n if (!res) throw new Error(\"has_profile returned no rows\");\n return res.has_profile;\n });\n }\n\n async createUserProfile(params: CreateProfileReqParams): Promise<idOSUser> {\n const payload = this.#ensureEntityId(params);\n await addUserAsInserter(this.#kwilClient, payload);\n return payload;\n }\n\n async upsertWalletAsInserter(params: UpsertWalletReqParams): Promise<idOSWallet> {\n const payload = this.#ensureEntityId(params);\n await _upsertWalletAsInserter(this.#kwilClient, payload);\n return payload;\n }\n\n async addWalletMessage(params: AddWalletMessageInput): Promise<string> {\n const result = await _addWalletMessage(this.#kwilClient, params);\n return result.message;\n }\n\n /// Useful to understand if a user id already exists.\n async getUser(params: GetUserAsInserterInput): Promise<idOSUser> {\n const user = await getUserAsInserter(this.#kwilClient, this.#ensureEntityId(params));\n if (!user) throw new Error(\"get_user_as_inserter returned no rows\");\n return user;\n }\n\n async createUser(\n user: CreateProfileReqParams,\n wallet: CreateWalletReqParams,\n ): Promise<[idOSUser, idOSWallet]> {\n const user_id = user.id ?? crypto.randomUUID();\n const wallet_id = wallet.id ?? crypto.randomUUID();\n\n const userReqParams = {\n ...user,\n id: user_id,\n };\n\n const userResponse = await this.createUserProfile(userReqParams);\n\n const walletReqParams = {\n ...wallet,\n user_id,\n id: wallet_id,\n };\n\n const walletResponse = await this.upsertWalletAsInserter(walletReqParams);\n\n return [userResponse, walletResponse];\n }\n}\n","import type {\n AvailableIssuerType,\n idOSCredential,\n idOSCredentialRecord,\n} from \"@idos-network/credentials/types\";\nimport type {\n AddWalletMessageInput,\n EditPublicNotesAsIssuerInput,\n idOSDelegatedWriteGrant,\n idOSGrant,\n idOSUser,\n idOSUserAttribute,\n idOSWallet,\n} from \"@idos-network/kwil-infra/actions\";\nimport type { SignKeyPair } from \"tweetnacl\";\n\nimport {\n createKgwAuthenticatedBlobGateway,\n createNodeKwilClient,\n createServerKwilSigner,\n} from \"@idos-network/kwil-infra\";\n\nimport {\n CredentialService,\n type CredentialByDelegatedWriteGrantBaseParams,\n type DelegatedWriteGrantBaseParams,\n type DelegatedWriteGrantParams,\n} from \"./services/credential.service\";\nimport {\n type CreateProfileReqParams,\n type CreateWalletReqParams,\n type UpsertWalletReqParams,\n UserService,\n} from \"./services/user.service\";\n\ntype CreateIssuerParams = {\n chainId?: string;\n nodeUrl: string;\n blobGatewayUrl?: string;\n signingKeyPair: SignKeyPair;\n};\n\nexport class idOSIssuer {\n readonly #credentialService: CredentialService;\n readonly #userService: UserService;\n\n static async init(params: CreateIssuerParams): Promise<idOSIssuer> {\n const kwilClient = await createNodeKwilClient({\n nodeUrl: params.nodeUrl,\n chainId: params.chainId,\n });\n\n const [signer] = await createServerKwilSigner(params.signingKeyPair);\n kwilClient.setSigner(signer);\n\n const blobGateway = createKgwAuthenticatedBlobGateway({\n url: params.blobGatewayUrl ?? params.nodeUrl,\n kwilClient,\n signer,\n });\n\n const credentialService = new CredentialService(kwilClient, params.signingKeyPair, blobGateway);\n const userService = new UserService(kwilClient);\n\n return new idOSIssuer(credentialService, userService);\n }\n\n private constructor(credentialService: CredentialService, userService: UserService) {\n this.#credentialService = credentialService;\n this.#userService = userService;\n }\n\n // User Service facade methods\n async hasProfile(userAddress: string): Promise<boolean> {\n return this.#userService.hasProfile(userAddress);\n }\n\n async createUserProfile(params: CreateProfileReqParams): Promise<idOSUser> {\n return this.#userService.createUserProfile(params);\n }\n\n async upsertWalletAsInserter(params: UpsertWalletReqParams): Promise<idOSWallet> {\n return this.#userService.upsertWalletAsInserter(params);\n }\n\n async addWalletMessage(params: AddWalletMessageInput): Promise<string> {\n return this.#userService.addWalletMessage(params);\n }\n\n async createUser(\n user: CreateProfileReqParams,\n wallet: CreateWalletReqParams,\n ): Promise<[idOSUser, idOSWallet]> {\n return this.#userService.createUser(user, wallet);\n }\n\n async getUser(id: string): Promise<idOSUser> {\n return this.#userService.getUser({ id });\n }\n\n async requestDelegatedWriteGrantMessage(params: idOSDelegatedWriteGrant): Promise<string> {\n return this.#credentialService.requestDelegatedWriteGrantMessage(params);\n }\n\n async createCredentialByDelegatedWriteGrant(\n credentialParams: CredentialByDelegatedWriteGrantBaseParams,\n delegatedWriteGrant: DelegatedWriteGrantParams,\n consumerEncryptionPublicKey: Uint8Array,\n ): Promise<{\n originalCredential: Omit<idOSCredential, \"user_id\">;\n copyCredential: Omit<idOSCredential, \"user_id\">;\n }> {\n return this.#credentialService.createCredentialByDelegatedWriteGrant(\n credentialParams,\n delegatedWriteGrant,\n consumerEncryptionPublicKey,\n );\n }\n\n async editCredentialAsIssuer(\n publicNotesId: string,\n publicNotes: string,\n ): Promise<EditPublicNotesAsIssuerInput | null> {\n return this.#credentialService.editCredentialAsIssuer(publicNotesId, publicNotes);\n }\n\n async getCredentialIdByContentHash(contentHash: string): Promise<string | null> {\n return this.#credentialService.getCredentialIdByContentHash(contentHash);\n }\n\n async getCredentialShared(id: string): Promise<idOSCredentialRecord | null> {\n return this.#credentialService.getCredentialShared(id);\n }\n}\n\nexport type {\n idOSCredential,\n idOSGrant,\n idOSUser,\n idOSUserAttribute,\n idOSDelegatedWriteGrant,\n idOSWallet,\n AvailableIssuerType,\n CredentialByDelegatedWriteGrantBaseParams,\n DelegatedWriteGrantBaseParams,\n DelegatedWriteGrantParams,\n};\n\nexport { toDelegatedWriteGrantBaseParams } from \"@idos-network/kwil-infra/actions\";\n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3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "idOS Issuer JavaScript SDK for server environments",
|
|
5
5
|
"homepage": "https://idos.network",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@idos-network/credentials": "
|
|
32
|
-
"@idos-network/kwil-infra": "
|
|
31
|
+
"@idos-network/credentials": "4.0.0",
|
|
32
|
+
"@idos-network/kwil-infra": "4.0.0",
|
|
33
33
|
"@idos-network/kwil-js": "0.2.2",
|
|
34
|
-
"@idos-network/utils": "3.
|
|
34
|
+
"@idos-network/utils": "3.1.0",
|
|
35
35
|
"tweetnacl": "^1.0.3"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
package/src/index.test.ts
CHANGED
|
@@ -5,11 +5,13 @@ import { idOSIssuer, toDelegatedWriteGrantBaseParams } from "./index.js";
|
|
|
5
5
|
|
|
6
6
|
const mocks = vi.hoisted(() => ({
|
|
7
7
|
blobGateway: { fetchBlob: vi.fn(), uploadCredentialBlobs: vi.fn() },
|
|
8
|
+
credentialBroaderMessage: vi.fn(async () => ({ message: "credential-message" })),
|
|
8
9
|
createPreliminaryCredentialsByDwg: vi.fn(),
|
|
9
10
|
addWalletMessage: vi.fn(async () => ({ message: "add-wallet-message" })),
|
|
10
11
|
dwgMessage: vi.fn(async () => ({ message: "dwg-message-string" })),
|
|
11
12
|
kwilClient: {
|
|
12
13
|
setSigner: vi.fn(),
|
|
14
|
+
call: vi.fn(),
|
|
13
15
|
},
|
|
14
16
|
signer: { publicKey: "signer" },
|
|
15
17
|
}));
|
|
@@ -24,6 +26,7 @@ vi.mock("@idos-network/kwil-infra/actions", async (importOriginal) => ({
|
|
|
24
26
|
...((await importOriginal()) as object),
|
|
25
27
|
addWalletMessage: mocks.addWalletMessage,
|
|
26
28
|
createPreliminaryCredentialsByDwg: mocks.createPreliminaryCredentialsByDwg,
|
|
29
|
+
credentialBroaderMessage: mocks.credentialBroaderMessage,
|
|
27
30
|
dwgMessage: mocks.dwgMessage,
|
|
28
31
|
}));
|
|
29
32
|
|
|
@@ -88,6 +91,7 @@ describe("idOSIssuer", () => {
|
|
|
88
91
|
expect(payload.copy_content_size).toBeGreaterThan(0);
|
|
89
92
|
expect(mocks.blobGateway.uploadCredentialBlobs).toHaveBeenCalledWith({
|
|
90
93
|
requestId: payload.request_id,
|
|
94
|
+
credentialIds: [payload.original_id, payload.copy_id],
|
|
91
95
|
original: expect.any(Uint8Array),
|
|
92
96
|
copy: expect.any(Uint8Array),
|
|
93
97
|
});
|
|
@@ -106,20 +110,17 @@ describe("idOSIssuer", () => {
|
|
|
106
110
|
);
|
|
107
111
|
});
|
|
108
112
|
|
|
109
|
-
it("
|
|
113
|
+
it("addresses both delegated write grant blobs from one ukyc storage id", async () => {
|
|
110
114
|
const issuer = await idOSIssuer.init({
|
|
111
115
|
nodeUrl: "https://nodes.example",
|
|
112
116
|
blobGatewayUrl: "https://blob.example",
|
|
113
117
|
signingKeyPair: nacl.sign.keyPair(),
|
|
114
118
|
});
|
|
115
|
-
const originalContentUri = "ukyc://storage-abc/blobs/original";
|
|
116
|
-
const copyContentUri = "ukyc://storage-abc/blobs/copy";
|
|
117
119
|
const credentialParams = {
|
|
118
120
|
publicNotes: "{}",
|
|
119
121
|
plaintextContent: new Uint8Array([1, 2, 3]),
|
|
120
122
|
recipientEncryptionPublicKey: nacl.box.keyPair().publicKey,
|
|
121
|
-
|
|
122
|
-
copyContentUri,
|
|
123
|
+
ukycStorageId: "storage-abc",
|
|
123
124
|
};
|
|
124
125
|
const delegatedWriteGrant = {
|
|
125
126
|
id: crypto.randomUUID(),
|
|
@@ -140,19 +141,11 @@ describe("idOSIssuer", () => {
|
|
|
140
141
|
);
|
|
141
142
|
|
|
142
143
|
const payload = mocks.createPreliminaryCredentialsByDwg.mock.calls[0]?.[1];
|
|
143
|
-
expect(payload.original_content_uri).
|
|
144
|
-
expect(payload.copy_content_uri).
|
|
145
|
-
expect(
|
|
146
|
-
expect(result.
|
|
147
|
-
|
|
148
|
-
await expect(
|
|
149
|
-
issuer.createCredentialByDelegatedWriteGrant(
|
|
150
|
-
{ ...credentialParams, copyContentUri: originalContentUri },
|
|
151
|
-
delegatedWriteGrant,
|
|
152
|
-
consumerEncryptionPublicKey,
|
|
153
|
-
),
|
|
154
|
-
).rejects.toThrow("Original and copy credentials must use distinct content URIs");
|
|
155
|
-
expect(mocks.createPreliminaryCredentialsByDwg).toHaveBeenCalledOnce();
|
|
144
|
+
expect(payload.original_content_uri).toMatch(/^ukyc:\/\/storage-abc\/blobs\/[0-9a-f]{64}$/);
|
|
145
|
+
expect(payload.copy_content_uri).toMatch(/^ukyc:\/\/storage-abc\/blobs\/[0-9a-f]{64}$/);
|
|
146
|
+
expect(payload.original_content_uri).not.toBe(payload.copy_content_uri);
|
|
147
|
+
expect(result.originalCredential.content_uri).toBe(payload.original_content_uri);
|
|
148
|
+
expect(result.copyCredential.content_uri).toBe(payload.copy_content_uri);
|
|
156
149
|
});
|
|
157
150
|
|
|
158
151
|
it("maps request params for createCredentialByDelegatedWriteGrant via toDelegatedWriteGrantBaseParams", async () => {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
type CreatePreliminaryCredentialsByDwgInput,
|
|
12
12
|
createPreliminaryCredentialsByDwg,
|
|
13
|
+
credentialBroaderMessage,
|
|
13
14
|
dwgMessage,
|
|
14
15
|
type EditPublicNotesAsIssuerInput,
|
|
15
16
|
editPublicNotesAsIssuer,
|
|
@@ -31,11 +32,8 @@ export type DelegatedWriteGrantParams = DelegatedWriteGrantBaseParams & {
|
|
|
31
32
|
|
|
32
33
|
export type CredentialByDelegatedWriteGrantBaseParams = Omit<
|
|
33
34
|
BuildPreliminaryIDOSCredentialArgs,
|
|
34
|
-
"issuerSigningSecretKey" | "
|
|
35
|
-
|
|
36
|
-
originalContentUri?: string;
|
|
37
|
-
copyContentUri?: string;
|
|
38
|
-
};
|
|
35
|
+
"issuerSigningSecretKey" | "broaderMessageFor"
|
|
36
|
+
>;
|
|
39
37
|
|
|
40
38
|
export class CredentialService {
|
|
41
39
|
readonly #kwilClient: KwilActionClient;
|
|
@@ -53,7 +51,10 @@ export class CredentialService {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
async requestDelegatedWriteGrantMessage(params: idOSDelegatedWriteGrant): Promise<string> {
|
|
56
|
-
return dwgMessage(this.#kwilClient, params).then((res) =>
|
|
54
|
+
return dwgMessage(this.#kwilClient, params).then((res) => {
|
|
55
|
+
if (!res) throw new Error("dwg_message returned no rows");
|
|
56
|
+
return res.message;
|
|
57
|
+
});
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
async createCredentialByDelegatedWriteGrant(
|
|
@@ -64,11 +65,16 @@ export class CredentialService {
|
|
|
64
65
|
originalCredential: Omit<idOSCredential, "user_id">;
|
|
65
66
|
copyCredential: Omit<idOSCredential, "user_id">;
|
|
66
67
|
}> {
|
|
67
|
-
const
|
|
68
|
+
const broaderMessageFor = (publicNotesSignature: string, contentUri: string) =>
|
|
69
|
+
credentialBroaderMessage(this.#kwilClient, {
|
|
70
|
+
public_notes_signature: publicNotesSignature,
|
|
71
|
+
content_uri: contentUri,
|
|
72
|
+
recipient_wallet: delegatedWriteGrant.ownerWalletIdentifier,
|
|
73
|
+
}).then((row) => row.message);
|
|
68
74
|
const originalCredential: PreliminaryIDOSCredential = {
|
|
69
75
|
...(await buildPreliminaryIDOSCredential({
|
|
70
|
-
...
|
|
71
|
-
|
|
76
|
+
...credentialParams,
|
|
77
|
+
broaderMessageFor,
|
|
72
78
|
issuerSigningSecretKey: this.#signingKeyPair.secretKey,
|
|
73
79
|
})),
|
|
74
80
|
id: crypto.randomUUID(),
|
|
@@ -78,10 +84,10 @@ export class CredentialService {
|
|
|
78
84
|
|
|
79
85
|
const copyCredential: PreliminaryIDOSCredential = {
|
|
80
86
|
...(await buildPreliminaryIDOSCredential({
|
|
81
|
-
...
|
|
82
|
-
contentUri: copyContentUri,
|
|
87
|
+
...credentialParams,
|
|
83
88
|
publicNotes: "",
|
|
84
89
|
recipientEncryptionPublicKey: consumerEncryptionPublicKey,
|
|
90
|
+
broaderMessageFor,
|
|
85
91
|
issuerSigningSecretKey: this.#signingKeyPair.secretKey,
|
|
86
92
|
})),
|
|
87
93
|
id: crypto.randomUUID(),
|
|
@@ -124,6 +130,7 @@ export class CredentialService {
|
|
|
124
130
|
|
|
125
131
|
await this.#blobGateway.uploadCredentialBlobs({
|
|
126
132
|
requestId,
|
|
133
|
+
credentialIds: [originalCredential.id, copyCredential.id],
|
|
127
134
|
original: originalCredential.encryptedContent,
|
|
128
135
|
copy: copyCredential.encryptedContent,
|
|
129
136
|
});
|
|
@@ -150,7 +157,7 @@ export class CredentialService {
|
|
|
150
157
|
|
|
151
158
|
async getCredentialIdByContentHash(contentHash: string): Promise<string | null> {
|
|
152
159
|
const id = await getSiblingCredentialId(this.#kwilClient, { content_hash: contentHash }).then(
|
|
153
|
-
(res) => res
|
|
160
|
+
(res) => res?.id,
|
|
154
161
|
);
|
|
155
162
|
|
|
156
163
|
invariant(id, "Required `idOSCredential` id not found");
|
|
@@ -39,7 +39,10 @@ export class UserService {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
async hasProfile(address: string): Promise<boolean> {
|
|
42
|
-
return _hasProfile(this.#kwilClient, { address }).then((res) =>
|
|
42
|
+
return _hasProfile(this.#kwilClient, { address }).then((res) => {
|
|
43
|
+
if (!res) throw new Error("has_profile returned no rows");
|
|
44
|
+
return res.has_profile;
|
|
45
|
+
});
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
async createUserProfile(params: CreateProfileReqParams): Promise<idOSUser> {
|
|
@@ -61,7 +64,9 @@ export class UserService {
|
|
|
61
64
|
|
|
62
65
|
/// Useful to understand if a user id already exists.
|
|
63
66
|
async getUser(params: GetUserAsInserterInput): Promise<idOSUser> {
|
|
64
|
-
|
|
67
|
+
const user = await getUserAsInserter(this.#kwilClient, this.#ensureEntityId(params));
|
|
68
|
+
if (!user) throw new Error("get_user_as_inserter returned no rows");
|
|
69
|
+
return user;
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
async createUser(
|