Skip to content

Commit

Permalink
feat(core): verifyMessageJoyId
Browse files Browse the repository at this point in the history
CKB SDK JS has fixed commonjs support.
  • Loading branch information
Hanssen0 committed Aug 1, 2024
1 parent 84b3011 commit 19a2ae5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
},
"dependencies": {
"@ckb-lumos/helpers": "^0.22.2",
"@joyid/ckb": "^1.0.1",
"@noble/ciphers": "^0.5.3",
"@noble/curves": "^1.4.2",
"@noble/hashes": "^1.4.0",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/signer/ckb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./signerCkbPrivateKey.js";
export * from "./signerCkbPublicKey.js";
export * from "./signerCkbScriptReadonly.js";
export * from "./verifyCkbSecp256k1.js";
export * from "./verifyJoyId.js";
20 changes: 20 additions & 0 deletions packages/core/src/signer/ckb/verifyJoyId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { verifySignature } from "@joyid/ckb";
import { BytesLike } from "../../bytes/index.js";
import { hexFrom } from "../../hex/index.js";

export function verifyMessageJoyId(
message: string | BytesLike,
signature: string,
identity: string,
): Promise<boolean> {
const challenge =
typeof message === "string" ? message : hexFrom(message).slice(2);
const { publicKey, keyType } = JSON.parse(identity);

return verifySignature({
challenge,
pubkey: publicKey,
keyType,
...JSON.parse(signature),
});
}
7 changes: 6 additions & 1 deletion packages/core/src/signer/signer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Hex } from "../../hex/index.js";
import { Num } from "../../num/index.js";
import { verifyMessageBtcEcdsa } from "../btc/index.js";
import { verifyMessageCkbSecp256k1 } from "../ckb/verifyCkbSecp256k1.js";
import { verifyMessageJoyId } from "../ckb/verifyJoyId.js";
import { verifyMessageEvmPersonal } from "../evm/verify.js";
import { verifyMessageNostrEvent } from "../nostr/verify.js";

Expand Down Expand Up @@ -106,7 +107,11 @@ export abstract class Signer {
signature.identity,
);
case SignerSignType.JoyId:
throw new Error("Not supported yet");
return verifyMessageJoyId(
message,
signature.signature,
signature.identity,
);
case SignerSignType.NostrEvent:
return verifyMessageNostrEvent(
message,
Expand Down
1 change: 0 additions & 1 deletion packages/faucet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
},
"dependencies": {
"@ckb-ccc/core": "workspace:*",
"@nervosnetwork/ckb-sdk-utils": "0.109.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
Expand Down
38 changes: 11 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19a2ae5

Please sign in to comment.