Skip to content

Commit fed103a

Browse files
committed
Merge pull-request #1166
2 parents ef00a39 + 471b8b4 commit fed103a

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

.changeset/khaki-grapes-talk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@turnkey/crypto": patch
33
---
44

5-
Remove `@turnkey/http` from devDependencies
5+
Remove `@turnkey/http` and `@turnkey/api-key-stamper` from devDependencies

packages/crypto/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"cbor-js": "0.1.0"
5757
},
5858
"devDependencies": {
59-
"@turnkey/api-key-stamper": "workspace:*",
6059
"@types/cbor-js": "^0.1.1",
6160
"@types/jest": "^29.5.3",
6261
"jest": "29.7.0"

packages/crypto/src/__tests__/crypto-test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { test, expect, describe } from "@jest/globals";
2-
import { ApiKeyStamper } from "@turnkey/api-key-stamper";
32
import { uint8ArrayFromHexString } from "@turnkey/encoding";
3+
import { p256 } from "@noble/curves/p256";
4+
import { sha256 } from "@noble/hashes/sha256";
45
import {
56
getPublicKey,
67
generateP256KeyPair,
@@ -198,27 +199,23 @@ describe("Turnkey Crypto Primitives", () => {
198199
test("verifyRequestStamp", async () => {
199200
const { publicKey: apiPublicKey, privateKey: apiPrivateKey } =
200201
generateP256KeyPair();
201-
const apiKeyStamper = new ApiKeyStamper({
202-
apiPublicKey,
203-
apiPrivateKey,
204-
});
205202

206203
// we create a sample request payload
207204
const requestBody = JSON.stringify({
208205
organizationId: "00000000-00000000-00000000-00000000",
209206
timestampMs: Date.now().toString(),
210207
});
211208

212-
// we stamp the request payload to get the signature
213-
const { stampHeaderValue } = await apiKeyStamper.stamp(requestBody);
214-
215-
const decodedStampContents = atob(stampHeaderValue);
216-
const parsedStampContents = JSON.parse(decodedStampContents);
217-
const signature = parsedStampContents.signature;
209+
// we manually create a signature using @noble/curves directly
210+
// to avoid a circular dependency with ApiKeyStamper
211+
const messageHash = sha256(new TextEncoder().encode(requestBody));
212+
const privateKeyBytes = uint8ArrayFromHexString(apiPrivateKey);
213+
const signatureBytes = p256.sign(messageHash, privateKeyBytes).toDERHex();
218214

215+
// we verify the signature
219216
const verified = await verifyStampSignature(
220217
apiPublicKey,
221-
signature,
218+
signatureBytes,
222219
requestBody,
223220
);
224221

pnpm-lock.yaml

Lines changed: 33 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)