@twin.org/crypto 0.0.1-next.9 → 0.0.2-next.3

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 (38) hide show
  1. package/dist/cjs/index.cjs +304 -1
  2. package/dist/esm/index.mjs +304 -3
  3. package/dist/types/address/bip44.d.ts +15 -0
  4. package/dist/types/ciphers/rsa.d.ts +63 -0
  5. package/dist/types/curves/ed25519.d.ts +12 -0
  6. package/dist/types/helpers/pemHelper.d.ts +19 -0
  7. package/dist/types/index.d.ts +2 -0
  8. package/docs/changelog.md +400 -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 +28 -14
  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/PemHelper.md +69 -0
  25. package/docs/reference/classes/RSA.md +213 -0
  26. package/docs/reference/classes/Secp256k1.md +21 -9
  27. package/docs/reference/classes/Sha1.md +11 -7
  28. package/docs/reference/classes/Sha256.md +17 -9
  29. package/docs/reference/classes/Sha3.md +23 -11
  30. package/docs/reference/classes/Sha512.md +23 -11
  31. package/docs/reference/classes/Slip0010.md +27 -11
  32. package/docs/reference/classes/Totp.md +42 -16
  33. package/docs/reference/classes/X25519.md +9 -5
  34. package/docs/reference/classes/Zip215.md +12 -6
  35. package/docs/reference/index.md +2 -0
  36. package/docs/reference/type-aliases/KeyType.md +1 -1
  37. package/locales/en.json +4 -0
  38. package/package.json +13 -13
@@ -0,0 +1,213 @@
1
+ # Class: RSA
2
+
3
+ Implementation of the RSA cipher.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new RSA**(`publicKey`, `privateKey?`): `RSA`
10
+
11
+ Create a new instance of RSA.
12
+
13
+ #### Parameters
14
+
15
+ ##### publicKey
16
+
17
+ `Uint8Array`
18
+
19
+ The public key for encryption (DER format as Uint8Array).
20
+
21
+ ##### privateKey?
22
+
23
+ `Uint8Array`\<`ArrayBufferLike`\>
24
+
25
+ The private key for decryption (DER format as Uint8Array).
26
+
27
+ #### Returns
28
+
29
+ `RSA`
30
+
31
+ ## Methods
32
+
33
+ ### generateKeyPair()
34
+
35
+ > `static` **generateKeyPair**(`modulusLength`): `object`
36
+
37
+ Generate a new RSA key pair in PKCS8 format.
38
+
39
+ #### Parameters
40
+
41
+ ##### modulusLength
42
+
43
+ `number` = `2048`
44
+
45
+ The key size in bits (default: 2048).
46
+
47
+ #### Returns
48
+
49
+ `object`
50
+
51
+ The public and private keys as Uint8Array.
52
+
53
+ ##### publicKey
54
+
55
+ > **publicKey**: `Uint8Array`
56
+
57
+ ##### privateKey
58
+
59
+ > **privateKey**: `Uint8Array`
60
+
61
+ ***
62
+
63
+ ### convertPkcs1ToPkcs8()
64
+
65
+ > `static` **convertPkcs1ToPkcs8**(`pkcs1Key`): `Uint8Array`
66
+
67
+ Convert a PKCS1 key to a PKCS8 key.
68
+
69
+ #### Parameters
70
+
71
+ ##### pkcs1Key
72
+
73
+ `Uint8Array`
74
+
75
+ The PKCS1 key as Uint8Array.
76
+
77
+ #### Returns
78
+
79
+ `Uint8Array`
80
+
81
+ The PKCS8 key as Uint8Array.
82
+
83
+ ***
84
+
85
+ ### getPrivateKeyComponents()
86
+
87
+ > `static` **getPrivateKeyComponents**(`pkcs8Key`): `object`
88
+
89
+ Break the private key down in to its components.
90
+
91
+ #### Parameters
92
+
93
+ ##### pkcs8Key
94
+
95
+ `Uint8Array`
96
+
97
+ The PKCS8 key as Uint8Array.
98
+
99
+ #### Returns
100
+
101
+ `object`
102
+
103
+ The key components.
104
+
105
+ ##### n
106
+
107
+ > **n**: `bigint`
108
+
109
+ ##### e
110
+
111
+ > **e**: `bigint`
112
+
113
+ ##### d
114
+
115
+ > **d**: `bigint`
116
+
117
+ ##### p
118
+
119
+ > **p**: `bigint`
120
+
121
+ ##### q
122
+
123
+ > **q**: `bigint`
124
+
125
+ ##### dp
126
+
127
+ > **dp**: `bigint`
128
+
129
+ ##### dq
130
+
131
+ > **dq**: `bigint`
132
+
133
+ ##### qi
134
+
135
+ > **qi**: `bigint`
136
+
137
+ ***
138
+
139
+ ### getPublicKeyComponents()
140
+
141
+ > `static` **getPublicKeyComponents**(`spkiKey`): `object`
142
+
143
+ Break the public key down in to its components.
144
+
145
+ #### Parameters
146
+
147
+ ##### spkiKey
148
+
149
+ `Uint8Array`
150
+
151
+ The SPKI key as Uint8Array.
152
+
153
+ #### Returns
154
+
155
+ `object`
156
+
157
+ The key components.
158
+
159
+ ##### n
160
+
161
+ > **n**: `bigint`
162
+
163
+ ##### e
164
+
165
+ > **e**: `bigint`
166
+
167
+ ***
168
+
169
+ ### encrypt()
170
+
171
+ > **encrypt**(`data`): `Uint8Array`
172
+
173
+ Encrypt the data.
174
+
175
+ #### Parameters
176
+
177
+ ##### data
178
+
179
+ `Uint8Array`
180
+
181
+ The data to encrypt.
182
+
183
+ #### Returns
184
+
185
+ `Uint8Array`
186
+
187
+ The data encrypted.
188
+
189
+ ***
190
+
191
+ ### decrypt()
192
+
193
+ > **decrypt**(`data`): `Uint8Array`
194
+
195
+ Decrypt the data.
196
+
197
+ #### Parameters
198
+
199
+ ##### data
200
+
201
+ `Uint8Array`
202
+
203
+ The data to decrypt.
204
+
205
+ #### Returns
206
+
207
+ `Uint8Array`
208
+
209
+ The data decrypted.
210
+
211
+ #### Throws
212
+
213
+ GeneralError If no private key is provided.
@@ -4,13 +4,13 @@ Implementation of secp256k1.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Secp256k1()
7
+ ### Constructor
8
8
 
9
- > **new Secp256k1**(): [`Secp256k1`](Secp256k1.md)
9
+ > **new Secp256k1**(): `Secp256k1`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`Secp256k1`](Secp256k1.md)
13
+ `Secp256k1`
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
 
@@ -4,15 +4,15 @@ Perform a SHA-1 hash on the block.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Sha1()
7
+ ### Constructor
8
8
 
9
- > **new Sha1**(): [`Sha1`](Sha1.md)
9
+ > **new Sha1**(): `Sha1`
10
10
 
11
11
  Create a new instance of Sha1.
12
12
 
13
13
  #### Returns
14
14
 
15
- [`Sha1`](Sha1.md)
15
+ `Sha1`
16
16
 
17
17
  ## Methods
18
18
 
@@ -24,7 +24,9 @@ Perform Sum on the block.
24
24
 
25
25
  #### Parameters
26
26
 
27
- **block**: `Uint8Array`
27
+ ##### block
28
+
29
+ `Uint8Array`
28
30
 
29
31
  The block to operate on.
30
32
 
@@ -38,19 +40,21 @@ The sum of the block.
38
40
 
39
41
  ### update()
40
42
 
41
- > **update**(`block`): [`Sha1`](Sha1.md)
43
+ > **update**(`block`): `Sha1`
42
44
 
43
45
  Update the hash with the block.
44
46
 
45
47
  #### Parameters
46
48
 
47
- **block**: `Uint8Array`
49
+ ##### block
50
+
51
+ `Uint8Array`
48
52
 
49
53
  The block to update the hash with.
50
54
 
51
55
  #### Returns
52
56
 
53
- [`Sha1`](Sha1.md)
57
+ `Sha1`
54
58
 
55
59
  The instance for chaining.
56
60
 
@@ -4,21 +4,23 @@ Perform a SHA-256 hash on the block.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Sha256()
7
+ ### Constructor
8
8
 
9
- > **new Sha256**(`bits`): [`Sha256`](Sha256.md)
9
+ > **new Sha256**(`bits`): `Sha256`
10
10
 
11
11
  Create a new instance of Sha256.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **bits**: `number` = `Sha256.SIZE_256`
15
+ ##### bits
16
+
17
+ `number` = `Sha256.SIZE_256`
16
18
 
17
19
  The number of bits.
18
20
 
19
21
  #### Returns
20
22
 
21
- [`Sha256`](Sha256.md)
23
+ `Sha256`
22
24
 
23
25
  ## Properties
24
26
 
@@ -46,7 +48,9 @@ Perform Sum 256 on the block.
46
48
 
47
49
  #### Parameters
48
50
 
49
- **block**: `Uint8Array`
51
+ ##### block
52
+
53
+ `Uint8Array`
50
54
 
51
55
  The block to operate on.
52
56
 
@@ -66,7 +70,9 @@ Perform Sum 224 on the block.
66
70
 
67
71
  #### Parameters
68
72
 
69
- **block**: `Uint8Array`
73
+ ##### block
74
+
75
+ `Uint8Array`
70
76
 
71
77
  The block to operate on.
72
78
 
@@ -80,19 +86,21 @@ The sum 224 of the block.
80
86
 
81
87
  ### update()
82
88
 
83
- > **update**(`block`): [`Sha256`](Sha256.md)
89
+ > **update**(`block`): `Sha256`
84
90
 
85
91
  Update the hash with the block.
86
92
 
87
93
  #### Parameters
88
94
 
89
- **block**: `Uint8Array`
95
+ ##### block
96
+
97
+ `Uint8Array`
90
98
 
91
99
  The block to update the hash with.
92
100
 
93
101
  #### Returns
94
102
 
95
- [`Sha256`](Sha256.md)
103
+ `Sha256`
96
104
 
97
105
  The instance for chaining.
98
106
 
@@ -4,21 +4,23 @@ Perform a SHA-3 hash on the block.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Sha3()
7
+ ### Constructor
8
8
 
9
- > **new Sha3**(`bits`): [`Sha3`](Sha3.md)
9
+ > **new Sha3**(`bits`): `Sha3`
10
10
 
11
11
  Create a new instance of Sha3.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **bits**: `number` = `Sha3.SIZE_256`
15
+ ##### bits
16
+
17
+ `number` = `Sha3.SIZE_256`
16
18
 
17
19
  The number of bits.
18
20
 
19
21
  #### Returns
20
22
 
21
- [`Sha3`](Sha3.md)
23
+ `Sha3`
22
24
 
23
25
  ## Properties
24
26
 
@@ -62,7 +64,9 @@ Perform Sum 256 on the block.
62
64
 
63
65
  #### Parameters
64
66
 
65
- **block**: `Uint8Array`
67
+ ##### block
68
+
69
+ `Uint8Array`
66
70
 
67
71
  The block to operate on.
68
72
 
@@ -82,7 +86,9 @@ Perform Sum 224 on the block.
82
86
 
83
87
  #### Parameters
84
88
 
85
- **block**: `Uint8Array`
89
+ ##### block
90
+
91
+ `Uint8Array`
86
92
 
87
93
  The block to operate on.
88
94
 
@@ -102,7 +108,9 @@ Perform Sum 384 on the block.
102
108
 
103
109
  #### Parameters
104
110
 
105
- **block**: `Uint8Array`
111
+ ##### block
112
+
113
+ `Uint8Array`
106
114
 
107
115
  The block to operate on.
108
116
 
@@ -122,7 +130,9 @@ Perform Sum 512 on the block.
122
130
 
123
131
  #### Parameters
124
132
 
125
- **block**: `Uint8Array`
133
+ ##### block
134
+
135
+ `Uint8Array`
126
136
 
127
137
  The block to operate on.
128
138
 
@@ -136,19 +146,21 @@ The sum 512 of the block.
136
146
 
137
147
  ### update()
138
148
 
139
- > **update**(`block`): [`Sha3`](Sha3.md)
149
+ > **update**(`block`): `Sha3`
140
150
 
141
151
  Update the hash with the block.
142
152
 
143
153
  #### Parameters
144
154
 
145
- **block**: `Uint8Array`
155
+ ##### block
156
+
157
+ `Uint8Array`
146
158
 
147
159
  The block to update the hash with.
148
160
 
149
161
  #### Returns
150
162
 
151
- [`Sha3`](Sha3.md)
163
+ `Sha3`
152
164
 
153
165
  The instance for chaining.
154
166
 
@@ -4,21 +4,23 @@ Perform a SHA-512 hash on the block.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Sha512()
7
+ ### Constructor
8
8
 
9
- > **new Sha512**(`bits`): [`Sha512`](Sha512.md)
9
+ > **new Sha512**(`bits`): `Sha512`
10
10
 
11
11
  Create a new instance of Sha512.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **bits**: `number` = `Sha512.SIZE_512`
15
+ ##### bits
16
+
17
+ `number` = `Sha512.SIZE_512`
16
18
 
17
19
  The number of bits.
18
20
 
19
21
  #### Returns
20
22
 
21
- [`Sha512`](Sha512.md)
23
+ `Sha512`
22
24
 
23
25
  ## Properties
24
26
 
@@ -62,7 +64,9 @@ Perform Sum 512 on the block.
62
64
 
63
65
  #### Parameters
64
66
 
65
- **block**: `Uint8Array`
67
+ ##### block
68
+
69
+ `Uint8Array`
66
70
 
67
71
  The block to operate on.
68
72
 
@@ -82,7 +86,9 @@ Perform Sum 384 on the block.
82
86
 
83
87
  #### Parameters
84
88
 
85
- **block**: `Uint8Array`
89
+ ##### block
90
+
91
+ `Uint8Array`
86
92
 
87
93
  The block to operate on.
88
94
 
@@ -102,7 +108,9 @@ Perform Sum 256 on the block.
102
108
 
103
109
  #### Parameters
104
110
 
105
- **block**: `Uint8Array`
111
+ ##### block
112
+
113
+ `Uint8Array`
106
114
 
107
115
  The block to operate on.
108
116
 
@@ -122,7 +130,9 @@ Perform Sum 224 on the block.
122
130
 
123
131
  #### Parameters
124
132
 
125
- **block**: `Uint8Array`
133
+ ##### block
134
+
135
+ `Uint8Array`
126
136
 
127
137
  The block to operate on.
128
138
 
@@ -136,19 +146,21 @@ The sum 224 of the block.
136
146
 
137
147
  ### update()
138
148
 
139
- > **update**(`block`): [`Sha512`](Sha512.md)
149
+ > **update**(`block`): `Sha512`
140
150
 
141
151
  Update the hash with the block.
142
152
 
143
153
  #### Parameters
144
154
 
145
- **block**: `Uint8Array`
155
+ ##### block
156
+
157
+ `Uint8Array`
146
158
 
147
159
  The block to update the hash with.
148
160
 
149
161
  #### Returns
150
162
 
151
- [`Sha512`](Sha512.md)
163
+ `Sha512`
152
164
 
153
165
  The instance for chaining.
154
166
 
@@ -5,13 +5,13 @@ https://github.com/satoshilabs/slips/blob/master/slip-0010.md.
5
5
 
6
6
  ## Constructors
7
7
 
8
- ### new Slip0010()
8
+ ### Constructor
9
9
 
10
- > **new Slip0010**(): [`Slip0010`](Slip0010.md)
10
+ > **new Slip0010**(): `Slip0010`
11
11
 
12
12
  #### Returns
13
13
 
14
- [`Slip0010`](Slip0010.md)
14
+ `Slip0010`
15
15
 
16
16
  ## Methods
17
17
 
@@ -23,11 +23,15 @@ Get the master key from the seed.
23
23
 
24
24
  #### Parameters
25
25
 
26
- **seed**: `Uint8Array`
26
+ ##### seed
27
+
28
+ `Uint8Array`
27
29
 
28
30
  The seed to generate the master key from.
29
31
 
30
- **keyType**: [`KeyType`](../type-aliases/KeyType.md) = `KeyType.Ed25519`
32
+ ##### keyType
33
+
34
+ [`KeyType`](../type-aliases/KeyType.md) = `KeyType.Ed25519`
31
35
 
32
36
  The key type.
33
37
 
@@ -59,15 +63,21 @@ Derive a key from the path.
59
63
 
60
64
  #### Parameters
61
65
 
62
- **seed**: `Uint8Array`
66
+ ##### seed
67
+
68
+ `Uint8Array`
63
69
 
64
70
  The seed.
65
71
 
66
- **path**: [`Bip32Path`](Bip32Path.md)
72
+ ##### path
73
+
74
+ [`Bip32Path`](Bip32Path.md)
67
75
 
68
76
  The path.
69
77
 
70
- **keyType**: [`KeyType`](../type-aliases/KeyType.md) = `KeyType.Ed25519`
78
+ ##### keyType
79
+
80
+ [`KeyType`](../type-aliases/KeyType.md) = `KeyType.Ed25519`
71
81
 
72
82
  The key type.
73
83
 
@@ -95,15 +105,21 @@ Get the public key from the private key.
95
105
 
96
106
  #### Parameters
97
107
 
98
- **privateKey**: `Uint8Array`
108
+ ##### privateKey
109
+
110
+ `Uint8Array`
99
111
 
100
112
  The private key.
101
113
 
102
- **keyType**: [`KeyType`](../type-aliases/KeyType.md) = `KeyType.Ed25519`
114
+ ##### keyType
115
+
116
+ [`KeyType`](../type-aliases/KeyType.md) = `KeyType.Ed25519`
103
117
 
104
118
  The key type.
105
119
 
106
- **withZeroByte**: `boolean` = `true`
120
+ ##### withZeroByte
121
+
122
+ `boolean` = `true`
107
123
 
108
124
  Include a zero bute prefix.
109
125