Skip to content

Commit

Permalink
Update lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ardier16 committed Mar 19, 2024
1 parent c1b5bf3 commit dfaabae
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},

Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions packages/snap/src/helpers/ceramic-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 <T>(data: string): Promise<T> => {
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));
};
}
36 changes: 18 additions & 18 deletions packages/snap/src/helpers/credential-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?: {
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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,
);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dfaabae

Please sign in to comment.