diff --git a/package.json b/package.json index 72fd892..562e3a5 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "prepare": "yarn build" }, "dependencies": { + "@stablelib/ed25519": "^1.0.2", "one-webcrypto": "^1.0.1", - "tweetnacl": "^1.0.3", "uint8arrays": "^3.0.0" }, "devDependencies": { diff --git a/src/did/validation.ts b/src/did/validation.ts index d708e7b..dd28825 100644 --- a/src/did/validation.ts +++ b/src/did/validation.ts @@ -1,5 +1,5 @@ +import * as ed25519 from "@stablelib/ed25519" import * as uint8arrays from "uint8arrays" -import nacl from "tweetnacl" import * as rsa from "../crypto/rsa" import * as ecdsa from "../crypto/ecdsa" @@ -17,7 +17,7 @@ export async function verifySignature(data: Uint8Array, signature: Uint8Array, d switch (type) { case "ed25519": - return nacl.sign.detached.verify(data, signature, publicKey) + return ed25519.verify(publicKey, data, signature) case "rsa": return await rsa.verify(data, signature, publicKey) diff --git a/src/keypair/ed25519.ts b/src/keypair/ed25519.ts index bc92ca1..15e6f5e 100644 --- a/src/keypair/ed25519.ts +++ b/src/keypair/ed25519.ts @@ -1,4 +1,4 @@ -import nacl from "tweetnacl" +import * as ed25519 from "@stablelib/ed25519" import * as uint8arrays from "uint8arrays" import BaseKeypair from "./base" import { Encodings } from "../types" @@ -16,7 +16,7 @@ export class EdKeypair extends BaseKeypair { exportable: boolean }): Promise { const { exportable } = params || {} - const keypair = nacl.sign.keyPair() + const keypair = ed25519.generateKeyPair() return new EdKeypair(keypair.secretKey, keypair.publicKey, exportable ?? false) } @@ -26,12 +26,12 @@ export class EdKeypair extends BaseKeypair { }): EdKeypair { const { format = "base64pad", exportable = false } = params || {} const secretKey = uint8arrays.fromString(key, format) - const keypair = nacl.sign.keyPair.fromSecretKey(secretKey) - return new EdKeypair(keypair.secretKey, keypair.publicKey, exportable) + const publicKey = ed25519.extractPublicKeyFromSecretKey(secretKey) + return new EdKeypair(secretKey, publicKey, exportable) } async sign(msg: Uint8Array): Promise { - return nacl.sign.detached(msg, this.secretKey) + return ed25519.sign(this.secretKey, msg) } async export(format: Encodings = "base64pad"): Promise { diff --git a/yarn.lock b/yarn.lock index b90695a..4628527 100644 --- a/yarn.lock +++ b/yarn.lock @@ -551,6 +551,54 @@ dependencies: "@sinonjs/commons" "^1.7.0" +"@stablelib/binary@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@stablelib/binary/-/binary-1.0.1.tgz#c5900b94368baf00f811da5bdb1610963dfddf7f" + integrity sha512-ClJWvmL6UBM/wjkvv/7m5VP3GMr9t0osr4yVgLZsLCOz4hGN9gIAFEqnJ0TsSMAN+n840nf2cHZnA5/KFqHC7Q== + dependencies: + "@stablelib/int" "^1.0.1" + +"@stablelib/ed25519@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@stablelib/ed25519/-/ed25519-1.0.2.tgz#937a88a2f73a71d9bdc3ea276efe8954776ae0f4" + integrity sha512-FtnvUwvKbp6l1dNcg4CswMAVFVu/nzLK3oC7/PRtjYyHbWsIkD8j+5cjXHmwcCpdCpRCaTGACkEhhMQ1RcdSOQ== + dependencies: + "@stablelib/random" "^1.0.1" + "@stablelib/sha512" "^1.0.1" + "@stablelib/wipe" "^1.0.1" + +"@stablelib/hash@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@stablelib/hash/-/hash-1.0.1.tgz#3c944403ff2239fad8ebb9015e33e98444058bc5" + integrity sha512-eTPJc/stDkdtOcrNMZ6mcMK1e6yBbqRBaNW55XA1jU8w/7QdnCF0CmMmOD1m7VSkBR44PWrMHU2l6r8YEQHMgg== + +"@stablelib/int@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@stablelib/int/-/int-1.0.1.tgz#75928cc25d59d73d75ae361f02128588c15fd008" + integrity sha512-byr69X/sDtDiIjIV6m4roLVWnNNlRGzsvxw+agj8CIEazqWGOQp2dTYgQhtyVXV9wpO6WyXRQUzLV/JRNumT2w== + +"@stablelib/random@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@stablelib/random/-/random-1.0.1.tgz#4357a00cb1249d484a9a71e6054bc7b8324a7009" + integrity sha512-zOh+JHX3XG9MSfIB0LZl/YwPP9w3o6WBiJkZvjPoKKu5LKFW4OLV71vMxWp9qG5T43NaWyn0QQTWgqCdO+yOBQ== + dependencies: + "@stablelib/binary" "^1.0.1" + "@stablelib/wipe" "^1.0.1" + +"@stablelib/sha512@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@stablelib/sha512/-/sha512-1.0.1.tgz#6da700c901c2c0ceacbd3ae122a38ac57c72145f" + integrity sha512-13gl/iawHV9zvDKciLo1fQ8Bgn2Pvf7OV6amaRVKiq3pjQ3UmEpXxWiAfV8tYjUpeZroBxtyrwtdooQT/i3hzw== + dependencies: + "@stablelib/binary" "^1.0.1" + "@stablelib/hash" "^1.0.1" + "@stablelib/wipe" "^1.0.1" + +"@stablelib/wipe@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@stablelib/wipe/-/wipe-1.0.1.tgz#d21401f1d59ade56a62e139462a97f104ed19a36" + integrity sha512-WfqfX/eXGiAd3RJe4VU2snh/ZPwtSjLG4ynQ/vYzvghTh7dHFcI1wl+nrkWG6lGhukOxOsUHfv8dUXr58D0ayg== + "@tootallnate/once@1": version "1.1.2" resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" @@ -2934,11 +2982,6 @@ tsutils@^3.21.0: dependencies: tslib "^1.8.1" -tweetnacl@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" - integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== - type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"