@ocap/mcrypto 1.28.6 → 1.28.8
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/README.md +1 -1
- package/esm/crypter/aes-legacy.mjs +2 -2
- package/esm/crypter/aes.mjs +1 -1
- package/esm/crypter/rsa.d.mts +1 -1
- package/esm/crypter/rsa.mjs +1 -1
- package/esm/hasher/keccak.mjs +1 -1
- package/esm/hasher/sha2.mjs +1 -1
- package/esm/hasher/sha3.mjs +1 -1
- package/esm/signer/ed25519.d.mts +0 -1
- package/esm/signer/ed25519.mjs +0 -3
- package/esm/signer/passkey.d.mts +3 -4
- package/esm/signer/passkey.mjs +3 -6
- package/esm/signer/secp256k1.mjs +2 -2
- package/lib/crypter/aes-legacy.cjs +4 -4
- package/lib/crypter/aes.cjs +4 -4
- package/lib/crypter/rsa.cjs +5 -5
- package/lib/crypter/rsa.d.cts +1 -1
- package/lib/hasher/keccak.cjs +1 -1
- package/lib/hasher/sha2.cjs +1 -1
- package/lib/hasher/sha3.cjs +1 -1
- package/lib/signer/ed25519.cjs +0 -3
- package/lib/signer/ed25519.d.cts +0 -1
- package/lib/signer/passkey.cjs +3 -6
- package/lib/signer/passkey.d.cts +3 -4
- package/lib/signer/secp256k1.cjs +2 -2
- package/package.json +15 -19
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import crypter_default from "../protocols/crypter.mjs";
|
|
2
2
|
import AES from "crypto-js/aes.js";
|
|
3
|
+
import encBase64 from "crypto-js/enc-base64.js";
|
|
4
|
+
import encHex from "crypto-js/enc-hex.js";
|
|
3
5
|
import encLatin1 from "crypto-js/enc-latin1.js";
|
|
4
6
|
import encUtf8 from "crypto-js/enc-utf8.js";
|
|
5
7
|
import encUtf16 from "crypto-js/enc-utf16.js";
|
|
6
|
-
import encBase64 from "crypto-js/enc-base64.js";
|
|
7
|
-
import encHex from "crypto-js/enc-hex.js";
|
|
8
8
|
|
|
9
9
|
//#region src/crypter/aes-legacy.ts
|
|
10
10
|
const encoders = {
|
package/esm/crypter/aes.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { encode } from "../encode.mjs";
|
|
|
2
2
|
import sha3_default from "../hasher/sha3.mjs";
|
|
3
3
|
import crypter_default from "../protocols/crypter.mjs";
|
|
4
4
|
import { toBuffer } from "@ocap/util";
|
|
5
|
-
import crypto from "crypto";
|
|
5
|
+
import crypto from "node:crypto";
|
|
6
6
|
|
|
7
7
|
//#region src/crypter/aes.ts
|
|
8
8
|
var AesCrypter = class extends crypter_default {
|
package/esm/crypter/rsa.d.mts
CHANGED
package/esm/crypter/rsa.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { encode } from "../encode.mjs";
|
|
2
2
|
import crypter_default from "../protocols/crypter.mjs";
|
|
3
3
|
import { toBuffer } from "@ocap/util";
|
|
4
|
-
import crypto from "crypto";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
5
|
|
|
6
6
|
//#region src/crypter/rsa.ts
|
|
7
7
|
var RSACrypter = class extends crypter_default {
|
package/esm/hasher/keccak.mjs
CHANGED
package/esm/hasher/sha2.mjs
CHANGED
|
@@ -29,7 +29,7 @@ var Sha2Hasher = class {
|
|
|
29
29
|
let inputBytes = input;
|
|
30
30
|
try {
|
|
31
31
|
inputBytes = toUint8Array(input);
|
|
32
|
-
} catch (
|
|
32
|
+
} catch (_err) {}
|
|
33
33
|
if (round === 1) return `0x${hasher().update(inputBytes).digest("hex")}`;
|
|
34
34
|
return hashFn(hashFn(inputBytes, 1), round - 1);
|
|
35
35
|
};
|
package/esm/hasher/sha3.mjs
CHANGED
package/esm/signer/ed25519.d.mts
CHANGED
package/esm/signer/ed25519.mjs
CHANGED
package/esm/signer/passkey.d.mts
CHANGED
|
@@ -11,10 +11,9 @@ import { BytesType, EncodingType, KeyPairType } from "@ocap/util";
|
|
|
11
11
|
* @class PasskeySigner
|
|
12
12
|
*/
|
|
13
13
|
declare class PasskeySigner extends _default$1 {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
sign(message: BytesType, sk: BytesType, encoding?: EncodingType): BytesType;
|
|
14
|
+
genKeyPair(_encoding?: EncodingType, _userSeed?: BytesType): KeyPairType;
|
|
15
|
+
getPublicKey(_sk: BytesType, _encoding?: EncodingType): BytesType;
|
|
16
|
+
sign(_message: BytesType, _sk: BytesType, _encoding?: EncodingType): BytesType;
|
|
18
17
|
/**
|
|
19
18
|
* Verify if a signature is valid
|
|
20
19
|
*
|
package/esm/signer/passkey.mjs
CHANGED
|
@@ -11,16 +11,13 @@ import { decodeClientDataJSON, isoBase64URL, isoUint8Array, toHash, verifySignat
|
|
|
11
11
|
* @class PasskeySigner
|
|
12
12
|
*/
|
|
13
13
|
var PasskeySigner = class extends signer_default {
|
|
14
|
-
|
|
15
|
-
super();
|
|
16
|
-
}
|
|
17
|
-
genKeyPair(encoding = "hex", userSeed) {
|
|
14
|
+
genKeyPair(_encoding = "hex", _userSeed) {
|
|
18
15
|
throw new Error("Not supported");
|
|
19
16
|
}
|
|
20
|
-
getPublicKey(
|
|
17
|
+
getPublicKey(_sk, _encoding = "hex") {
|
|
21
18
|
throw new Error("Not supported");
|
|
22
19
|
}
|
|
23
|
-
sign(
|
|
20
|
+
sign(_message, _sk, _encoding = "hex") {
|
|
24
21
|
throw new Error("Not supported");
|
|
25
22
|
}
|
|
26
23
|
/**
|
package/esm/signer/secp256k1.mjs
CHANGED
|
@@ -60,7 +60,7 @@ var Secp256k1Signer = class extends signer_default {
|
|
|
60
60
|
let msg = message;
|
|
61
61
|
try {
|
|
62
62
|
msg = toUint8Array(message);
|
|
63
|
-
} catch (
|
|
63
|
+
} catch (_err) {}
|
|
64
64
|
return encode(`0x${secp256k1.keyFromPrivate(toBuffer(sk)).sign(stripHexPrefix(msg), { canonical: true }).toDER("hex")}`, encoding);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
@@ -70,7 +70,7 @@ var Secp256k1Signer = class extends signer_default {
|
|
|
70
70
|
let msg = message;
|
|
71
71
|
try {
|
|
72
72
|
msg = toUint8Array(message);
|
|
73
|
-
} catch (
|
|
73
|
+
} catch (_err) {}
|
|
74
74
|
let pkBuffer = toBuffer(pk);
|
|
75
75
|
if (this.pkHasFormatPrefix === false && pkBuffer[0] !== 4 && pkBuffer.byteLength === 64) pkBuffer = Buffer.concat([Buffer.from([4]), pkBuffer]);
|
|
76
76
|
return secp256k1.keyFromPublic(pkBuffer).verify(stripHexPrefix(msg), stripHexPrefix(toHex(signature)));
|
|
@@ -3,16 +3,16 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_protocols_crypter = require('../protocols/crypter.cjs');
|
|
4
4
|
let crypto_js_aes = require("crypto-js/aes");
|
|
5
5
|
crypto_js_aes = require_rolldown_runtime.__toESM(crypto_js_aes);
|
|
6
|
+
let crypto_js_enc_base64 = require("crypto-js/enc-base64");
|
|
7
|
+
crypto_js_enc_base64 = require_rolldown_runtime.__toESM(crypto_js_enc_base64);
|
|
8
|
+
let crypto_js_enc_hex = require("crypto-js/enc-hex");
|
|
9
|
+
crypto_js_enc_hex = require_rolldown_runtime.__toESM(crypto_js_enc_hex);
|
|
6
10
|
let crypto_js_enc_latin1 = require("crypto-js/enc-latin1");
|
|
7
11
|
crypto_js_enc_latin1 = require_rolldown_runtime.__toESM(crypto_js_enc_latin1);
|
|
8
12
|
let crypto_js_enc_utf8 = require("crypto-js/enc-utf8");
|
|
9
13
|
crypto_js_enc_utf8 = require_rolldown_runtime.__toESM(crypto_js_enc_utf8);
|
|
10
14
|
let crypto_js_enc_utf16 = require("crypto-js/enc-utf16");
|
|
11
15
|
crypto_js_enc_utf16 = require_rolldown_runtime.__toESM(crypto_js_enc_utf16);
|
|
12
|
-
let crypto_js_enc_base64 = require("crypto-js/enc-base64");
|
|
13
|
-
crypto_js_enc_base64 = require_rolldown_runtime.__toESM(crypto_js_enc_base64);
|
|
14
|
-
let crypto_js_enc_hex = require("crypto-js/enc-hex");
|
|
15
|
-
crypto_js_enc_hex = require_rolldown_runtime.__toESM(crypto_js_enc_hex);
|
|
16
16
|
|
|
17
17
|
//#region src/crypter/aes-legacy.ts
|
|
18
18
|
const encoders = {
|
package/lib/crypter/aes.cjs
CHANGED
|
@@ -4,21 +4,21 @@ const require_encode = require('../encode.cjs');
|
|
|
4
4
|
const require_hasher_sha3 = require('../hasher/sha3.cjs');
|
|
5
5
|
const require_protocols_crypter = require('../protocols/crypter.cjs');
|
|
6
6
|
let _ocap_util = require("@ocap/util");
|
|
7
|
-
let
|
|
8
|
-
|
|
7
|
+
let node_crypto = require("node:crypto");
|
|
8
|
+
node_crypto = require_rolldown_runtime.__toESM(node_crypto);
|
|
9
9
|
|
|
10
10
|
//#region src/crypter/aes.ts
|
|
11
11
|
var AesCrypter = class extends require_protocols_crypter.default {
|
|
12
12
|
encrypt(message, secret, encoding = "hex") {
|
|
13
13
|
const key = require_hasher_sha3.default.hash256(secret, 1, "buffer");
|
|
14
|
-
const cipher =
|
|
14
|
+
const cipher = node_crypto.default.createCipheriv("aes-256-ecb", key, "");
|
|
15
15
|
cipher.setAutoPadding(true);
|
|
16
16
|
const output = cipher.update((0, _ocap_util.toBuffer)(message));
|
|
17
17
|
return require_encode.encode(Buffer.concat([output, cipher.final()]), encoding);
|
|
18
18
|
}
|
|
19
19
|
decrypt(message, secret, encoding = "hex") {
|
|
20
20
|
const key = require_hasher_sha3.default.hash256(secret, 1, "buffer");
|
|
21
|
-
const decipher =
|
|
21
|
+
const decipher = node_crypto.default.createDecipheriv("aes-256-ecb", key, "");
|
|
22
22
|
decipher.setAutoPadding(true);
|
|
23
23
|
const output = decipher.update((0, _ocap_util.toBuffer)(message));
|
|
24
24
|
return require_encode.encode(Buffer.concat([output, decipher.final()]), encoding);
|
package/lib/crypter/rsa.cjs
CHANGED
|
@@ -3,13 +3,13 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_encode = require('../encode.cjs');
|
|
4
4
|
const require_protocols_crypter = require('../protocols/crypter.cjs');
|
|
5
5
|
let _ocap_util = require("@ocap/util");
|
|
6
|
-
let
|
|
7
|
-
|
|
6
|
+
let node_crypto = require("node:crypto");
|
|
7
|
+
node_crypto = require_rolldown_runtime.__toESM(node_crypto);
|
|
8
8
|
|
|
9
9
|
//#region src/crypter/rsa.ts
|
|
10
10
|
var RSACrypter = class extends require_protocols_crypter.default {
|
|
11
11
|
genKeyPair(length = 2048) {
|
|
12
|
-
return
|
|
12
|
+
return node_crypto.default.generateKeyPairSync("rsa", {
|
|
13
13
|
modulusLength: length,
|
|
14
14
|
publicKeyEncoding: {
|
|
15
15
|
type: "spki",
|
|
@@ -22,10 +22,10 @@ var RSACrypter = class extends require_protocols_crypter.default {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
encrypt(message, key, encoding = "hex") {
|
|
25
|
-
return require_encode.encode(
|
|
25
|
+
return require_encode.encode(node_crypto.default.publicEncrypt(key, (0, _ocap_util.toBuffer)(message)), encoding);
|
|
26
26
|
}
|
|
27
27
|
decrypt(message, key, encoding = "hex") {
|
|
28
|
-
return require_encode.encode(
|
|
28
|
+
return require_encode.encode(node_crypto.default.privateDecrypt(key, (0, _ocap_util.toBuffer)(message)), encoding);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
var rsa_default = new RSACrypter();
|
package/lib/crypter/rsa.d.cts
CHANGED
package/lib/hasher/keccak.cjs
CHANGED
package/lib/hasher/sha2.cjs
CHANGED
|
@@ -30,7 +30,7 @@ var Sha2Hasher = class {
|
|
|
30
30
|
let inputBytes = input;
|
|
31
31
|
try {
|
|
32
32
|
inputBytes = (0, _ocap_util.toUint8Array)(input);
|
|
33
|
-
} catch (
|
|
33
|
+
} catch (_err) {}
|
|
34
34
|
if (round === 1) return `0x${hasher().update(inputBytes).digest("hex")}`;
|
|
35
35
|
return hashFn(hashFn(inputBytes, 1), round - 1);
|
|
36
36
|
};
|
package/lib/hasher/sha3.cjs
CHANGED
package/lib/signer/ed25519.cjs
CHANGED
package/lib/signer/ed25519.d.cts
CHANGED
package/lib/signer/passkey.cjs
CHANGED
|
@@ -13,16 +13,13 @@ let _simplewebauthn_server_helpers = require("@simplewebauthn/server/helpers");
|
|
|
13
13
|
* @class PasskeySigner
|
|
14
14
|
*/
|
|
15
15
|
var PasskeySigner = class extends require_protocols_signer.default {
|
|
16
|
-
|
|
17
|
-
super();
|
|
18
|
-
}
|
|
19
|
-
genKeyPair(encoding = "hex", userSeed) {
|
|
16
|
+
genKeyPair(_encoding = "hex", _userSeed) {
|
|
20
17
|
throw new Error("Not supported");
|
|
21
18
|
}
|
|
22
|
-
getPublicKey(
|
|
19
|
+
getPublicKey(_sk, _encoding = "hex") {
|
|
23
20
|
throw new Error("Not supported");
|
|
24
21
|
}
|
|
25
|
-
sign(
|
|
22
|
+
sign(_message, _sk, _encoding = "hex") {
|
|
26
23
|
throw new Error("Not supported");
|
|
27
24
|
}
|
|
28
25
|
/**
|
package/lib/signer/passkey.d.cts
CHANGED
|
@@ -11,10 +11,9 @@ import { BytesType, EncodingType, KeyPairType } from "@ocap/util";
|
|
|
11
11
|
* @class PasskeySigner
|
|
12
12
|
*/
|
|
13
13
|
declare class PasskeySigner extends _default$1 {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
sign(message: BytesType, sk: BytesType, encoding?: EncodingType): BytesType;
|
|
14
|
+
genKeyPair(_encoding?: EncodingType, _userSeed?: BytesType): KeyPairType;
|
|
15
|
+
getPublicKey(_sk: BytesType, _encoding?: EncodingType): BytesType;
|
|
16
|
+
sign(_message: BytesType, _sk: BytesType, _encoding?: EncodingType): BytesType;
|
|
18
17
|
/**
|
|
19
18
|
* Verify if a signature is valid
|
|
20
19
|
*
|
package/lib/signer/secp256k1.cjs
CHANGED
|
@@ -64,7 +64,7 @@ var Secp256k1Signer = class extends require_protocols_signer.default {
|
|
|
64
64
|
let msg = message;
|
|
65
65
|
try {
|
|
66
66
|
msg = (0, _ocap_util.toUint8Array)(message);
|
|
67
|
-
} catch (
|
|
67
|
+
} catch (_err) {}
|
|
68
68
|
return require_encode.encode(`0x${secp256k1.keyFromPrivate((0, _ocap_util.toBuffer)(sk)).sign((0, _ocap_util.stripHexPrefix)(msg), { canonical: true }).toDER("hex")}`, encoding);
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
@@ -74,7 +74,7 @@ var Secp256k1Signer = class extends require_protocols_signer.default {
|
|
|
74
74
|
let msg = message;
|
|
75
75
|
try {
|
|
76
76
|
msg = (0, _ocap_util.toUint8Array)(message);
|
|
77
|
-
} catch (
|
|
77
|
+
} catch (_err) {}
|
|
78
78
|
let pkBuffer = (0, _ocap_util.toBuffer)(pk);
|
|
79
79
|
if (this.pkHasFormatPrefix === false && pkBuffer[0] !== 4 && pkBuffer.byteLength === 64) pkBuffer = Buffer.concat([Buffer.from([4]), pkBuffer]);
|
|
80
80
|
return secp256k1.keyFromPublic(pkBuffer).verify((0, _ocap_util.stripHexPrefix)(msg), (0, _ocap_util.stripHexPrefix)((0, _ocap_util.toHex)(signature)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/mcrypto",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Crypto lib that provides signer,crypter,hasher interface",
|
|
6
6
|
"keywords": [
|
|
@@ -48,27 +48,33 @@
|
|
|
48
48
|
"esm"
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@
|
|
51
|
+
"@ocap/e2e-test": "1.28.8",
|
|
52
52
|
"@types/crypto-js": "^4.2.2",
|
|
53
53
|
"@types/elliptic": "^6.4.18",
|
|
54
54
|
"@types/node": "^22.7.5",
|
|
55
55
|
"@types/randombytes": "^2.0.3",
|
|
56
|
-
"eslint": "^8.57.0",
|
|
57
|
-
"jest": "^29.7.0",
|
|
58
|
-
"ts-jest": "^29.2.5",
|
|
59
56
|
"tsdown": "^0.18.4",
|
|
60
57
|
"type-fest": "^3.1.0",
|
|
61
|
-
"typescript": "^5.6.2"
|
|
62
|
-
"@ocap/e2e-test": "1.28.6"
|
|
58
|
+
"typescript": "^5.6.2"
|
|
63
59
|
},
|
|
64
60
|
"repository": {
|
|
65
61
|
"type": "git",
|
|
66
62
|
"url": "git+https://github.com/ArcBlock/blockchain.git"
|
|
67
63
|
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"lint": "biome check",
|
|
66
|
+
"lint:fix": "biome check --write",
|
|
67
|
+
"prepush": "CI=1 npm run test",
|
|
68
|
+
"test": "bun test",
|
|
69
|
+
"coverage": "npm run test -- --coverage",
|
|
70
|
+
"build": "tsdown",
|
|
71
|
+
"build:watch": "tsdown -w"
|
|
72
|
+
},
|
|
68
73
|
"bugs": {
|
|
69
74
|
"url": "https://github.com/ArcBlock/blockchain/issues"
|
|
70
75
|
},
|
|
71
76
|
"dependencies": {
|
|
77
|
+
"@ocap/util": "1.28.8",
|
|
72
78
|
"@simplewebauthn/server": "^13.0.0",
|
|
73
79
|
"bn.js": "5.2.2",
|
|
74
80
|
"crypto-js": "^4.2.0",
|
|
@@ -78,20 +84,10 @@
|
|
|
78
84
|
"interface": "^1.2.1",
|
|
79
85
|
"js-sha3": "^0.8.0",
|
|
80
86
|
"randombytes": "^2.1.0",
|
|
81
|
-
"tweetnacl": "^1.0.3"
|
|
82
|
-
"@ocap/util": "1.28.6"
|
|
87
|
+
"tweetnacl": "^1.0.3"
|
|
83
88
|
},
|
|
84
89
|
"resolutions": {
|
|
85
90
|
"bn.js": "5.2.2",
|
|
86
91
|
"elliptic": "6.5.3"
|
|
87
|
-
},
|
|
88
|
-
"scripts": {
|
|
89
|
-
"lint": "eslint src tests",
|
|
90
|
-
"lint:fix": "npm run lint -- --fix",
|
|
91
|
-
"prepush": "CI=1 npm run test",
|
|
92
|
-
"test": "jest --forceExit --detectOpenHandles",
|
|
93
|
-
"coverage": "npm run test -- --coverage",
|
|
94
|
-
"build": "tsdown",
|
|
95
|
-
"build:watch": "tsdown -w"
|
|
96
92
|
}
|
|
97
|
-
}
|
|
93
|
+
}
|