@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
package/esm/hasher/sha3.js
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { toUint8Array } from
|
|
3
|
-
import
|
|
1
|
+
import { encode } from "../encode.js";
|
|
2
|
+
import { toUint8Array } from "@ocap/util";
|
|
3
|
+
import sha3 from "js-sha3";
|
|
4
|
+
|
|
5
|
+
//#region src/hasher/sha3.ts
|
|
4
6
|
/**
|
|
5
|
-
|
|
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
|
-
export default
|
|
37
|
-
export { Sha3Hasher };
|
|
7
|
+
* Sha3 support with different hash length
|
|
8
|
+
*
|
|
9
|
+
* @class Sha3Hasher
|
|
10
|
+
*/
|
|
11
|
+
var Sha3Hasher = class {
|
|
12
|
+
constructor() {
|
|
13
|
+
[
|
|
14
|
+
224,
|
|
15
|
+
256,
|
|
16
|
+
384,
|
|
17
|
+
512
|
|
18
|
+
].forEach((x) => {
|
|
19
|
+
const name = `hash${x}`;
|
|
20
|
+
const hasher = sha3[`sha3_${x}`];
|
|
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 sha3_default = new Sha3Hasher();
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { Sha3Hasher, sha3_default as default };
|
package/esm/index.d.ts
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { KeccakHasher } from "./hasher/keccak.js";
|
|
2
|
+
import { Sha2Hasher } from "./hasher/sha2.js";
|
|
3
|
+
import { Sha3Hasher } from "./hasher/sha3.js";
|
|
4
|
+
import { Ed25519Signer } from "./signer/ed25519.js";
|
|
5
|
+
import { Secp256k1Signer } from "./signer/secp256k1.js";
|
|
6
|
+
import { EthereumSigner } from "./signer/ethereum.js";
|
|
7
|
+
import { PasskeySigner } from "./signer/passkey.js";
|
|
8
|
+
import { BytesType, EncodingType, KeyPairType } from "@ocap/util";
|
|
9
|
+
import { LiteralUnion } from "type-fest";
|
|
10
|
+
|
|
11
|
+
//#region src/index.d.ts
|
|
12
|
+
type KeyType = LiteralUnion<'ED25519' | 'SECP256K1' | 'ETHEREUM', string>;
|
|
13
|
+
type HashType = LiteralUnion<'KECCAK' | 'SHA3' | 'KECCAK_384' | 'SHA3_384' | 'KECCAK_512' | 'SHA3_512' | 'SHA2', string>;
|
|
14
|
+
type RoleType = LiteralUnion<'ROLE_ACCOUNT' | 'ROLE_NODE' | 'ROLE_DEVICE' | 'ROLE_APPLICATION' | 'ROLE_SMART_CONTRACT' | 'ROLE_BOT' | 'ROLE_ASSET' | 'ROLE_STAKE' | 'ROLE_VALIDATOR' | 'ROLE_GROUP' | 'ROLE_GROUP' | 'ROLE_TX' | 'ROLE_TETHER' | 'ROLE_SWAP' | 'ROLE_DELEGATION' | 'ROLE_VC' | 'ROLE_BLOCKLET' | 'ROLE_STORE' | 'ROLE_TOKEN' | 'ROLE_FACTORY' | 'ROLE_ROLLUP' | 'ROLE_STORAGE' | 'ROLE_PROFILE' | 'ROLE_PASSKEY' | 'ROLE_TOKEN_FACTORY' | 'ROLE_ANY', string>;
|
|
15
|
+
type AddressType = LiteralUnion<'BASE16' | 'BASE58', string>;
|
|
16
|
+
interface HashFnType {
|
|
17
|
+
(data: BytesType, round: number, encoding?: 'hex'): string;
|
|
18
|
+
(data: BytesType, round: number, encoding?: 'base16'): string;
|
|
19
|
+
(data: BytesType, round: number, encoding?: 'base58'): string;
|
|
20
|
+
(data: BytesType, round: number, encoding?: 'base64'): string;
|
|
21
|
+
(data: BytesType, round: number, encoding?: 'buffer'): Buffer;
|
|
22
|
+
(data: BytesType, round: number, encoding?: 'Uint8Array'): Uint8Array;
|
|
23
|
+
(data: BytesType, round: number, encoding?: EncodingType): BytesType;
|
|
15
24
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
interface SignerType {
|
|
26
|
+
genKeyPair(encoding?: EncodingType, seed?: BytesType): KeyPairType;
|
|
27
|
+
getPublicKey(sk: BytesType, encoding?: 'hex'): string;
|
|
28
|
+
getPublicKey(sk: BytesType, encoding?: 'base16'): string;
|
|
29
|
+
getPublicKey(sk: BytesType, encoding?: 'base58'): string;
|
|
30
|
+
getPublicKey(sk: BytesType, encoding?: 'base64'): string;
|
|
31
|
+
getPublicKey(sk: BytesType, encoding?: 'buffer'): Buffer;
|
|
32
|
+
getPublicKey(sk: BytesType, encoding?: 'Uint8Array'): Uint8Array;
|
|
33
|
+
getPublicKey(sk: BytesType, encoding?: EncodingType): BytesType;
|
|
34
|
+
sign(data: BytesType, sk: BytesType, encoding?: 'hex'): string;
|
|
35
|
+
sign(data: BytesType, sk: BytesType, encoding?: 'base16'): string;
|
|
36
|
+
sign(data: BytesType, sk: BytesType, encoding?: 'base58'): string;
|
|
37
|
+
sign(data: BytesType, sk: BytesType, encoding?: 'base64'): string;
|
|
38
|
+
sign(data: BytesType, sk: BytesType, encoding?: 'buffer'): Buffer;
|
|
39
|
+
sign(data: BytesType, sk: BytesType, encoding?: 'Uint8Array'): Uint8Array;
|
|
40
|
+
sign(data: BytesType, sk: BytesType, encoding?: EncodingType): BytesType;
|
|
41
|
+
verify(data: BytesType, pk: BytesType, signature: BytesType, extra?: any): boolean;
|
|
42
|
+
ethHash?(data: string): string;
|
|
43
|
+
ethSign?(data: string, sk: string): string;
|
|
44
|
+
ethVerify?(data: string, pk: string, signature: BytesType): boolean;
|
|
45
|
+
ethRecover?(hash: string, signature: string): string;
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
48
|
* Contains all supported signers, eg: `Ed25519` and `Secp256k1`
|
|
@@ -52,11 +61,11 @@ export interface SignerType {
|
|
|
52
61
|
* const result = Signer.Ed25519.verify(message, signature, keyPair.publicKey);
|
|
53
62
|
* assert.ok(result);
|
|
54
63
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
declare const Signer: {
|
|
65
|
+
Ed25519: Ed25519Signer;
|
|
66
|
+
Secp256k1: Secp256k1Signer;
|
|
67
|
+
Ethereum: EthereumSigner;
|
|
68
|
+
Passkey: PasskeySigner;
|
|
60
69
|
};
|
|
61
70
|
/**
|
|
62
71
|
* Contains all supported hasher, eg: `SHA2`,`SHA3` and `Keccak`, each of them supports `hash224`, `hash256`, `hash384`, `hash512`
|
|
@@ -71,10 +80,10 @@ export declare const Signer: {
|
|
|
71
80
|
* const message = 'message to hash';
|
|
72
81
|
* const hash = Hasher.SHA2.hash256(message);
|
|
73
82
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
declare const Hasher: {
|
|
84
|
+
SHA2: Sha2Hasher;
|
|
85
|
+
SHA3: Sha3Hasher;
|
|
86
|
+
Keccak: KeccakHasher;
|
|
78
87
|
};
|
|
79
88
|
/**
|
|
80
89
|
* Contains type constants that represent can be used to compose different crypto method, each crypto method consist one of:
|
|
@@ -92,89 +101,89 @@ export declare const Hasher: {
|
|
|
92
101
|
* // types.HashType.SHA3
|
|
93
102
|
* // types.EncodingType.BASE58
|
|
94
103
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
104
|
+
declare const types: {
|
|
105
|
+
/**
|
|
106
|
+
* Key-pair derivation algorithms
|
|
107
|
+
*
|
|
108
|
+
* @readonly
|
|
109
|
+
* @enum {number}
|
|
110
|
+
* @name types.KeyType
|
|
111
|
+
* @memberof types
|
|
112
|
+
* @static
|
|
113
|
+
*/
|
|
114
|
+
KeyType: {
|
|
115
|
+
ED25519: number;
|
|
116
|
+
SECP256K1: number;
|
|
117
|
+
ETHEREUM: number;
|
|
118
|
+
PASSKEY: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Hashing algorithms
|
|
122
|
+
*
|
|
123
|
+
* @readonly
|
|
124
|
+
* @enum {number}
|
|
125
|
+
* @name types.HashType
|
|
126
|
+
* @memberof types
|
|
127
|
+
* @static
|
|
128
|
+
*/
|
|
129
|
+
HashType: {
|
|
130
|
+
KECCAK: number;
|
|
131
|
+
SHA3: number;
|
|
132
|
+
KECCAK_384: number;
|
|
133
|
+
SHA3_384: number;
|
|
134
|
+
KECCAK_512: number;
|
|
135
|
+
SHA3_512: number;
|
|
136
|
+
SHA2: number;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* DID wallet role type
|
|
140
|
+
*
|
|
141
|
+
* @readonly
|
|
142
|
+
* @enum {number}
|
|
143
|
+
* @name types.RoleType
|
|
144
|
+
* @memberof types
|
|
145
|
+
* @static
|
|
146
|
+
*/
|
|
147
|
+
RoleType: {
|
|
148
|
+
ROLE_ACCOUNT: number;
|
|
149
|
+
ROLE_NODE: number;
|
|
150
|
+
ROLE_DEVICE: number;
|
|
151
|
+
ROLE_APPLICATION: number;
|
|
152
|
+
ROLE_SMART_CONTRACT: number;
|
|
153
|
+
ROLE_BOT: number;
|
|
154
|
+
ROLE_ASSET: number;
|
|
155
|
+
ROLE_STAKE: number;
|
|
156
|
+
ROLE_VALIDATOR: number;
|
|
157
|
+
ROLE_GROUP: number;
|
|
158
|
+
ROLE_TX: number;
|
|
159
|
+
ROLE_TETHER: number;
|
|
160
|
+
ROLE_SWAP: number;
|
|
161
|
+
ROLE_DELEGATION: number;
|
|
162
|
+
ROLE_VC: number;
|
|
163
|
+
ROLE_BLOCKLET: number;
|
|
164
|
+
ROLE_STORE: number;
|
|
165
|
+
ROLE_TOKEN: number;
|
|
166
|
+
ROLE_FACTORY: number;
|
|
167
|
+
ROLE_ROLLUP: number;
|
|
168
|
+
ROLE_STORAGE: number;
|
|
169
|
+
ROLE_PROFILE: number;
|
|
170
|
+
ROLE_PASSKEY: number;
|
|
171
|
+
ROLE_TOKEN_FACTORY: number;
|
|
172
|
+
ROLE_ANY: number;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Address encoding algorithm, defaults to `base58btc`
|
|
176
|
+
*
|
|
177
|
+
* @readonly
|
|
178
|
+
* @enum {number}
|
|
179
|
+
* @name types.RoleType
|
|
180
|
+
* @memberof types
|
|
181
|
+
* @static
|
|
182
|
+
*/
|
|
183
|
+
EncodingType: {
|
|
184
|
+
BASE16: number;
|
|
185
|
+
BASE58: number;
|
|
186
|
+
};
|
|
178
187
|
};
|
|
179
188
|
/**
|
|
180
189
|
* Get signer instance
|
|
@@ -195,7 +204,7 @@ export declare const types: {
|
|
|
195
204
|
* const result1 = signer.verify(message, signature1, keyPair1.publicKey);
|
|
196
205
|
* assert.ok(result1);
|
|
197
206
|
*/
|
|
198
|
-
|
|
207
|
+
declare function getSigner(type: number): SignerType;
|
|
199
208
|
/**
|
|
200
209
|
* Get hasher instance
|
|
201
210
|
*
|
|
@@ -214,21 +223,17 @@ export declare function getSigner(type: number): SignerType;
|
|
|
214
223
|
* const hashFn = getHasher(types.HashType.SHA3);
|
|
215
224
|
* const hash2 = hashFn(message);
|
|
216
225
|
*/
|
|
217
|
-
|
|
226
|
+
declare function getHasher(type: number): HashFnType;
|
|
218
227
|
/**
|
|
219
228
|
* Get random bytes in specified encoding
|
|
220
229
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
export declare const Hashers: Readonly<{
|
|
232
|
-
[x: number]: (data: BytesType, round?: number, encoding?: EncodingType) => BytesType;
|
|
233
|
-
}>;
|
|
234
|
-
export declare const toTxHash: (buf: Buffer | Uint8Array) => string;
|
|
230
|
+
declare function getRandomBytes(length: number, encoding?: 'hex'): string;
|
|
231
|
+
declare function getRandomBytes(length: number, encoding?: 'base16'): string;
|
|
232
|
+
declare function getRandomBytes(length: number, encoding?: 'base58'): string;
|
|
233
|
+
declare function getRandomBytes(length: number, encoding?: 'base64'): string;
|
|
234
|
+
declare function getRandomBytes(length: number, encoding?: 'buffer'): Buffer;
|
|
235
|
+
declare function getRandomBytes(length: number, encoding?: 'Uint8Array'): Uint8Array;
|
|
236
|
+
declare function getRandomBytes(length: number, encoding?: EncodingType): BytesType;
|
|
237
|
+
declare const toTxHash: (buf: Buffer | Uint8Array) => string;
|
|
238
|
+
//#endregion
|
|
239
|
+
export { AddressType, HashFnType, HashType, Hasher, KeyType, RoleType, Signer, SignerType, getHasher, getRandomBytes, getSigner, toTxHash, types };
|