diff --git a/.eslintrc.js b/.eslintrc.js index 8592787..b4ac692 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,8 +28,6 @@ module.exports = { '@typescript-eslint/unbound-method': 0, '@typescript-eslint/no-unnecessary-type-assertion': 0, '@typescript-eslint/restrict-plus-operands': 0, - // TEMP: - 'no-restricted-syntax': 0, }, }, diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index e69e7ba..cdc622e 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/rarimo/rarime.git" }, "source": { - "shasum": "i3zejnjMXgIzAtSlngzOwVzLGk6rqg7rM/0dD1k9nc8=", + "shasum": "pR/GHO8ZzuPevQqqoN4Qt1F5Yo/90qjJom/1cLj2EAk=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/helpers/ceramic-helpers.ts b/packages/snap/src/helpers/ceramic-helpers.ts index 69e5db0..923ae86 100644 --- a/packages/snap/src/helpers/ceramic-helpers.ts +++ b/packages/snap/src/helpers/ceramic-helpers.ts @@ -8,13 +8,13 @@ import { getResolver } from 'key-did-resolver'; import { CERAMIC_URL } from '../config'; export class CeramicProvider { - private readonly pkHex: string; + readonly #pkHex: string; - private readonly _compose: ComposeClient; + readonly #compose: ComposeClient; constructor(pkHex: string, composeClient: ComposeClient) { - this.pkHex = pkHex; - this._compose = composeClient; + this.#pkHex = pkHex; + this.#compose = composeClient; } public static create( @@ -32,30 +32,30 @@ export class CeramicProvider { async auth() { const did = new CeramicDID({ - provider: new Ed25519Provider(Hex.decodeString(this.pkHex)), + provider: new Ed25519Provider(Hex.decodeString(this.#pkHex)), resolver: getResolver(), }); await did.authenticate(); - this._compose.setDID(did); + this.#compose.setDID(did); } public client() { - return this._compose; + return this.#compose; } public encrypt = async (data: unknown) => { - const jwe = await this._compose.did?.createJWE( + const jwe = await this.#compose.did?.createJWE( new TextEncoder().encode(JSON.stringify(data)), - [this._compose.did.id], + [this.#compose.did.id], ); return btoa(JSON.stringify(jwe)); }; public decrypt = async (data: string): Promise => { const jwe = JSON.parse(atob(data)); - const decrypted = await this._compose.did?.decryptJWE(jwe); + const decrypted = await this.#compose.did?.decryptJWE(jwe); return JSON.parse(new TextDecoder().decode(decrypted)); }; } diff --git a/packages/snap/src/helpers/credential-helpers.ts b/packages/snap/src/helpers/credential-helpers.ts index 5ef9426..6bcd69e 100644 --- a/packages/snap/src/helpers/credential-helpers.ts +++ b/packages/snap/src/helpers/credential-helpers.ts @@ -128,11 +128,11 @@ export const getAuthenticatedCeramicProvider = async ( export class VCManager { ceramicProvider: CeramicProvider; - private readonly saltedEntropy: string; + readonly #saltedEntropy: string; constructor(ceramicProvider: CeramicProvider, saltedEntropy: string) { this.ceramicProvider = ceramicProvider; - this.saltedEntropy = saltedEntropy; + this.#saltedEntropy = saltedEntropy; } static async create(opts?: { @@ -178,8 +178,8 @@ export class VCManager { ); } - private personalHashStr(str: string) { - return sha256(Buffer.from(str + this.saltedEntropy)); + #personalHashStr(str: string) { + return sha256(Buffer.from(str + this.#saltedEntropy)); } public async getDecryptedVCsByQueryHash( @@ -191,9 +191,9 @@ export class VCManager { throw new TypeError('Client not authenticated'); } - const hashedOwnerDid = this.personalHashStr(client.did.id); + const hashedOwnerDid = this.#personalHashStr(client.did.id); - const hashedQueryHash = this.personalHashStr(queryHash); + const hashedQueryHash = this.#personalHashStr(queryHash); const data = await loadAllCredentialsListPages< GetVerifiableCredentialsByQueryHashQueryVariables, @@ -236,12 +236,12 @@ export class VCManager { const claimIds = getClaimIdsFromOffer(claimOffer); const queryHash = hashVC(JSON.stringify(query.type), issuerDid, ownerDid); - const hashedQueryHash = this.personalHashStr(queryHash); + const hashedQueryHash = this.#personalHashStr(queryHash); const encryptedVCs = await Promise.all( claimIds.map(async (claimId) => { - const hashedClaimId = this.personalHashStr(claimId); - const hashedOwnerDid = this.personalHashStr(ownerDid); + const hashedClaimId = this.#personalHashStr(claimId); + const hashedOwnerDid = this.#personalHashStr(ownerDid); const data = await loadAllCredentialsListPages< GetVerifiableCredentialsByClaimIdAndQueryHashQueryVariables, @@ -298,8 +298,8 @@ export class VCManager { const encryptedVCs = await Promise.all( claimIds.map(async (claimId) => { - const hashedClaimId = this.personalHashStr(claimId); - const hashedOwnerDid = this.personalHashStr(ownerDid); + const hashedClaimId = this.#personalHashStr(claimId); + const hashedOwnerDid = this.#personalHashStr(ownerDid); const data = await loadAllCredentialsListPages< GetVerifiableCredentialsByClaimIdQueryVariables, @@ -334,7 +334,7 @@ export class VCManager { ); } - private async getPreparedVCFields(credential: W3CCredential) { + async #getPreparedVCFields(credential: W3CCredential) { const client = this.ceramicProvider.client(); const ownerDid = client.did?.id; @@ -352,9 +352,9 @@ export class VCManager { const claimId = getClaimIdFromVCId(credential.id); const [hashedOwnerDid, hashedQueryHash, hashedClaimId] = await Promise.all([ - this.personalHashStr(ownerDid), - this.personalHashStr(queryHash), - this.personalHashStr(claimId), + this.#personalHashStr(ownerDid), + this.#personalHashStr(queryHash), + this.#personalHashStr(claimId), ]); return { @@ -377,7 +377,7 @@ export class VCManager { public async clearMatchedVcs(credential: W3CCredential) { const client = this.ceramicProvider.client(); - const { hashedOwnerDid, hashedQueryHash } = await this.getPreparedVCFields( + const { hashedOwnerDid, hashedQueryHash } = await this.#getPreparedVCFields( credential, ); @@ -417,7 +417,7 @@ export class VCManager { const client = this.ceramicProvider.client(); const { hashedOwnerDid, hashedQueryHash, hashedClaimId } = - await this.getPreparedVCFields(credential); + await this.#getPreparedVCFields(credential); const encryptedVC = await this.ceramicProvider.encrypt(credential); @@ -446,7 +446,7 @@ export class VCManager { throw new TypeError('Client not authenticated'); } - const hashedOwnerDid = this.personalHashStr(ownerDid); + const hashedOwnerDid = this.#personalHashStr(ownerDid); const data = await loadAllCredentialsListPages< GetAllVerifiableCredentialsQueryVariables,