Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
magnified103 committed Jan 3, 2025
1 parent 9ab2c25 commit 4d22d07
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ export class DRPNode {
log.error("::signVertexOperation: Invalid peer id");
return;
}
vertex.signature = await this.credentialStore.sign(vertex.hash);
vertex.signature = await this.credentialStore.signWithEd25519(vertex.hash);
}
}
23 changes: 17 additions & 6 deletions packages/node/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { DRPObject, DRPPublicCredential } from "@ts-drp/object";
import bls from "@chainsafe/bls/herumi";
import { deriveKeyFromEntropy } from "@chainsafe/bls-keygen";
import type { SecretKey as BlsSecretKey } from "@chainsafe/bls/types";
import { generateKeyPair, generateKeyPairFromSeed } from "@libp2p/crypto/keys";
import type { Ed25519PrivateKey } from "@libp2p/interface";
import bls from "@chainsafe/bls";
import type { SecretKey as BlsSecretKey } from "@chainsafe/bls/types";
import { deriveKeyFromEntropy } from "@chainsafe/bls-keygen";
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
import type { DRPObject, DRPPublicCredential } from "@ts-drp/object";
import { toString as uint8ArrayToString } from "uint8arrays";
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";

export type DRPObjectStoreCallback = (
objectId: string,
Expand Down Expand Up @@ -93,7 +93,7 @@ export class DRPCredentialStore {
};
}

async sign(data: string): Promise<string> {
async signWithEd25519(data: string): Promise<string> {
if (!this._ed25519PrivateKey) {
throw new Error("Private key not found");
}
Expand All @@ -103,4 +103,15 @@ export class DRPCredentialStore {
);
return uint8ArrayToString(signature, "base64");
}

signWithBls(data: string): string {
if (!this._blsPrivateKey) {
throw new Error("Private key not found");
}

const signature = this._blsPrivateKey
.sign(uint8ArrayFromString(data))
.toBytes();
return uint8ArrayToString(signature, "base64");
}
}
5 changes: 4 additions & 1 deletion packages/node/tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ describe("DPRNode with verify and sign signature", () => {
beforeEach(async () => {
drp = new AddWinsSetWithACL(
new Map([
[drpNode.networkNode.peerId, drpNode.credentialStore.getPublicCredential() || ""],
[
drpNode.networkNode.peerId,
drpNode.credentialStore.getPublicCredential() || "",
],
]),
);
drpObject = new DRPObject(drpNode.networkNode.peerId, drp);
Expand Down
6 changes: 5 additions & 1 deletion packages/object/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export interface DRPPublicCredential {
export interface IACL {
isWriter: (peerId: string) => boolean;
isAdmin: (peerId: string) => boolean;
grant: (senderId: string, peerId: string, publicKey: DRPPublicCredential) => void;
grant: (
senderId: string,
peerId: string,
publicKey: DRPPublicCredential,
) => void;
revoke: (senderId: string, peerId: string) => void;
getPeerKey: (peerId: string) => DRPPublicCredential | undefined;
}
Expand Down

0 comments on commit 4d22d07

Please sign in to comment.