Skip to content

Commit

Permalink
Merge branch 'main' of github.com:rarimo/rarime into feature/cosmos-w…
Browse files Browse the repository at this point in the history
…allet
  • Loading branch information
ardier16 committed Mar 19, 2024
2 parents fb8ec6e + b0eba8d commit 5d3d4af
Show file tree
Hide file tree
Showing 8 changed files with 2,332 additions and 2,343 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
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ changesetBaseRefs:
- origin/main
- upstream/main

compressionLevel: mixed

enableGlobalCache: false

enableTelemetry: false

nodeLinker: node-modules
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- `@rarimo/rarime`:
- `CreateIdentity` - accept `privateKeyHex` optional param for identity creation
- Bump Yarn version to 4.1.1
- Use SWC instead of TSC for the build process
- Update Jest config for testing
- Use latest MetaMask snap libraries
- Use `workspace` version inside packages

### Removed
- `packages/site` package

### Removed
- `packages/site` package

## [2.0.3] - 2024-02-06
### Changed
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": "ABVTZiQu17L4Wp76l5HtJdnF9Oy/QeqaFccW0pLykv0=",
"shasum": "uwfyjQYW6oH/Kf1RokU8GLv56KdXpQOm+n7Arnvx16o=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
20 changes: 10 additions & 10 deletions packages/snap/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ export type WalletOptions = {
};

export class Wallet {
private readonly privateKey: Uint8Array;
readonly #privateKey: Uint8Array;

private readonly pubkey: Uint8Array;
readonly #pubkey: Uint8Array;

private readonly address: string;
readonly #address: string;

constructor(privateKey: Uint8Array, publicKey: Uint8Array, address: string) {
this.privateKey = privateKey;
this.pubkey = publicKey;
this.address = address;
this.#privateKey = privateKey;
this.#pubkey = publicKey;
this.#address = address;
}

static create(privateKey: string, addressPrefix: string) {
Expand All @@ -117,9 +117,9 @@ export class Wallet {
getAccounts() {
return [
{
address: this.address,
address: this.#address,
algo: 'secp256k1',
pubkey: this.pubkey,
pubkey: this.#pubkey,
},
];
}
Expand All @@ -135,7 +135,7 @@ export class Wallet {

const hash = sha256(serializeSignDoc(signDoc));

const signature = await secp.sign(hash, this.privateKey, {
const signature = await secp.sign(hash, this.#privateKey, {
canonical: true,
extraEntropy: true,
der: false,
Expand Down Expand Up @@ -165,7 +165,7 @@ export class Wallet {
}
const hash = sha256(serializeStdSignDoc(signDoc));
const extraEntropy = options?.extraEntropy ? true : undefined;
const signature = await secp.sign(hash, this.privateKey, {
const signature = await secp.sign(hash, this.#privateKey, {
// canonical: true,
extraEntropy,
// der: false,
Expand Down
20 changes: 10 additions & 10 deletions packages/snap/src/zkp/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 DID({
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/zkp/helpers/credential-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,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 @@ -176,8 +176,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 @@ -189,9 +189,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 @@ -234,12 +234,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 @@ -296,8 +296,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 @@ -332,7 +332,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 @@ -350,9 +350,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 @@ -375,7 +375,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 @@ -415,7 +415,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 @@ -444,7 +444,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
Loading

0 comments on commit 5d3d4af

Please sign in to comment.