@dxos/crypto
Advanced tools
Comparing version 0.6.12 to 0.6.13-main.09887cd
@@ -1,1 +0,1 @@ | ||
{"inputs":{"inject-globals:@inject-globals":{"bytes":384,"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/keys.ts":{"bytes":8453,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/signer.ts":{"bytes":810,"imports":[{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/browser/subtle.ts":{"bytes":925,"imports":[{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/validator.ts":{"bytes":1519,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/verify.ts":{"bytes":2511,"imports":[{"path":"packages/common/crypto/src/browser/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/uuid.ts":{"bytes":821,"imports":[{"path":"packages/common/crypto/src/browser/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/index.ts":{"bytes":909,"imports":[{"path":"packages/common/crypto/src/keys.ts","kind":"import-statement","original":"./keys"},{"path":"packages/common/crypto/src/signer.ts","kind":"import-statement","original":"./signer"},{"path":"packages/common/crypto/src/browser/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"packages/common/crypto/src/validator.ts","kind":"import-statement","original":"./validator"},{"path":"packages/common/crypto/src/verify.ts","kind":"import-statement","original":"./verify"},{"path":"packages/common/crypto/src/uuid.ts","kind":"import-statement","original":"./uuid"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/common/crypto/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6150},"packages/common/crypto/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"exports":["SIGNATURE_LENGTH","createId","createKeyPair","discoveryKey","getSignatureValidator","randomBytes","randomUUID","sign","subtleCrypto","validateKeyPair","verify","verifySignature","webcrypto"],"entryPoint":"packages/common/crypto/src/index.ts","inputs":{"inject-globals:@inject-globals":{"bytesInOutput":79},"packages/common/crypto/src/keys.ts":{"bytesInOutput":2241},"packages/common/crypto/src/index.ts":{"bytesInOutput":0},"packages/common/crypto/src/browser/subtle.ts":{"bytesInOutput":58},"packages/common/crypto/src/validator.ts":{"bytesInOutput":238},"packages/common/crypto/src/verify.ts":{"bytesInOutput":387},"packages/common/crypto/src/uuid.ts":{"bytesInOutput":61}},"bytes":3594}}} | ||
{"inputs":{"inject-globals:@inject-globals":{"bytes":324,"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/keys.ts":{"bytes":8453,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/signer.ts":{"bytes":810,"imports":[{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/browser/subtle.ts":{"bytes":925,"imports":[{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/validator.ts":{"bytes":1519,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/verify.ts":{"bytes":4811,"imports":[{"path":"packages/common/crypto/src/browser/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/uuid.ts":{"bytes":821,"imports":[{"path":"packages/common/crypto/src/browser/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/index.ts":{"bytes":909,"imports":[{"path":"packages/common/crypto/src/keys.ts","kind":"import-statement","original":"./keys"},{"path":"packages/common/crypto/src/signer.ts","kind":"import-statement","original":"./signer"},{"path":"packages/common/crypto/src/browser/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"packages/common/crypto/src/validator.ts","kind":"import-statement","original":"./validator"},{"path":"packages/common/crypto/src/verify.ts","kind":"import-statement","original":"./verify"},{"path":"packages/common/crypto/src/uuid.ts","kind":"import-statement","original":"./uuid"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/common/crypto/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7375},"packages/common/crypto/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"exports":["SIGNATURE_LENGTH","createId","createKeyPair","discoveryKey","ed25519Signature","getSignatureValidator","randomBytes","randomUUID","sign","subtleCrypto","validateKeyPair","verify","verifySignature","webcrypto"],"entryPoint":"packages/common/crypto/src/index.ts","inputs":{"inject-globals:@inject-globals":{"bytesInOutput":79},"packages/common/crypto/src/keys.ts":{"bytesInOutput":2241},"packages/common/crypto/src/index.ts":{"bytesInOutput":0},"packages/common/crypto/src/browser/subtle.ts":{"bytesInOutput":58},"packages/common/crypto/src/validator.ts":{"bytesInOutput":238},"packages/common/crypto/src/verify.ts":{"bytesInOutput":908},"packages/common/crypto/src/uuid.ts":{"bytesInOutput":61}},"bytes":4135}}} |
@@ -1,1 +0,1 @@ | ||
{"inputs":{"packages/common/crypto/src/keys.ts":{"bytes":8453,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/signer.ts":{"bytes":810,"imports":[],"format":"esm"},"packages/common/crypto/src/subtle.ts":{"bytes":978,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/validator.ts":{"bytes":1519,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/verify.ts":{"bytes":2511,"imports":[{"path":"packages/common/crypto/src/subtle.ts","kind":"import-statement","original":"./subtle"}],"format":"esm"},"packages/common/crypto/src/uuid.ts":{"bytes":821,"imports":[{"path":"packages/common/crypto/src/subtle.ts","kind":"import-statement","original":"./subtle"}],"format":"esm"},"packages/common/crypto/src/index.ts":{"bytes":909,"imports":[{"path":"packages/common/crypto/src/keys.ts","kind":"import-statement","original":"./keys"},{"path":"packages/common/crypto/src/signer.ts","kind":"import-statement","original":"./signer"},{"path":"packages/common/crypto/src/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"packages/common/crypto/src/validator.ts","kind":"import-statement","original":"./validator"},{"path":"packages/common/crypto/src/verify.ts","kind":"import-statement","original":"./verify"},{"path":"packages/common/crypto/src/uuid.ts","kind":"import-statement","original":"./uuid"}],"format":"esm"}},"outputs":{"packages/common/crypto/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6164},"packages/common/crypto/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"exports":["SIGNATURE_LENGTH","createId","createKeyPair","discoveryKey","getSignatureValidator","randomBytes","randomUUID","sign","subtleCrypto","validateKeyPair","verify","verifySignature","webcrypto"],"entryPoint":"packages/common/crypto/src/index.ts","inputs":{"packages/common/crypto/src/keys.ts":{"bytesInOutput":2233},"packages/common/crypto/src/index.ts":{"bytesInOutput":0},"packages/common/crypto/src/subtle.ts":{"bytesInOutput":130},"packages/common/crypto/src/validator.ts":{"bytesInOutput":238},"packages/common/crypto/src/verify.ts":{"bytesInOutput":387},"packages/common/crypto/src/uuid.ts":{"bytesInOutput":62}},"bytes":3517}}} | ||
{"inputs":{"packages/common/crypto/src/keys.ts":{"bytes":8453,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/signer.ts":{"bytes":810,"imports":[],"format":"esm"},"packages/common/crypto/src/subtle.ts":{"bytes":978,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/validator.ts":{"bytes":1519,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"format":"esm"},"packages/common/crypto/src/verify.ts":{"bytes":4811,"imports":[{"path":"packages/common/crypto/src/subtle.ts","kind":"import-statement","original":"./subtle"}],"format":"esm"},"packages/common/crypto/src/uuid.ts":{"bytes":821,"imports":[{"path":"packages/common/crypto/src/subtle.ts","kind":"import-statement","original":"./subtle"}],"format":"esm"},"packages/common/crypto/src/index.ts":{"bytes":909,"imports":[{"path":"packages/common/crypto/src/keys.ts","kind":"import-statement","original":"./keys"},{"path":"packages/common/crypto/src/signer.ts","kind":"import-statement","original":"./signer"},{"path":"packages/common/crypto/src/subtle.ts","kind":"import-statement","original":"./subtle"},{"path":"packages/common/crypto/src/validator.ts","kind":"import-statement","original":"./validator"},{"path":"packages/common/crypto/src/verify.ts","kind":"import-statement","original":"./verify"},{"path":"packages/common/crypto/src/uuid.ts","kind":"import-statement","original":"./uuid"}],"format":"esm"}},"outputs":{"packages/common/crypto/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7389},"packages/common/crypto/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"#hypercore-crypto","kind":"import-statement","external":true}],"exports":["SIGNATURE_LENGTH","createId","createKeyPair","discoveryKey","ed25519Signature","getSignatureValidator","randomBytes","randomUUID","sign","subtleCrypto","validateKeyPair","verify","verifySignature","webcrypto"],"entryPoint":"packages/common/crypto/src/index.ts","inputs":{"packages/common/crypto/src/keys.ts":{"bytesInOutput":2233},"packages/common/crypto/src/index.ts":{"bytesInOutput":0},"packages/common/crypto/src/subtle.ts":{"bytesInOutput":130},"packages/common/crypto/src/validator.ts":{"bytesInOutput":238},"packages/common/crypto/src/verify.ts":{"bytesInOutput":908},"packages/common/crypto/src/uuid.ts":{"bytesInOutput":62}},"bytes":4058}}} |
@@ -5,3 +5,10 @@ import { type PublicKey } from '@dxos/keys'; | ||
*/ | ||
export declare const verifySignature: (key: PublicKey, message: Uint8Array, signature: Uint8Array) => Promise<boolean>; | ||
export declare const verifySignature: (key: PublicKey, message: Uint8Array, signature: Uint8Array, algorithm?: { | ||
name: string; | ||
namedCurve?: string; | ||
}) => Promise<boolean>; | ||
/** | ||
* Creates an Ed25519 (libsodium keypair format) signature. | ||
*/ | ||
export declare const ed25519Signature: (secretKey: Uint8Array, message: Uint8Array) => Promise<Uint8Array>; | ||
//# sourceMappingURL=verify.d.ts.map |
{ | ||
"name": "@dxos/crypto", | ||
"version": "0.6.12", | ||
"version": "0.6.13-main.09887cd", | ||
"description": "Basic cross-platform crypto utils.", | ||
@@ -11,3 +11,3 @@ "homepage": "https://dxos.org", | ||
"#hypercore-crypto": { | ||
"workerd": "./hypercore-crypto-stub.js", | ||
"workerd": "./hypercore-crypto-stub.mjs", | ||
"default": "hypercore-crypto" | ||
@@ -20,3 +20,4 @@ } | ||
"node": { | ||
"default": "./dist/lib/node/index.cjs" | ||
"require": "./dist/lib/node/index.cjs", | ||
"default": "./dist/lib/node-esm/index.mjs" | ||
}, | ||
@@ -36,13 +37,12 @@ "types": "./dist/types/src/index.d.ts" | ||
"src", | ||
"./hypercore-crypto-stub.js" | ||
"./hypercore-crypto-stub.mjs" | ||
], | ||
"dependencies": { | ||
"hypercore-crypto": "^2.3.0", | ||
"@dxos/invariant": "0.6.12", | ||
"@dxos/node-std": "0.6.12", | ||
"@dxos/keys": "0.6.12" | ||
"@dxos/invariant": "0.6.13-main.09887cd", | ||
"@dxos/keys": "0.6.13-main.09887cd", | ||
"@dxos/node-std": "0.6.13-main.09887cd" | ||
}, | ||
"devDependencies": { | ||
"@types/crypto-js": "~4.0.2", | ||
"@types/node": "^18.11.9" | ||
"@types/node": "^22.7.4" | ||
}, | ||
@@ -49,0 +49,0 @@ "publishConfig": { |
@@ -5,6 +5,4 @@ // | ||
import { expect } from 'chai'; | ||
import { describe, test, expect } from 'vitest'; | ||
import { test } from '@dxos/test'; | ||
import { createId, createKeyPair, randomBytes, sign, verify } from './keys'; | ||
@@ -11,0 +9,0 @@ |
@@ -12,16 +12,12 @@ // | ||
*/ | ||
export const verifySignature = async (key: PublicKey, message: Uint8Array, signature: Uint8Array): Promise<boolean> => { | ||
export const verifySignature = async ( | ||
key: PublicKey, | ||
message: Uint8Array, | ||
signature: Uint8Array, | ||
algorithm: { name: string; namedCurve?: string } = { name: 'ECDSA', namedCurve: 'P-256' }, | ||
): Promise<boolean> => { | ||
let publicKey!: CryptoKey; | ||
try { | ||
publicKey = await subtleCrypto.importKey( | ||
'raw', | ||
key.asUint8Array(), | ||
{ | ||
name: 'ECDSA', | ||
namedCurve: 'P-256', | ||
}, | ||
true, | ||
['verify'], | ||
); | ||
publicKey = await subtleCrypto.importKey('raw', key.asUint8Array(), algorithm, true, ['verify']); | ||
} catch { | ||
@@ -33,3 +29,3 @@ return false; | ||
{ | ||
name: 'ECDSA', | ||
name: algorithm.name, | ||
hash: 'SHA-256', | ||
@@ -42,1 +38,16 @@ }, | ||
}; | ||
/** | ||
* Creates an Ed25519 (libsodium keypair format) signature. | ||
*/ | ||
export const ed25519Signature = async (secretKey: Uint8Array, message: Uint8Array): Promise<Uint8Array> => { | ||
const curve = 'Ed25519'; | ||
const privateKeyJwk = { | ||
kty: 'OKP', | ||
crv: curve, | ||
x: Buffer.from(secretKey.subarray(32)).toString('base64url'), | ||
d: Buffer.from(secretKey.subarray(0, 32)).toString('base64url'), | ||
}; | ||
const key = await subtleCrypto.importKey('jwk', privateKeyJwk, { name: curve }, true, ['sign']); | ||
return new Uint8Array(await subtleCrypto.sign({ name: curve, hash: 'SHA-256' }, key, message)); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61142
1
44
767
+ Added@dxos/debug@0.6.13-main.09887cd(transitive)
+ Added@dxos/keys@0.6.13-main.09887cd(transitive)
+ Added@dxos/node-std@0.6.13-main.09887cd(transitive)
- Removed@dxos/debug@0.6.12(transitive)
- Removed@dxos/keys@0.6.12(transitive)
- Removed@dxos/node-std@0.6.12(transitive)