@twin.org/crypto 0.0.1-next.6 → 0.0.1-next.62

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.
Files changed (36) hide show
  1. package/dist/cjs/index.cjs +251 -0
  2. package/dist/esm/index.mjs +251 -2
  3. package/dist/types/address/bip44.d.ts +15 -0
  4. package/dist/types/curves/ed25519.d.ts +12 -0
  5. package/dist/types/hashes/blake3.d.ts +44 -0
  6. package/dist/types/hashes/sha3.d.ts +61 -0
  7. package/dist/types/index.d.ts +2 -0
  8. package/docs/changelog.md +184 -1
  9. package/docs/reference/classes/Bech32.md +15 -7
  10. package/docs/reference/classes/Bip32Path.md +17 -9
  11. package/docs/reference/classes/Bip39.md +28 -12
  12. package/docs/reference/classes/Bip44.md +121 -21
  13. package/docs/reference/classes/Blake2b.md +35 -17
  14. package/docs/reference/classes/Blake3.md +137 -0
  15. package/docs/reference/classes/ChaCha20Poly1305.md +18 -8
  16. package/docs/reference/classes/Ed25519.md +65 -9
  17. package/docs/reference/classes/HmacSha1.md +17 -9
  18. package/docs/reference/classes/HmacSha256.md +26 -12
  19. package/docs/reference/classes/HmacSha512.md +38 -16
  20. package/docs/reference/classes/Hotp.md +9 -5
  21. package/docs/reference/classes/PasswordGenerator.md +6 -4
  22. package/docs/reference/classes/PasswordValidator.md +23 -11
  23. package/docs/reference/classes/Pbkdf2.md +27 -11
  24. package/docs/reference/classes/Secp256k1.md +21 -9
  25. package/docs/reference/classes/Sha1.md +11 -7
  26. package/docs/reference/classes/Sha256.md +17 -9
  27. package/docs/reference/classes/Sha3.md +179 -0
  28. package/docs/reference/classes/Sha512.md +23 -11
  29. package/docs/reference/classes/Slip0010.md +27 -11
  30. package/docs/reference/classes/Totp.md +42 -16
  31. package/docs/reference/classes/X25519.md +9 -5
  32. package/docs/reference/classes/Zip215.md +12 -6
  33. package/docs/reference/index.md +2 -0
  34. package/docs/reference/type-aliases/KeyType.md +1 -1
  35. package/locales/en.json +3 -6
  36. package/package.json +12 -12
@@ -4,25 +4,29 @@ Class to help with Blake2B Signature scheme.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Blake2b()
7
+ ### Constructor
8
8
 
9
- > **new Blake2b**(`outputLength`, `key`?): [`Blake2b`](Blake2b.md)
9
+ > **new Blake2b**(`outputLength`, `key?`): `Blake2b`
10
10
 
11
11
  Create a new instance of Blake2b.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **outputLength**: `number`
15
+ ##### outputLength
16
+
17
+ `number`
16
18
 
17
19
  The output length.
18
20
 
19
- **key?**: `Uint8Array`
21
+ ##### key?
22
+
23
+ `Uint8Array`\<`ArrayBufferLike`\>
20
24
 
21
25
  Optional key for the hash.
22
26
 
23
27
  #### Returns
24
28
 
25
- [`Blake2b`](Blake2b.md)
29
+ `Blake2b`
26
30
 
27
31
  ## Properties
28
32
 
@@ -52,17 +56,21 @@ Blake2b 512.
52
56
 
53
57
  ### sum160()
54
58
 
55
- > `static` **sum160**(`block`, `key`?): `Uint8Array`
59
+ > `static` **sum160**(`block`, `key?`): `Uint8Array`
56
60
 
57
61
  Perform Sum 160 on the block.
58
62
 
59
63
  #### Parameters
60
64
 
61
- **block**: `Uint8Array`
65
+ ##### block
66
+
67
+ `Uint8Array`
62
68
 
63
69
  The block to operate on.
64
70
 
65
- **key?**: `Uint8Array`
71
+ ##### key?
72
+
73
+ `Uint8Array`\<`ArrayBufferLike`\>
66
74
 
67
75
  Optional key for the hash.
68
76
 
@@ -76,17 +84,21 @@ The sum 160 of the block.
76
84
 
77
85
  ### sum256()
78
86
 
79
- > `static` **sum256**(`block`, `key`?): `Uint8Array`
87
+ > `static` **sum256**(`block`, `key?`): `Uint8Array`
80
88
 
81
89
  Perform Sum 256 on the block.
82
90
 
83
91
  #### Parameters
84
92
 
85
- **block**: `Uint8Array`
93
+ ##### block
94
+
95
+ `Uint8Array`
86
96
 
87
97
  The block to operate on.
88
98
 
89
- **key?**: `Uint8Array`
99
+ ##### key?
100
+
101
+ `Uint8Array`\<`ArrayBufferLike`\>
90
102
 
91
103
  Optional key for the hash.
92
104
 
@@ -100,17 +112,21 @@ The sum 256 of the block.
100
112
 
101
113
  ### sum512()
102
114
 
103
- > `static` **sum512**(`block`, `key`?): `Uint8Array`
115
+ > `static` **sum512**(`block`, `key?`): `Uint8Array`
104
116
 
105
117
  Perform Sum 512 on the block.
106
118
 
107
119
  #### Parameters
108
120
 
109
- **block**: `Uint8Array`
121
+ ##### block
122
+
123
+ `Uint8Array`
110
124
 
111
125
  The block to operate on.
112
126
 
113
- **key?**: `Uint8Array`
127
+ ##### key?
128
+
129
+ `Uint8Array`\<`ArrayBufferLike`\>
114
130
 
115
131
  Optional key for the hash.
116
132
 
@@ -124,19 +140,21 @@ The sum 512 of the block.
124
140
 
125
141
  ### update()
126
142
 
127
- > **update**(`block`): [`Blake2b`](Blake2b.md)
143
+ > **update**(`block`): `Blake2b`
128
144
 
129
145
  Update the hash with the block.
130
146
 
131
147
  #### Parameters
132
148
 
133
- **block**: `Uint8Array`
149
+ ##### block
150
+
151
+ `Uint8Array`
134
152
 
135
153
  The block to update the hash with.
136
154
 
137
155
  #### Returns
138
156
 
139
- [`Blake2b`](Blake2b.md)
157
+ `Blake2b`
140
158
 
141
159
  The instance for chaining.
142
160
 
@@ -0,0 +1,137 @@
1
+ # Class: Blake3
2
+
3
+ Class to help with Blake3 Signature scheme.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new Blake3**(`outputLength`, `key?`): `Blake3`
10
+
11
+ Create a new instance of Blake3.
12
+
13
+ #### Parameters
14
+
15
+ ##### outputLength
16
+
17
+ `number`
18
+
19
+ The output length.
20
+
21
+ ##### key?
22
+
23
+ `Uint8Array`\<`ArrayBufferLike`\>
24
+
25
+ Optional key for the hash.
26
+
27
+ #### Returns
28
+
29
+ `Blake3`
30
+
31
+ ## Properties
32
+
33
+ ### SIZE\_256
34
+
35
+ > `static` **SIZE\_256**: `number` = `32`
36
+
37
+ Blake3 256.
38
+
39
+ ***
40
+
41
+ ### SIZE\_512
42
+
43
+ > `static` **SIZE\_512**: `number` = `64`
44
+
45
+ Blake3 512.
46
+
47
+ ## Methods
48
+
49
+ ### sum256()
50
+
51
+ > `static` **sum256**(`block`, `key?`): `Uint8Array`
52
+
53
+ Perform Sum 256 on the block.
54
+
55
+ #### Parameters
56
+
57
+ ##### block
58
+
59
+ `Uint8Array`
60
+
61
+ The block to operate on.
62
+
63
+ ##### key?
64
+
65
+ `Uint8Array`\<`ArrayBufferLike`\>
66
+
67
+ Optional key for the hash.
68
+
69
+ #### Returns
70
+
71
+ `Uint8Array`
72
+
73
+ The sum 256 of the block.
74
+
75
+ ***
76
+
77
+ ### sum512()
78
+
79
+ > `static` **sum512**(`block`, `key?`): `Uint8Array`
80
+
81
+ Perform Sum 512 on the block.
82
+
83
+ #### Parameters
84
+
85
+ ##### block
86
+
87
+ `Uint8Array`
88
+
89
+ The block to operate on.
90
+
91
+ ##### key?
92
+
93
+ `Uint8Array`\<`ArrayBufferLike`\>
94
+
95
+ Optional key for the hash.
96
+
97
+ #### Returns
98
+
99
+ `Uint8Array`
100
+
101
+ The sum 512 of the block.
102
+
103
+ ***
104
+
105
+ ### update()
106
+
107
+ > **update**(`block`): `Blake3`
108
+
109
+ Update the hash with the block.
110
+
111
+ #### Parameters
112
+
113
+ ##### block
114
+
115
+ `Uint8Array`
116
+
117
+ The block to update the hash with.
118
+
119
+ #### Returns
120
+
121
+ `Blake3`
122
+
123
+ The instance for chaining.
124
+
125
+ ***
126
+
127
+ ### digest()
128
+
129
+ > **digest**(): `Uint8Array`
130
+
131
+ Get the digest for the hash.
132
+
133
+ #### Returns
134
+
135
+ `Uint8Array`
136
+
137
+ The instance for chaining.
@@ -4,29 +4,35 @@ Implementation of the ChaCha20Poly1305 cipher.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new ChaCha20Poly1305()
7
+ ### Constructor
8
8
 
9
- > **new ChaCha20Poly1305**(`key`, `nonce`, `aad`?): [`ChaCha20Poly1305`](ChaCha20Poly1305.md)
9
+ > **new ChaCha20Poly1305**(`key`, `nonce`, `aad?`): `ChaCha20Poly1305`
10
10
 
11
11
  Create a new instance of ChaCha20Poly1305.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **key**: `Uint8Array`
15
+ ##### key
16
+
17
+ `Uint8Array`
16
18
 
17
19
  The key.
18
20
 
19
- **nonce**: `Uint8Array`
21
+ ##### nonce
22
+
23
+ `Uint8Array`
20
24
 
21
25
  The nonce.
22
26
 
23
- **aad?**: `Uint8Array`
27
+ ##### aad?
28
+
29
+ `Uint8Array`\<`ArrayBufferLike`\>
24
30
 
25
31
  The additional authenticated data.
26
32
 
27
33
  #### Returns
28
34
 
29
- [`ChaCha20Poly1305`](ChaCha20Poly1305.md)
35
+ `ChaCha20Poly1305`
30
36
 
31
37
  ## Methods
32
38
 
@@ -38,7 +44,9 @@ Encrypt the block.
38
44
 
39
45
  #### Parameters
40
46
 
41
- **block**: `Uint8Array`
47
+ ##### block
48
+
49
+ `Uint8Array`
42
50
 
43
51
  The block to encrypt.
44
52
 
@@ -58,7 +66,9 @@ Decrypt the block.
58
66
 
59
67
  #### Parameters
60
68
 
61
- **block**: `Uint8Array`
69
+ ##### block
70
+
71
+ `Uint8Array`
62
72
 
63
73
  The block to decrypt.
64
74
 
@@ -4,13 +4,13 @@ Implementation of Ed25519.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Ed25519()
7
+ ### Constructor
8
8
 
9
- > **new Ed25519**(): [`Ed25519`](Ed25519.md)
9
+ > **new Ed25519**(): `Ed25519`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`Ed25519`](Ed25519.md)
13
+ `Ed25519`
14
14
 
15
15
  ## Properties
16
16
 
@@ -38,7 +38,9 @@ Public returns the PublicKey corresponding to private.
38
38
 
39
39
  #### Parameters
40
40
 
41
- **privateKey**: `Uint8Array`
41
+ ##### privateKey
42
+
43
+ `Uint8Array`
42
44
 
43
45
  The private key to get the corresponding public key.
44
46
 
@@ -62,11 +64,15 @@ Sign the block with privateKey and returns a signature.
62
64
 
63
65
  #### Parameters
64
66
 
65
- **privateKey**: `Uint8Array`
67
+ ##### privateKey
68
+
69
+ `Uint8Array`
66
70
 
67
71
  The private key.
68
72
 
69
- **block**: `Uint8Array`
73
+ ##### block
74
+
75
+ `Uint8Array`
70
76
 
71
77
  The block to sign.
72
78
 
@@ -90,15 +96,21 @@ Verify reports whether sig is a valid signature of block by publicKey.
90
96
 
91
97
  #### Parameters
92
98
 
93
- **publicKey**: `Uint8Array`
99
+ ##### publicKey
100
+
101
+ `Uint8Array`
94
102
 
95
103
  The public key to verify the signature.
96
104
 
97
- **block**: `Uint8Array`
105
+ ##### block
106
+
107
+ `Uint8Array`
98
108
 
99
109
  The block for the signature.
100
110
 
101
- **signature**: `Uint8Array`
111
+ ##### signature
112
+
113
+ `Uint8Array`
102
114
 
103
115
  The signature.
104
116
 
@@ -111,3 +123,47 @@ True if the signature matches.
111
123
  #### Throws
112
124
 
113
125
  Error if the public key is not the correct length.
126
+
127
+ ***
128
+
129
+ ### privateKeyToPkcs8()
130
+
131
+ > `static` **privateKeyToPkcs8**(`privateKey`): `Promise`\<`CryptoKey`\>
132
+
133
+ Convert a private key in PKCS8 format.
134
+
135
+ #### Parameters
136
+
137
+ ##### privateKey
138
+
139
+ `Uint8Array`
140
+
141
+ The private key to convert.
142
+
143
+ #### Returns
144
+
145
+ `Promise`\<`CryptoKey`\>
146
+
147
+ The private key in PKCS8 format.
148
+
149
+ ***
150
+
151
+ ### pkcs8ToPrivateKey()
152
+
153
+ > `static` **pkcs8ToPrivateKey**(`cryptoKey`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
154
+
155
+ Convert a crypto key to raw private key.
156
+
157
+ #### Parameters
158
+
159
+ ##### cryptoKey
160
+
161
+ `CryptoKey`
162
+
163
+ The crypto key to convert.
164
+
165
+ #### Returns
166
+
167
+ `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
168
+
169
+ The raw private key.
@@ -4,21 +4,23 @@ Class to help with HmacSha1 scheme.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new HmacSha1()
7
+ ### Constructor
8
8
 
9
- > **new HmacSha1**(`key`): [`HmacSha1`](HmacSha1.md)
9
+ > **new HmacSha1**(`key`): `HmacSha1`
10
10
 
11
11
  Create a new instance of HmacSha1.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **key**: `Uint8Array`
15
+ ##### key
16
+
17
+ `Uint8Array`
16
18
 
17
19
  The key for the hmac.
18
20
 
19
21
  #### Returns
20
22
 
21
- [`HmacSha1`](HmacSha1.md)
23
+ `HmacSha1`
22
24
 
23
25
  ## Methods
24
26
 
@@ -30,11 +32,15 @@ Perform Sum on the block.
30
32
 
31
33
  #### Parameters
32
34
 
33
- **key**: `Uint8Array`
35
+ ##### key
36
+
37
+ `Uint8Array`
34
38
 
35
39
  The key for the hmac.
36
40
 
37
- **block**: `Uint8Array`
41
+ ##### block
42
+
43
+ `Uint8Array`
38
44
 
39
45
  The block to operate on.
40
46
 
@@ -48,19 +54,21 @@ The sum of the block.
48
54
 
49
55
  ### update()
50
56
 
51
- > **update**(`block`): [`HmacSha1`](HmacSha1.md)
57
+ > **update**(`block`): `HmacSha1`
52
58
 
53
59
  Update the hash with the block.
54
60
 
55
61
  #### Parameters
56
62
 
57
- **block**: `Uint8Array`
63
+ ##### block
64
+
65
+ `Uint8Array`
58
66
 
59
67
  The block to update the hash with.
60
68
 
61
69
  #### Returns
62
70
 
63
- [`HmacSha1`](HmacSha1.md)
71
+ `HmacSha1`
64
72
 
65
73
  The instance for chaining.
66
74
 
@@ -4,25 +4,29 @@ Class to help with HmacSha256 scheme.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new HmacSha256()
7
+ ### Constructor
8
8
 
9
- > **new HmacSha256**(`key`, `bits`): [`HmacSha256`](HmacSha256.md)
9
+ > **new HmacSha256**(`key`, `bits`): `HmacSha256`
10
10
 
11
11
  Create a new instance of HmacSha256.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **key**: `Uint8Array`
15
+ ##### key
16
+
17
+ `Uint8Array`
16
18
 
17
19
  The key for the hmac.
18
20
 
19
- **bits**: `number` = `HmacSha256.SIZE_256`
21
+ ##### bits
22
+
23
+ `number` = `HmacSha256.SIZE_256`
20
24
 
21
25
  The number of bits.
22
26
 
23
27
  #### Returns
24
28
 
25
- [`HmacSha256`](HmacSha256.md)
29
+ `HmacSha256`
26
30
 
27
31
  ## Properties
28
32
 
@@ -50,11 +54,15 @@ Perform Sum 224 on the block.
50
54
 
51
55
  #### Parameters
52
56
 
53
- **key**: `Uint8Array`
57
+ ##### key
58
+
59
+ `Uint8Array`
54
60
 
55
61
  The key for the hmac.
56
62
 
57
- **block**: `Uint8Array`
63
+ ##### block
64
+
65
+ `Uint8Array`
58
66
 
59
67
  The block to operate on.
60
68
 
@@ -74,11 +82,15 @@ Perform Sum 256 on the block.
74
82
 
75
83
  #### Parameters
76
84
 
77
- **key**: `Uint8Array`
85
+ ##### key
86
+
87
+ `Uint8Array`
78
88
 
79
89
  The key for the hmac.
80
90
 
81
- **block**: `Uint8Array`
91
+ ##### block
92
+
93
+ `Uint8Array`
82
94
 
83
95
  The block to operate on.
84
96
 
@@ -92,19 +104,21 @@ The sum 256 of the block.
92
104
 
93
105
  ### update()
94
106
 
95
- > **update**(`block`): [`HmacSha256`](HmacSha256.md)
107
+ > **update**(`block`): `HmacSha256`
96
108
 
97
109
  Update the hash with the block.
98
110
 
99
111
  #### Parameters
100
112
 
101
- **block**: `Uint8Array`
113
+ ##### block
114
+
115
+ `Uint8Array`
102
116
 
103
117
  The block to update the hash with.
104
118
 
105
119
  #### Returns
106
120
 
107
- [`HmacSha256`](HmacSha256.md)
121
+ `HmacSha256`
108
122
 
109
123
  The instance for chaining.
110
124