@ocap/mcrypto 1.29.3 → 1.29.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/signer/ed25519.d.mts +1 -1
- package/esm/signer/ed25519.mjs +17 -12
- package/lib/signer/ed25519.cjs +19 -13
- package/lib/signer/ed25519.d.cts +1 -1
- package/package.json +5 -5
package/esm/signer/ed25519.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { BytesType, EncodingType, KeyPairType } from "@ocap/util";
|
|
|
4
4
|
//#region src/signer/ed25519.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Signer implementation for ed25519, based on `
|
|
7
|
+
* Signer implementation for ed25519, based on `@noble/ed25519`
|
|
8
8
|
*
|
|
9
9
|
* @class Ed25519Signer
|
|
10
10
|
*/
|
package/esm/signer/ed25519.mjs
CHANGED
|
@@ -2,12 +2,13 @@ import { encode } from "../encode.mjs";
|
|
|
2
2
|
import signer_default from "../protocols/signer.mjs";
|
|
3
3
|
import { toUint8Array } from "@ocap/util";
|
|
4
4
|
import randomBytes from "randombytes";
|
|
5
|
-
import
|
|
5
|
+
import hashjs from "hash.js";
|
|
6
|
+
import * as ed from "@noble/ed25519";
|
|
6
7
|
|
|
7
8
|
//#region src/signer/ed25519.ts
|
|
8
|
-
|
|
9
|
+
ed.hashes.sha512 = (msg) => new Uint8Array(hashjs.sha512().update(msg).digest());
|
|
9
10
|
/**
|
|
10
|
-
* Signer implementation for ed25519, based on `
|
|
11
|
+
* Signer implementation for ed25519, based on `@noble/ed25519`
|
|
11
12
|
*
|
|
12
13
|
* @class Ed25519Signer
|
|
13
14
|
*/
|
|
@@ -30,10 +31,14 @@ var Ed25519Signer = class extends signer_default {
|
|
|
30
31
|
genKeyPair(encoding = "hex", userSeed) {
|
|
31
32
|
const seed = userSeed ? toUint8Array(userSeed) : new Uint8Array(randomBytes(32));
|
|
32
33
|
if (seed.byteLength !== 32) throw new Error("Invalid seed to generate key pair");
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const publicKey = ed.getPublicKey(seed);
|
|
35
|
+
const secretKey = new Uint8Array(64);
|
|
36
|
+
secretKey.set(seed);
|
|
37
|
+
secretKey.set(publicKey, 32);
|
|
38
|
+
return {
|
|
39
|
+
publicKey: encode(publicKey, encoding),
|
|
40
|
+
secretKey: encode(secretKey, encoding)
|
|
41
|
+
};
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
39
44
|
* Get publicKey from secretKey
|
|
@@ -43,8 +48,8 @@ var Ed25519Signer = class extends signer_default {
|
|
|
43
48
|
*/
|
|
44
49
|
getPublicKey(sk, encoding = "hex") {
|
|
45
50
|
const skBytes = toUint8Array(sk);
|
|
46
|
-
|
|
47
|
-
return encode(
|
|
51
|
+
if (skBytes.byteLength === 64) return encode(skBytes.slice(32, 64), encoding);
|
|
52
|
+
return encode(ed.getPublicKey(skBytes), encoding);
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
55
|
* Sign a message and get the signature hex
|
|
@@ -54,9 +59,9 @@ var Ed25519Signer = class extends signer_default {
|
|
|
54
59
|
* @returns {string} hex encoded signature
|
|
55
60
|
*/
|
|
56
61
|
sign(message, sk, encoding = "hex") {
|
|
57
|
-
const
|
|
62
|
+
const seed = toUint8Array(sk).slice(0, 32);
|
|
58
63
|
const messageBytes = toUint8Array(message);
|
|
59
|
-
return encode(
|
|
64
|
+
return encode(ed.sign(messageBytes, seed), encoding);
|
|
60
65
|
}
|
|
61
66
|
/**
|
|
62
67
|
* Verify if a signature is valid
|
|
@@ -70,7 +75,7 @@ var Ed25519Signer = class extends signer_default {
|
|
|
70
75
|
const pkBytes = toUint8Array(pk);
|
|
71
76
|
const messageBytes = toUint8Array(message);
|
|
72
77
|
const signatureBytes = toUint8Array(signature);
|
|
73
|
-
return
|
|
78
|
+
return ed.verify(signatureBytes, messageBytes, pkBytes);
|
|
74
79
|
}
|
|
75
80
|
};
|
|
76
81
|
var ed25519_default = new Ed25519Signer();
|
package/lib/signer/ed25519.cjs
CHANGED
|
@@ -5,13 +5,15 @@ const require_protocols_signer = require('../protocols/signer.cjs');
|
|
|
5
5
|
let _ocap_util = require("@ocap/util");
|
|
6
6
|
let randombytes = require("randombytes");
|
|
7
7
|
randombytes = require_rolldown_runtime.__toESM(randombytes);
|
|
8
|
-
let
|
|
9
|
-
|
|
8
|
+
let hash_js = require("hash.js");
|
|
9
|
+
hash_js = require_rolldown_runtime.__toESM(hash_js);
|
|
10
|
+
let _noble_ed25519 = require("@noble/ed25519");
|
|
11
|
+
_noble_ed25519 = require_rolldown_runtime.__toESM(_noble_ed25519);
|
|
10
12
|
|
|
11
13
|
//#region src/signer/ed25519.ts
|
|
12
|
-
|
|
14
|
+
_noble_ed25519.hashes.sha512 = (msg) => new Uint8Array(hash_js.default.sha512().update(msg).digest());
|
|
13
15
|
/**
|
|
14
|
-
* Signer implementation for ed25519, based on `
|
|
16
|
+
* Signer implementation for ed25519, based on `@noble/ed25519`
|
|
15
17
|
*
|
|
16
18
|
* @class Ed25519Signer
|
|
17
19
|
*/
|
|
@@ -34,10 +36,14 @@ var Ed25519Signer = class extends require_protocols_signer.default {
|
|
|
34
36
|
genKeyPair(encoding = "hex", userSeed) {
|
|
35
37
|
const seed = userSeed ? (0, _ocap_util.toUint8Array)(userSeed) : new Uint8Array((0, randombytes.default)(32));
|
|
36
38
|
if (seed.byteLength !== 32) throw new Error("Invalid seed to generate key pair");
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const publicKey = _noble_ed25519.getPublicKey(seed);
|
|
40
|
+
const secretKey = new Uint8Array(64);
|
|
41
|
+
secretKey.set(seed);
|
|
42
|
+
secretKey.set(publicKey, 32);
|
|
43
|
+
return {
|
|
44
|
+
publicKey: require_encode.encode(publicKey, encoding),
|
|
45
|
+
secretKey: require_encode.encode(secretKey, encoding)
|
|
46
|
+
};
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* Get publicKey from secretKey
|
|
@@ -47,8 +53,8 @@ var Ed25519Signer = class extends require_protocols_signer.default {
|
|
|
47
53
|
*/
|
|
48
54
|
getPublicKey(sk, encoding = "hex") {
|
|
49
55
|
const skBytes = (0, _ocap_util.toUint8Array)(sk);
|
|
50
|
-
|
|
51
|
-
return require_encode.encode(
|
|
56
|
+
if (skBytes.byteLength === 64) return require_encode.encode(skBytes.slice(32, 64), encoding);
|
|
57
|
+
return require_encode.encode(_noble_ed25519.getPublicKey(skBytes), encoding);
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
54
60
|
* Sign a message and get the signature hex
|
|
@@ -58,9 +64,9 @@ var Ed25519Signer = class extends require_protocols_signer.default {
|
|
|
58
64
|
* @returns {string} hex encoded signature
|
|
59
65
|
*/
|
|
60
66
|
sign(message, sk, encoding = "hex") {
|
|
61
|
-
const
|
|
67
|
+
const seed = (0, _ocap_util.toUint8Array)(sk).slice(0, 32);
|
|
62
68
|
const messageBytes = (0, _ocap_util.toUint8Array)(message);
|
|
63
|
-
return require_encode.encode(
|
|
69
|
+
return require_encode.encode(_noble_ed25519.sign(messageBytes, seed), encoding);
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
72
|
* Verify if a signature is valid
|
|
@@ -74,7 +80,7 @@ var Ed25519Signer = class extends require_protocols_signer.default {
|
|
|
74
80
|
const pkBytes = (0, _ocap_util.toUint8Array)(pk);
|
|
75
81
|
const messageBytes = (0, _ocap_util.toUint8Array)(message);
|
|
76
82
|
const signatureBytes = (0, _ocap_util.toUint8Array)(signature);
|
|
77
|
-
return
|
|
83
|
+
return _noble_ed25519.verify(signatureBytes, messageBytes, pkBytes);
|
|
78
84
|
}
|
|
79
85
|
};
|
|
80
86
|
var ed25519_default = new Ed25519Signer();
|
package/lib/signer/ed25519.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { BytesType, EncodingType, KeyPairType } from "@ocap/util";
|
|
|
4
4
|
//#region src/signer/ed25519.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Signer implementation for ed25519, based on `
|
|
7
|
+
* Signer implementation for ed25519, based on `@noble/ed25519`
|
|
8
8
|
*
|
|
9
9
|
* @class Ed25519Signer
|
|
10
10
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/mcrypto",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Crypto lib that provides signer,crypter,hasher interface",
|
|
6
6
|
"keywords": [
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"esm"
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@ocap/e2e-test": "1.29.
|
|
51
|
+
"@ocap/e2e-test": "1.29.5",
|
|
52
52
|
"@types/crypto-js": "^4.2.2",
|
|
53
53
|
"@types/elliptic": "^6.4.18",
|
|
54
54
|
"@types/node": "^22.7.5",
|
|
@@ -73,7 +73,8 @@
|
|
|
73
73
|
"url": "https://github.com/ArcBlock/blockchain/issues"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@
|
|
76
|
+
"@noble/ed25519": "^3.0.0",
|
|
77
|
+
"@ocap/util": "1.29.5",
|
|
77
78
|
"@simplewebauthn/server": "^13.0.0",
|
|
78
79
|
"bn.js": "5.2.2",
|
|
79
80
|
"crypto-js": "^4.2.0",
|
|
@@ -82,8 +83,7 @@
|
|
|
82
83
|
"hash.js": "^1.1.7",
|
|
83
84
|
"interface": "^1.2.1",
|
|
84
85
|
"js-sha3": "^0.8.0",
|
|
85
|
-
"randombytes": "^2.1.0"
|
|
86
|
-
"tweetnacl": "^1.0.3"
|
|
86
|
+
"randombytes": "^2.1.0"
|
|
87
87
|
},
|
|
88
88
|
"resolutions": {
|
|
89
89
|
"bn.js": "5.2.2",
|