@ocap/mcrypto 1.27.16 → 1.28.1
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/crypter/aes-legacy.d.ts +8 -6
- package/esm/crypter/aes-legacy.js +27 -24
- package/esm/crypter/aes.d.ts +9 -7
- package/esm/crypter/aes.js +27 -25
- package/esm/crypter/rsa-browserify.d.ts +7 -6
- package/esm/crypter/rsa-browserify.js +34 -31
- package/esm/crypter/rsa.d.ts +11 -9
- package/esm/crypter/rsa.js +31 -28
- package/esm/encode.d.ts +12 -8
- package/esm/encode.js +13 -18
- package/esm/hasher/keccak.d.ts +8 -5
- package/esm/hasher/keccak.js +37 -36
- package/esm/hasher/sha2.d.ts +8 -5
- package/esm/hasher/sha2.js +42 -40
- package/esm/hasher/sha3.d.ts +8 -5
- package/esm/hasher/sha3.js +37 -36
- package/esm/index.d.ts +148 -143
- package/esm/index.js +172 -209
- package/esm/protocols/crypter.d.ts +3 -1
- package/esm/protocols/crypter.js +7 -4
- package/esm/protocols/hasher.d.ts +3 -1
- package/esm/protocols/hasher.js +7 -4
- package/esm/protocols/signer.d.ts +3 -1
- package/esm/protocols/signer.js +7 -4
- package/esm/signer/ed25519.d.ts +49 -46
- package/esm/signer/ed25519.js +80 -80
- package/esm/signer/ethereum.d.ts +11 -8
- package/esm/signer/ethereum.js +34 -34
- package/esm/signer/passkey.d.ts +21 -18
- package/esm/signer/passkey.js +49 -58
- package/esm/signer/secp256k1.d.ts +35 -32
- package/esm/signer/secp256k1.js +80 -93
- package/lib/_virtual/rolldown_runtime.js +29 -0
- package/lib/crypter/aes-legacy.d.ts +8 -6
- package/lib/crypter/aes-legacy.js +35 -52
- package/lib/crypter/aes.d.ts +9 -7
- package/lib/crypter/aes.js +29 -29
- package/lib/crypter/rsa-browserify.d.ts +7 -6
- package/lib/crypter/rsa-browserify.js +36 -33
- package/lib/crypter/rsa.d.ts +11 -9
- package/lib/crypter/rsa.js +33 -32
- package/lib/encode.d.ts +12 -8
- package/lib/encode.js +14 -21
- package/lib/hasher/keccak.d.ts +8 -5
- package/lib/hasher/keccak.js +40 -41
- package/lib/hasher/sha2.d.ts +8 -5
- package/lib/hasher/sha2.js +43 -42
- package/lib/hasher/sha3.d.ts +8 -5
- package/lib/hasher/sha3.js +40 -41
- package/lib/index.d.ts +148 -143
- package/lib/index.js +177 -216
- package/lib/protocols/crypter.d.ts +3 -1
- package/lib/protocols/crypter.js +10 -9
- package/lib/protocols/hasher.d.ts +3 -1
- package/lib/protocols/hasher.js +10 -9
- package/lib/protocols/signer.d.ts +3 -1
- package/lib/protocols/signer.js +10 -9
- package/lib/signer/ed25519.d.ts +49 -46
- package/lib/signer/ed25519.js +85 -86
- package/lib/signer/ethereum.d.ts +11 -8
- package/lib/signer/ethereum.js +38 -39
- package/lib/signer/passkey.d.ts +21 -18
- package/lib/signer/passkey.js +51 -63
- package/lib/signer/secp256k1.d.ts +35 -32
- package/lib/signer/secp256k1.js +85 -99
- package/package.json +21 -10
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import _default$1 from "../protocols/crypter.js";
|
|
2
|
+
|
|
3
|
+
//#region src/crypter/aes-legacy.d.ts
|
|
4
|
+
declare class AesCrypter extends _default$1 {
|
|
5
|
+
encrypt(message: string | object, secret: string): string;
|
|
6
|
+
decrypt(cipher: string, secret: string, outputEncoding?: string): string;
|
|
5
7
|
}
|
|
6
8
|
declare const _default: AesCrypter;
|
|
7
|
-
|
|
8
|
-
export { AesCrypter };
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AesCrypter, _default as default };
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import crypter_default from "../protocols/crypter.js";
|
|
2
|
+
import * as AES from "crypto-js/aes.js";
|
|
3
|
+
import encLatin1 from "crypto-js/enc-latin1.js";
|
|
4
|
+
import encUtf8 from "crypto-js/enc-utf8.js";
|
|
5
|
+
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
|
+
|
|
9
|
+
//#region src/crypter/aes-legacy.ts
|
|
8
10
|
const encoders = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
latin1: encLatin1,
|
|
12
|
+
utf8: encUtf8,
|
|
13
|
+
hex: encHex,
|
|
14
|
+
utf16: encUtf16,
|
|
15
|
+
base64: encBase64
|
|
14
16
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
var AesCrypter = class extends crypter_default {
|
|
18
|
+
encrypt(message, secret) {
|
|
19
|
+
const text = typeof message === "string" ? message : JSON.stringify(message);
|
|
20
|
+
return AES.encrypt(text, secret).toString();
|
|
21
|
+
}
|
|
22
|
+
decrypt(cipher, secret, outputEncoding = "utf8") {
|
|
23
|
+
return AES.decrypt(cipher, secret).toString(encoders[outputEncoding]);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var aes_legacy_default = new AesCrypter();
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { AesCrypter, aes_legacy_default as default };
|
package/esm/crypter/aes.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import _default$1 from "../protocols/crypter.js";
|
|
2
|
+
import { BytesType, EncodingType } from "@ocap/util";
|
|
3
|
+
|
|
4
|
+
//#region src/crypter/aes.d.ts
|
|
5
|
+
declare class AesCrypter extends _default$1 {
|
|
6
|
+
encrypt(message: BytesType, secret: BytesType, encoding?: EncodingType): BytesType;
|
|
7
|
+
decrypt(message: BytesType, secret: BytesType, encoding?: EncodingType): BytesType;
|
|
6
8
|
}
|
|
7
9
|
declare const _default: AesCrypter;
|
|
8
|
-
|
|
9
|
-
export { AesCrypter };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { AesCrypter, _default as default };
|
package/esm/crypter/aes.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { encode } from "../encode.js";
|
|
2
|
+
import sha3_default from "../hasher/sha3.js";
|
|
3
|
+
import crypter_default from "../protocols/crypter.js";
|
|
4
|
+
import { toBuffer } from "@ocap/util";
|
|
5
|
+
import crypto from "crypto";
|
|
6
|
+
|
|
7
|
+
//#region src/crypter/aes.ts
|
|
8
|
+
var AesCrypter = class extends crypter_default {
|
|
9
|
+
encrypt(message, secret, encoding = "hex") {
|
|
10
|
+
const key = sha3_default.hash256(secret, 1, "buffer");
|
|
11
|
+
const cipher = crypto.createCipheriv("aes-256-ecb", key, "");
|
|
12
|
+
cipher.setAutoPadding(true);
|
|
13
|
+
const output = cipher.update(toBuffer(message));
|
|
14
|
+
return encode(Buffer.concat([output, cipher.final()]), encoding);
|
|
15
|
+
}
|
|
16
|
+
decrypt(message, secret, encoding = "hex") {
|
|
17
|
+
const key = sha3_default.hash256(secret, 1, "buffer");
|
|
18
|
+
const decipher = crypto.createDecipheriv("aes-256-ecb", key, "");
|
|
19
|
+
decipher.setAutoPadding(true);
|
|
20
|
+
const output = decipher.update(toBuffer(message));
|
|
21
|
+
return encode(Buffer.concat([output, decipher.final()]), encoding);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var aes_default = new AesCrypter();
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { AesCrypter, aes_default as default };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
//#region src/crypter/rsa-browserify.d.ts
|
|
1
2
|
declare class RSABrowserCrypter {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
genKeyPair(length?: number): Promise<CryptoKeyPair>;
|
|
4
|
+
formatPublicKey(key: CryptoKey): Promise<string>;
|
|
5
|
+
encrypt(message: string, key: CryptoKey): Promise<string>;
|
|
6
|
+
decrypt(message: string, key: CryptoKey): Promise<string>;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: RSABrowserCrypter;
|
|
8
|
-
|
|
9
|
-
export { RSABrowserCrypter };
|
|
9
|
+
//#endregion
|
|
10
|
+
export { RSABrowserCrypter, _default as default };
|
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { fromBase58, toBase58 } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/crypter/rsa-browserify.ts
|
|
4
4
|
const crypto = window.crypto.subtle;
|
|
5
|
-
// @ts-ignore
|
|
6
5
|
const ab2str = (buffer) => String.fromCharCode.apply(null, new Uint8Array(buffer));
|
|
7
|
-
const RSA_ALGORITHM =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
6
|
+
const RSA_ALGORITHM = "RSA-OAEP";
|
|
7
|
+
var RSABrowserCrypter = class {
|
|
8
|
+
genKeyPair(length = 2048) {
|
|
9
|
+
return crypto.generateKey({
|
|
10
|
+
name: RSA_ALGORITHM,
|
|
11
|
+
modulusLength: length,
|
|
12
|
+
publicExponent: new Uint8Array([
|
|
13
|
+
1,
|
|
14
|
+
0,
|
|
15
|
+
1
|
|
16
|
+
]),
|
|
17
|
+
hash: "SHA-256"
|
|
18
|
+
}, true, ["encrypt", "decrypt"]);
|
|
19
|
+
}
|
|
20
|
+
async formatPublicKey(key) {
|
|
21
|
+
const exported = await crypto.exportKey("spki", key);
|
|
22
|
+
return `-----BEGIN PUBLIC KEY-----\n${window.btoa(ab2str(exported))}\n-----END PUBLIC KEY-----`;
|
|
23
|
+
}
|
|
24
|
+
async encrypt(message, key) {
|
|
25
|
+
const encrypted = await crypto.encrypt({ name: RSA_ALGORITHM }, key, new TextEncoder().encode(message));
|
|
26
|
+
return toBase58(new Uint8Array(encrypted));
|
|
27
|
+
}
|
|
28
|
+
async decrypt(message, key) {
|
|
29
|
+
const decrypted = await crypto.decrypt({ name: RSA_ALGORITHM }, key, fromBase58(message));
|
|
30
|
+
return Buffer.from(new Uint8Array(decrypted)).toString("utf8");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rsa_browserify_default = new RSABrowserCrypter();
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { RSABrowserCrypter, rsa_browserify_default as default };
|
package/esm/crypter/rsa.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BytesType, EncodingType } from
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import _default$1 from "../protocols/crypter.js";
|
|
2
|
+
import { BytesType, EncodingType } from "@ocap/util";
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
|
|
5
|
+
//#region src/crypter/rsa.d.ts
|
|
6
|
+
declare class RSACrypter extends _default$1 {
|
|
7
|
+
genKeyPair(length?: number): crypto.KeyPairSyncResult<string, string>;
|
|
8
|
+
encrypt(message: BytesType, key: string, encoding?: EncodingType): BytesType;
|
|
9
|
+
decrypt(message: BytesType, key: string, encoding?: EncodingType): BytesType;
|
|
8
10
|
}
|
|
9
11
|
declare const _default: RSACrypter;
|
|
10
|
-
|
|
11
|
-
export { RSACrypter };
|
|
12
|
+
//#endregion
|
|
13
|
+
export { RSACrypter, _default as default };
|
package/esm/crypter/rsa.js
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { encode } from "../encode.js";
|
|
2
|
+
import crypter_default from "../protocols/crypter.js";
|
|
3
|
+
import { toBuffer } from "@ocap/util";
|
|
4
|
+
import crypto from "crypto";
|
|
5
|
+
|
|
6
|
+
//#region src/crypter/rsa.ts
|
|
7
|
+
var RSACrypter = class extends crypter_default {
|
|
8
|
+
genKeyPair(length = 2048) {
|
|
9
|
+
return crypto.generateKeyPairSync("rsa", {
|
|
10
|
+
modulusLength: length,
|
|
11
|
+
publicKeyEncoding: {
|
|
12
|
+
type: "spki",
|
|
13
|
+
format: "pem"
|
|
14
|
+
},
|
|
15
|
+
privateKeyEncoding: {
|
|
16
|
+
type: "pkcs8",
|
|
17
|
+
format: "pem"
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
encrypt(message, key, encoding = "hex") {
|
|
22
|
+
return encode(crypto.publicEncrypt(key, toBuffer(message)), encoding);
|
|
23
|
+
}
|
|
24
|
+
decrypt(message, key, encoding = "hex") {
|
|
25
|
+
return encode(crypto.privateDecrypt(key, toBuffer(message)), encoding);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rsa_default = new RSACrypter();
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { RSACrypter, rsa_default as default };
|
package/esm/encode.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { BytesType, EncodingType } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { BytesType, EncodingType } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/encode.d.ts
|
|
4
|
+
declare function encode(data: BytesType, encoding?: 'hex'): string;
|
|
5
|
+
declare function encode(data: BytesType, encoding?: 'base16'): string;
|
|
6
|
+
declare function encode(data: BytesType, encoding?: 'base58'): string;
|
|
7
|
+
declare function encode(data: BytesType, encoding?: 'base64'): string;
|
|
8
|
+
declare function encode(data: BytesType, encoding?: 'buffer'): Buffer;
|
|
9
|
+
declare function encode(data: BytesType, encoding?: 'Uint8Array'): Uint8Array;
|
|
10
|
+
declare function encode(data: BytesType, encoding?: EncodingType): BytesType;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { encode };
|
package/esm/encode.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
if (encoding === 'Uint8Array') {
|
|
13
|
-
return toUint8Array(data);
|
|
14
|
-
}
|
|
15
|
-
if (encoding === 'buffer') {
|
|
16
|
-
return toBuffer(data);
|
|
17
|
-
}
|
|
18
|
-
return data;
|
|
1
|
+
import { toBase58, toBase64, toBuffer, toHex, toUint8Array } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/encode.ts
|
|
4
|
+
function encode(data, encoding = "hex") {
|
|
5
|
+
if (["hex", "base16"].includes(encoding)) return toHex(data);
|
|
6
|
+
if (encoding === "base58") return toBase58(data);
|
|
7
|
+
if (encoding === "base64") return toBase64(data);
|
|
8
|
+
if (encoding === "Uint8Array") return toUint8Array(data);
|
|
9
|
+
if (encoding === "buffer") return toBuffer(data);
|
|
10
|
+
return data;
|
|
19
11
|
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { encode };
|
package/esm/hasher/keccak.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { BytesType, EncodingType } from
|
|
1
|
+
import { BytesType, EncodingType } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/hasher/keccak.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Keccak support with different hash length
|
|
4
7
|
*
|
|
5
8
|
* @class KeccakHasher
|
|
6
9
|
*/
|
|
7
10
|
declare class KeccakHasher {
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
[x: string]: (data: BytesType, round?: number, encoding?: EncodingType) => BytesType;
|
|
12
|
+
constructor();
|
|
10
13
|
}
|
|
11
14
|
declare const _default: KeccakHasher;
|
|
12
|
-
|
|
13
|
-
export { KeccakHasher };
|
|
15
|
+
//#endregion
|
|
16
|
+
export { KeccakHasher, _default as default };
|
package/esm/hasher/keccak.js
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { encode } from "../encode.js";
|
|
2
|
+
import { toUint8Array } from "@ocap/util";
|
|
3
|
+
import sha3 from "js-sha3";
|
|
4
|
+
|
|
5
|
+
//#region src/hasher/keccak.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export { KeccakHasher };
|
|
7
|
+
* Keccak support with different hash length
|
|
8
|
+
*
|
|
9
|
+
* @class KeccakHasher
|
|
10
|
+
*/
|
|
11
|
+
var KeccakHasher = class {
|
|
12
|
+
constructor() {
|
|
13
|
+
[
|
|
14
|
+
224,
|
|
15
|
+
256,
|
|
16
|
+
384,
|
|
17
|
+
512
|
|
18
|
+
].forEach((x) => {
|
|
19
|
+
const name = `hash${x}`;
|
|
20
|
+
const hasher = (data) => sha3[`keccak${x}`](data);
|
|
21
|
+
const hashFn = (input, round) => {
|
|
22
|
+
if (round === 1) return hasher(input);
|
|
23
|
+
return hashFn(hasher(input), round - 1);
|
|
24
|
+
};
|
|
25
|
+
this[name] = (data, round = 1, encoding = "hex") => {
|
|
26
|
+
let input = data;
|
|
27
|
+
try {
|
|
28
|
+
input = toUint8Array(data);
|
|
29
|
+
} catch (err) {}
|
|
30
|
+
return encode(`0x${hashFn(input, round)}`, encoding);
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var keccak_default = new KeccakHasher();
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { KeccakHasher, keccak_default as default };
|
package/esm/hasher/sha2.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { BytesType, EncodingType } from
|
|
1
|
+
import { BytesType, EncodingType } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/hasher/sha2.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Sha2 support with different hash length
|
|
4
7
|
*
|
|
5
8
|
* @class
|
|
6
9
|
*/
|
|
7
10
|
declare class Sha2Hasher {
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
[x: string]: (data: BytesType, round?: number, encoding?: EncodingType) => BytesType;
|
|
12
|
+
constructor();
|
|
10
13
|
}
|
|
11
14
|
declare const _default: Sha2Hasher;
|
|
12
|
-
|
|
13
|
-
export { Sha2Hasher };
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Sha2Hasher, _default as default };
|
package/esm/hasher/sha2.js
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
import { toUint8Array } from
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { encode } from "../encode.js";
|
|
2
|
+
import { toUint8Array } from "@ocap/util";
|
|
3
|
+
import _hash_js from "hash.js";
|
|
4
|
+
const { sha224, sha256, sha384, sha512 } = _hash_js;
|
|
5
|
+
|
|
6
|
+
//#region src/hasher/sha2.ts
|
|
5
7
|
const hashFns = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
sha224,
|
|
9
|
+
sha256,
|
|
10
|
+
sha384,
|
|
11
|
+
sha512
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export { Sha2Hasher };
|
|
14
|
+
* Sha2 support with different hash length
|
|
15
|
+
*
|
|
16
|
+
* @class
|
|
17
|
+
*/
|
|
18
|
+
var Sha2Hasher = class {
|
|
19
|
+
constructor() {
|
|
20
|
+
[
|
|
21
|
+
224,
|
|
22
|
+
256,
|
|
23
|
+
384,
|
|
24
|
+
512
|
|
25
|
+
].forEach((x) => {
|
|
26
|
+
const name = `hash${x}`;
|
|
27
|
+
const hasher = hashFns[`sha${x}`];
|
|
28
|
+
const hashFn = (input, round) => {
|
|
29
|
+
let inputBytes = input;
|
|
30
|
+
try {
|
|
31
|
+
inputBytes = toUint8Array(input);
|
|
32
|
+
} catch (err) {}
|
|
33
|
+
if (round === 1) return `0x${hasher().update(inputBytes).digest("hex")}`;
|
|
34
|
+
return hashFn(hashFn(inputBytes, 1), round - 1);
|
|
35
|
+
};
|
|
36
|
+
this[name] = (data, round = 2, encoding = "hex") => {
|
|
37
|
+
return encode(hashFn(data, round), encoding);
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var sha2_default = new Sha2Hasher();
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { Sha2Hasher, sha2_default as default };
|
package/esm/hasher/sha3.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { BytesType, EncodingType } from
|
|
1
|
+
import { BytesType, EncodingType } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/hasher/sha3.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Sha3 support with different hash length
|
|
4
7
|
*
|
|
5
8
|
* @class Sha3Hasher
|
|
6
9
|
*/
|
|
7
10
|
declare class Sha3Hasher {
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
[x: string]: (data: BytesType, round?: number, encoding?: EncodingType) => BytesType;
|
|
12
|
+
constructor();
|
|
10
13
|
}
|
|
11
14
|
declare const _default: Sha3Hasher;
|
|
12
|
-
|
|
13
|
-
export { Sha3Hasher };
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Sha3Hasher, _default as default };
|