@twin.org/crypto 0.0.1-next.8 → 0.0.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.
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 +331 -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 +13 -13
@@ -0,0 +1,179 @@
1
+ # Class: Sha3
2
+
3
+ Perform a SHA-3 hash on the block.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new Sha3**(`bits`): `Sha3`
10
+
11
+ Create a new instance of Sha3.
12
+
13
+ #### Parameters
14
+
15
+ ##### bits
16
+
17
+ `number` = `Sha3.SIZE_256`
18
+
19
+ The number of bits.
20
+
21
+ #### Returns
22
+
23
+ `Sha3`
24
+
25
+ ## Properties
26
+
27
+ ### SIZE\_224
28
+
29
+ > `readonly` `static` **SIZE\_224**: `number` = `224`
30
+
31
+ Sha3 224.
32
+
33
+ ***
34
+
35
+ ### SIZE\_256
36
+
37
+ > `readonly` `static` **SIZE\_256**: `number` = `256`
38
+
39
+ Sha3 256.
40
+
41
+ ***
42
+
43
+ ### SIZE\_384
44
+
45
+ > `readonly` `static` **SIZE\_384**: `number` = `384`
46
+
47
+ Sha3 384.
48
+
49
+ ***
50
+
51
+ ### SIZE\_512
52
+
53
+ > `readonly` `static` **SIZE\_512**: `number` = `512`
54
+
55
+ Sha3 512.
56
+
57
+ ## Methods
58
+
59
+ ### sum256()
60
+
61
+ > `static` **sum256**(`block`): `Uint8Array`
62
+
63
+ Perform Sum 256 on the block.
64
+
65
+ #### Parameters
66
+
67
+ ##### block
68
+
69
+ `Uint8Array`
70
+
71
+ The block to operate on.
72
+
73
+ #### Returns
74
+
75
+ `Uint8Array`
76
+
77
+ The sum 256 of the block.
78
+
79
+ ***
80
+
81
+ ### sum224()
82
+
83
+ > `static` **sum224**(`block`): `Uint8Array`
84
+
85
+ Perform Sum 224 on the block.
86
+
87
+ #### Parameters
88
+
89
+ ##### block
90
+
91
+ `Uint8Array`
92
+
93
+ The block to operate on.
94
+
95
+ #### Returns
96
+
97
+ `Uint8Array`
98
+
99
+ The sum 224 of the block.
100
+
101
+ ***
102
+
103
+ ### sum384()
104
+
105
+ > `static` **sum384**(`block`): `Uint8Array`
106
+
107
+ Perform Sum 384 on the block.
108
+
109
+ #### Parameters
110
+
111
+ ##### block
112
+
113
+ `Uint8Array`
114
+
115
+ The block to operate on.
116
+
117
+ #### Returns
118
+
119
+ `Uint8Array`
120
+
121
+ The sum 384 of the block.
122
+
123
+ ***
124
+
125
+ ### sum512()
126
+
127
+ > `static` **sum512**(`block`): `Uint8Array`
128
+
129
+ Perform Sum 512 on the block.
130
+
131
+ #### Parameters
132
+
133
+ ##### block
134
+
135
+ `Uint8Array`
136
+
137
+ The block to operate on.
138
+
139
+ #### Returns
140
+
141
+ `Uint8Array`
142
+
143
+ The sum 512 of the block.
144
+
145
+ ***
146
+
147
+ ### update()
148
+
149
+ > **update**(`block`): `Sha3`
150
+
151
+ Update the hash with the block.
152
+
153
+ #### Parameters
154
+
155
+ ##### block
156
+
157
+ `Uint8Array`
158
+
159
+ The block to update the hash with.
160
+
161
+ #### Returns
162
+
163
+ `Sha3`
164
+
165
+ The instance for chaining.
166
+
167
+ ***
168
+
169
+ ### digest()
170
+
171
+ > **digest**(): `Uint8Array`
172
+
173
+ Get the digest for the hash.
174
+
175
+ #### Returns
176
+
177
+ `Uint8Array`
178
+
179
+ The instance for chaining.
@@ -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
 
@@ -5,13 +5,13 @@ Implementation of https://datatracker.ietf.org/doc/html/rfc4226 .
5
5
 
6
6
  ## Constructors
7
7
 
8
- ### new Totp()
8
+ ### Constructor
9
9
 
10
- > **new Totp**(): [`Totp`](Totp.md)
10
+ > **new Totp**(): `Totp`
11
11
 
12
12
  #### Returns
13
13
 
14
- [`Totp`](Totp.md)
14
+ `Totp`
15
15
 
16
16
  ## Methods
17
17
 
@@ -23,15 +23,21 @@ Generate a time based One Time Password.
23
23
 
24
24
  #### Parameters
25
25
 
26
- **key**: `Uint8Array`
26
+ ##### key
27
+
28
+ `Uint8Array`
27
29
 
28
30
  Key for the one time password.
29
31
 
30
- **interval**: `number` = `30`
32
+ ##### interval
33
+
34
+ `number` = `30`
31
35
 
32
36
  The time step of the counter.
33
37
 
34
- **timestamp**: `number` = `...`
38
+ ##### timestamp
39
+
40
+ `number` = `...`
35
41
 
36
42
  The timestamp.
37
43
 
@@ -51,24 +57,34 @@ Check a One Time Password based on a timer.
51
57
 
52
58
  #### Parameters
53
59
 
54
- **token**: `string`
60
+ ##### token
61
+
62
+ `string`
55
63
 
56
64
  Passcode to validate.
57
65
 
58
- **key**: `Uint8Array`
66
+ ##### key
67
+
68
+ `Uint8Array`
59
69
 
60
70
  Key for the one time password. This should be unique and secret for
61
71
  every user as it is the seed used to calculate the HMAC.
62
72
 
63
- **window**: `number` = `2`
73
+ ##### window
74
+
75
+ `number` = `2`
64
76
 
65
77
  The allowable margin for the counter.
66
78
 
67
- **interval**: `number` = `30`
79
+ ##### interval
80
+
81
+ `number` = `30`
68
82
 
69
83
  The time step of the counter.
70
84
 
71
- **timestamp**: `number` = `...`
85
+ ##### timestamp
86
+
87
+ `number` = `...`
72
88
 
73
89
  The timestamp now.
74
90
 
@@ -88,7 +104,9 @@ Generate a secret.
88
104
 
89
105
  #### Parameters
90
106
 
91
- **length**: `number`
107
+ ##### length
108
+
109
+ `number`
92
110
 
93
111
  The length of the secret to generate.
94
112
 
@@ -108,7 +126,9 @@ Convert the secret back to bytes.
108
126
 
109
127
  #### Parameters
110
128
 
111
- **secretBase32**: `string`
129
+ ##### secretBase32
130
+
131
+ `string`
112
132
 
113
133
  The secret encoded as base32.
114
134
 
@@ -129,15 +149,21 @@ See https://github.com/google/google-authenticator/wiki/Key-Uri-Format .
129
149
 
130
150
  #### Parameters
131
151
 
132
- **issuer**: `string`
152
+ ##### issuer
153
+
154
+ `string`
133
155
 
134
156
  The issuer of the totp.
135
157
 
136
- **label**: `string`
158
+ ##### label
159
+
160
+ `string`
137
161
 
138
162
  The label that will show in auth apps.
139
163
 
140
- **secretBase32**: `string`
164
+ ##### secretBase32
165
+
166
+ `string`
141
167
 
142
168
  The secret as base 32.
143
169
 
@@ -4,13 +4,13 @@ Implementation of X25519.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new X25519()
7
+ ### Constructor
8
8
 
9
- > **new X25519**(): [`X25519`](X25519.md)
9
+ > **new X25519**(): `X25519`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`X25519`](X25519.md)
13
+ `X25519`
14
14
 
15
15
  ## Methods
16
16
 
@@ -22,7 +22,9 @@ Convert Ed25519 private key to X25519 private key.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **ed25519PrivateKey**: `Uint8Array`
25
+ ##### ed25519PrivateKey
26
+
27
+ `Uint8Array`
26
28
 
27
29
  The ed25519 private key to convert.
28
30
 
@@ -42,7 +44,9 @@ Convert Ed25519 public key to X25519 public key.
42
44
 
43
45
  #### Parameters
44
46
 
45
- **ed25519PublicKey**: `Uint8Array`
47
+ ##### ed25519PublicKey
48
+
49
+ `Uint8Array`
46
50
 
47
51
  The ed25519 public key to convert.
48
52
 
@@ -4,13 +4,13 @@ Implementation of Zip215.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Zip215()
7
+ ### Constructor
8
8
 
9
- > **new Zip215**(): [`Zip215`](Zip215.md)
9
+ > **new Zip215**(): `Zip215`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`Zip215`](Zip215.md)
13
+ `Zip215`
14
14
 
15
15
  ## Methods
16
16
 
@@ -24,15 +24,21 @@ for use in consensus-critical contexts.
24
24
 
25
25
  #### Parameters
26
26
 
27
- **publicKey**: `Uint8Array`
27
+ ##### publicKey
28
+
29
+ `Uint8Array`
28
30
 
29
31
  The public key for the block.
30
32
 
31
- **block**: `Uint8Array`
33
+ ##### block
34
+
35
+ `Uint8Array`
32
36
 
33
37
  The block content to validate.
34
38
 
35
- **sig**: `Uint8Array`
39
+ ##### sig
40
+
41
+ `Uint8Array`
36
42
 
37
43
  The signature to verify.
38
44
 
@@ -10,12 +10,14 @@
10
10
  - [X25519](classes/X25519.md)
11
11
  - [Zip215](classes/Zip215.md)
12
12
  - [Blake2b](classes/Blake2b.md)
13
+ - [Blake3](classes/Blake3.md)
13
14
  - [HmacSha1](classes/HmacSha1.md)
14
15
  - [HmacSha256](classes/HmacSha256.md)
15
16
  - [HmacSha512](classes/HmacSha512.md)
16
17
  - [Pbkdf2](classes/Pbkdf2.md)
17
18
  - [Sha1](classes/Sha1.md)
18
19
  - [Sha256](classes/Sha256.md)
20
+ - [Sha3](classes/Sha3.md)
19
21
  - [Sha512](classes/Sha512.md)
20
22
  - [Bip32Path](classes/Bip32Path.md)
21
23
  - [Bip39](classes/Bip39.md)
@@ -1,5 +1,5 @@
1
1
  # Type Alias: KeyType
2
2
 
3
- > **KeyType**: *typeof* [`KeyType`](../variables/KeyType.md)\[keyof *typeof* [`KeyType`](../variables/KeyType.md)\]
3
+ > **KeyType** = *typeof* [`KeyType`](../variables/KeyType.md)\[keyof *typeof* [`KeyType`](../variables/KeyType.md)\]
4
4
 
5
5
  Key types.
package/locales/en.json CHANGED
@@ -31,18 +31,15 @@
31
31
  "sha256": {
32
32
  "bitSize": "Only 224 or 256 bits are supported, it is \"{bitSize}\""
33
33
  },
34
+ "sha3": {
35
+ "bitSize": "Only 224, 256, 384 or 512 bits are supported, it is \"{bitSize}\""
36
+ },
34
37
  "hmacSha256": {
35
38
  "bitSize": "Only 224 or 256 bits are supported, it is \"{bitSize}\""
36
39
  },
37
40
  "hmacSha512": {
38
41
  "bitSize": "Only 224, 256, 384 or 512 bits are supported, it is \"{bitSize}\""
39
42
  },
40
- "base32": {
41
- "invalidCharacter": "Data contains a character \"{invalidCharacter}\" which is not in the charset"
42
- },
43
- "base64": {
44
- "length4Multiple": "Invalid length should be a multiple of 4, it is \"{value}\""
45
- },
46
43
  "bech32": {
47
44
  "decodeFailed": "The address contains decoding failed for address \"{bech32}\"",
48
45
  "invalidChecksum": "The address contains an invalid checksum in address, \"{bech32}\"",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/crypto",
3
- "version": "0.0.1-next.8",
3
+ "version": "0.0.1",
4
4
  "description": "Contains helper methods and classes which implement cryptographic functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,26 +14,26 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@noble/ciphers": "1.0.0",
18
- "@noble/curves": "1.6.0",
19
- "@noble/hashes": "1.5.0",
20
- "@scure/base": "1.1.9",
21
- "@scure/bip32": "1.5.0",
22
- "@scure/bip39": "1.4.0",
23
- "@twin.org/core": "0.0.1-next.8",
24
- "@twin.org/nameof": "next",
25
- "micro-key-producer": "0.7.0"
17
+ "@noble/ciphers": "1.3.0",
18
+ "@noble/curves": "1.9.2",
19
+ "@noble/hashes": "1.8.0",
20
+ "@scure/base": "1.2.6",
21
+ "@scure/bip32": "1.7.0",
22
+ "@scure/bip39": "1.6.0",
23
+ "@twin.org/core": "^0.0.1",
24
+ "@twin.org/nameof": "^0.0.1",
25
+ "micro-key-producer": "0.7.6"
26
26
  },
27
27
  "main": "./dist/cjs/index.cjs",
28
28
  "module": "./dist/esm/index.mjs",
29
29
  "types": "./dist/types/index.d.ts",
30
30
  "exports": {
31
31
  ".": {
32
+ "types": "./dist/types/index.d.ts",
32
33
  "require": "./dist/cjs/index.cjs",
33
- "import": "./dist/esm/index.mjs",
34
- "types": "./dist/types/index.d.ts"
34
+ "import": "./dist/esm/index.mjs"
35
35
  },
36
- "./locales": "./locales"
36
+ "./locales/*.json": "./locales/*.json"
37
37
  },
38
38
  "files": [
39
39
  "dist/cjs",