@twin.org/crypto 0.0.1-next.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 (57) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +31 -0
  3. package/dist/cjs/index.cjs +1572 -0
  4. package/dist/esm/index.mjs +1528 -0
  5. package/dist/types/address/bech32.d.ts +28 -0
  6. package/dist/types/address/bip44.d.ts +53 -0
  7. package/dist/types/ciphers/chaCha20Poly1305.d.ts +24 -0
  8. package/dist/types/curves/ed25519.d.ts +37 -0
  9. package/dist/types/curves/secp256k1.d.ts +37 -0
  10. package/dist/types/curves/x25519.d.ts +18 -0
  11. package/dist/types/curves/zip215.d.ts +15 -0
  12. package/dist/types/hashes/blake2b.d.ts +55 -0
  13. package/dist/types/hashes/hmacSha1.d.ts +28 -0
  14. package/dist/types/hashes/hmacSha256.d.ts +44 -0
  15. package/dist/types/hashes/hmacSha512.d.ts +66 -0
  16. package/dist/types/hashes/pbkdf2.d.ts +23 -0
  17. package/dist/types/hashes/sha1.d.ts +26 -0
  18. package/dist/types/hashes/sha256.d.ts +41 -0
  19. package/dist/types/hashes/sha512.d.ts +61 -0
  20. package/dist/types/index.d.ts +23 -0
  21. package/dist/types/keys/bip32Path.d.ts +40 -0
  22. package/dist/types/keys/bip39.d.ts +36 -0
  23. package/dist/types/keys/slip0010.d.ts +38 -0
  24. package/dist/types/models/keyType.d.ts +17 -0
  25. package/dist/types/otp/hotp.d.ts +14 -0
  26. package/dist/types/otp/totp.d.ts +46 -0
  27. package/dist/types/passwords/passwordGenerator.d.ts +11 -0
  28. package/dist/types/passwords/passwordValidator.d.ts +22 -0
  29. package/docs/changelog.md +5 -0
  30. package/docs/examples.md +1 -0
  31. package/docs/reference/classes/Bech32.md +89 -0
  32. package/docs/reference/classes/Bip32Path.md +117 -0
  33. package/docs/reference/classes/Bip39.md +121 -0
  34. package/docs/reference/classes/Bip44.md +173 -0
  35. package/docs/reference/classes/Blake2b.md +155 -0
  36. package/docs/reference/classes/ChaCha20Poly1305.md +69 -0
  37. package/docs/reference/classes/Ed25519.md +113 -0
  38. package/docs/reference/classes/HmacSha1.md +79 -0
  39. package/docs/reference/classes/HmacSha256.md +123 -0
  40. package/docs/reference/classes/HmacSha512.md +187 -0
  41. package/docs/reference/classes/Hotp.md +39 -0
  42. package/docs/reference/classes/PasswordGenerator.md +33 -0
  43. package/docs/reference/classes/PasswordValidator.md +56 -0
  44. package/docs/reference/classes/Pbkdf2.md +77 -0
  45. package/docs/reference/classes/Secp256k1.md +113 -0
  46. package/docs/reference/classes/Sha1.md +69 -0
  47. package/docs/reference/classes/Sha256.md +111 -0
  48. package/docs/reference/classes/Sha512.md +167 -0
  49. package/docs/reference/classes/Slip0010.md +114 -0
  50. package/docs/reference/classes/Totp.md +148 -0
  51. package/docs/reference/classes/X25519.md +57 -0
  52. package/docs/reference/classes/Zip215.md +43 -0
  53. package/docs/reference/index.md +34 -0
  54. package/docs/reference/type-aliases/KeyType.md +5 -0
  55. package/docs/reference/variables/KeyType.md +19 -0
  56. package/locales/en.json +71 -0
  57. package/package.json +71 -0
@@ -0,0 +1,39 @@
1
+ # Class: Hotp
2
+
3
+ Perform HOTP.
4
+ Implementation of https://datatracker.ietf.org/doc/html/rfc4226 .
5
+
6
+ ## Constructors
7
+
8
+ ### new Hotp()
9
+
10
+ > **new Hotp**(): [`Hotp`](Hotp.md)
11
+
12
+ #### Returns
13
+
14
+ [`Hotp`](Hotp.md)
15
+
16
+ ## Methods
17
+
18
+ ### generate()
19
+
20
+ > `static` **generate**(`key`, `counter`): `string`
21
+
22
+ Generate a counter based One Time Password.
23
+
24
+ #### Parameters
25
+
26
+ • **key**: `Uint8Array`
27
+
28
+ Key for the one time password.
29
+
30
+ • **counter**: `number`
31
+
32
+ This should be stored by the application,
33
+ must be user specific, and be incremented for each request.
34
+
35
+ #### Returns
36
+
37
+ `string`
38
+
39
+ The one time password.
@@ -0,0 +1,33 @@
1
+ # Class: PasswordGenerator
2
+
3
+ Generate random passwords.
4
+
5
+ ## Constructors
6
+
7
+ ### new PasswordGenerator()
8
+
9
+ > **new PasswordGenerator**(): [`PasswordGenerator`](PasswordGenerator.md)
10
+
11
+ #### Returns
12
+
13
+ [`PasswordGenerator`](PasswordGenerator.md)
14
+
15
+ ## Methods
16
+
17
+ ### generate()
18
+
19
+ > `static` **generate**(`length`): `string`
20
+
21
+ Generate a password of given length.
22
+
23
+ #### Parameters
24
+
25
+ • **length**: `number`
26
+
27
+ The length of the password to generate.
28
+
29
+ #### Returns
30
+
31
+ `string`
32
+
33
+ The random password.
@@ -0,0 +1,56 @@
1
+ # Class: PasswordValidator
2
+
3
+ Test password strength.
4
+ Ref https://www.owasp.org/index.php/Authentication_Cheat_Sheet#Implement_Proper_Password_Strength_Controls .
5
+
6
+ ## Constructors
7
+
8
+ ### new PasswordValidator()
9
+
10
+ > **new PasswordValidator**(): [`PasswordValidator`](PasswordValidator.md)
11
+
12
+ #### Returns
13
+
14
+ [`PasswordValidator`](PasswordValidator.md)
15
+
16
+ ## Methods
17
+
18
+ ### validate()
19
+
20
+ > `static` **validate**(`property`, `password`, `failures`, `options`?): `void`
21
+
22
+ Test the strength of the password.
23
+
24
+ #### Parameters
25
+
26
+ • **property**: `string`
27
+
28
+ The name of the property.
29
+
30
+ • **password**: `string`
31
+
32
+ The password to test.
33
+
34
+ • **failures**: `IValidationFailure`[]
35
+
36
+ The list of failures to add to.
37
+
38
+ • **options?**
39
+
40
+ Options to configure the testing.
41
+
42
+ • **options.minLength?**: `number`
43
+
44
+ The minimum length of the password, defaults to 8.
45
+
46
+ • **options.maxLength?**: `number`
47
+
48
+ The minimum length of the password, defaults to 128.
49
+
50
+ • **options.minPhraseLength?**: `number`
51
+
52
+ The minimum length of the password for it to be considered a pass phrase.
53
+
54
+ #### Returns
55
+
56
+ `void`
@@ -0,0 +1,77 @@
1
+ # Class: Pbkdf2
2
+
3
+ Implementation of the password based key derivation function 2.
4
+
5
+ ## Constructors
6
+
7
+ ### new Pbkdf2()
8
+
9
+ > **new Pbkdf2**(): [`Pbkdf2`](Pbkdf2.md)
10
+
11
+ #### Returns
12
+
13
+ [`Pbkdf2`](Pbkdf2.md)
14
+
15
+ ## Methods
16
+
17
+ ### sha256()
18
+
19
+ > `static` **sha256**(`password`, `salt`, `iterations`, `keyLength`): `Uint8Array`
20
+
21
+ Derive a key from the parameters using Sha256.
22
+
23
+ #### Parameters
24
+
25
+ • **password**: `Uint8Array`
26
+
27
+ The password to derive the key from.
28
+
29
+ • **salt**: `Uint8Array`
30
+
31
+ The salt for the derivation.
32
+
33
+ • **iterations**: `number`
34
+
35
+ Number of iterations to perform.
36
+
37
+ • **keyLength**: `number`
38
+
39
+ The length of the key to derive.
40
+
41
+ #### Returns
42
+
43
+ `Uint8Array`
44
+
45
+ The derived key.
46
+
47
+ ***
48
+
49
+ ### sha512()
50
+
51
+ > `static` **sha512**(`password`, `salt`, `iterations`, `keyLength`): `Uint8Array`
52
+
53
+ Derive a key from the parameters using Sha512.
54
+
55
+ #### Parameters
56
+
57
+ • **password**: `Uint8Array`
58
+
59
+ The password to derive the key from.
60
+
61
+ • **salt**: `Uint8Array`
62
+
63
+ The salt for the derivation.
64
+
65
+ • **iterations**: `number`
66
+
67
+ Number of iterations to perform.
68
+
69
+ • **keyLength**: `number`
70
+
71
+ The length of the key to derive.
72
+
73
+ #### Returns
74
+
75
+ `Uint8Array`
76
+
77
+ The derived key.
@@ -0,0 +1,113 @@
1
+ # Class: Secp256k1
2
+
3
+ Implementation of secp256k1.
4
+
5
+ ## Constructors
6
+
7
+ ### new Secp256k1()
8
+
9
+ > **new Secp256k1**(): [`Secp256k1`](Secp256k1.md)
10
+
11
+ #### Returns
12
+
13
+ [`Secp256k1`](Secp256k1.md)
14
+
15
+ ## Properties
16
+
17
+ ### PRIVATE\_KEY\_SIZE
18
+
19
+ > `static` **PRIVATE\_KEY\_SIZE**: `number` = `32`
20
+
21
+ Private Key Size is the size, in bytes, of private keys as used in this package.
22
+
23
+ ***
24
+
25
+ ### PUBLIC\_KEY\_SIZE
26
+
27
+ > `static` **PUBLIC\_KEY\_SIZE**: `number` = `33`
28
+
29
+ Public Key Size is the size, in bytes, of public keys as used in this package.
30
+
31
+ ## Methods
32
+
33
+ ### publicKeyFromPrivateKey()
34
+
35
+ > `static` **publicKeyFromPrivateKey**(`privateKey`): `Uint8Array`
36
+
37
+ Public returns the PublicKey corresponding to private.
38
+
39
+ #### Parameters
40
+
41
+ • **privateKey**: `Uint8Array`
42
+
43
+ The private key to get the corresponding public key.
44
+
45
+ #### Returns
46
+
47
+ `Uint8Array`
48
+
49
+ The public key.
50
+
51
+ #### Throws
52
+
53
+ Error if the private key is not the correct length.
54
+
55
+ ***
56
+
57
+ ### sign()
58
+
59
+ > `static` **sign**(`privateKey`, `block`): `Uint8Array`
60
+
61
+ Sign the block with privateKey and returns a signature.
62
+
63
+ #### Parameters
64
+
65
+ • **privateKey**: `Uint8Array`
66
+
67
+ The private key.
68
+
69
+ • **block**: `Uint8Array`
70
+
71
+ The block to sign.
72
+
73
+ #### Returns
74
+
75
+ `Uint8Array`
76
+
77
+ The signature.
78
+
79
+ #### Throws
80
+
81
+ Error if the private key is not the correct length.
82
+
83
+ ***
84
+
85
+ ### verify()
86
+
87
+ > `static` **verify**(`publicKey`, `block`, `signature`): `boolean`
88
+
89
+ Verify reports whether sig is a valid signature of block by publicKey.
90
+
91
+ #### Parameters
92
+
93
+ • **publicKey**: `Uint8Array`
94
+
95
+ The public key to verify the signature.
96
+
97
+ • **block**: `Uint8Array`
98
+
99
+ The block for the signature.
100
+
101
+ • **signature**: `Uint8Array`
102
+
103
+ The signature.
104
+
105
+ #### Returns
106
+
107
+ `boolean`
108
+
109
+ True if the signature matches.
110
+
111
+ #### Throws
112
+
113
+ Error if the public key is not the correct length.
@@ -0,0 +1,69 @@
1
+ # Class: Sha1
2
+
3
+ Perform a SHA-1 hash on the block.
4
+
5
+ ## Constructors
6
+
7
+ ### new Sha1()
8
+
9
+ > **new Sha1**(): [`Sha1`](Sha1.md)
10
+
11
+ Create a new instance of Sha1.
12
+
13
+ #### Returns
14
+
15
+ [`Sha1`](Sha1.md)
16
+
17
+ ## Methods
18
+
19
+ ### sum()
20
+
21
+ > `static` **sum**(`block`): `Uint8Array`
22
+
23
+ Perform Sum on the block.
24
+
25
+ #### Parameters
26
+
27
+ • **block**: `Uint8Array`
28
+
29
+ The block to operate on.
30
+
31
+ #### Returns
32
+
33
+ `Uint8Array`
34
+
35
+ The sum of the block.
36
+
37
+ ***
38
+
39
+ ### update()
40
+
41
+ > **update**(`block`): [`Sha1`](Sha1.md)
42
+
43
+ Update the hash with the block.
44
+
45
+ #### Parameters
46
+
47
+ • **block**: `Uint8Array`
48
+
49
+ The block to update the hash with.
50
+
51
+ #### Returns
52
+
53
+ [`Sha1`](Sha1.md)
54
+
55
+ The instance for chaining.
56
+
57
+ ***
58
+
59
+ ### digest()
60
+
61
+ > **digest**(): `Uint8Array`
62
+
63
+ Get the digest for the hash.
64
+
65
+ #### Returns
66
+
67
+ `Uint8Array`
68
+
69
+ The instance for chaining.
@@ -0,0 +1,111 @@
1
+ # Class: Sha256
2
+
3
+ Perform a SHA-256 hash on the block.
4
+
5
+ ## Constructors
6
+
7
+ ### new Sha256()
8
+
9
+ > **new Sha256**(`bits`): [`Sha256`](Sha256.md)
10
+
11
+ Create a new instance of Sha256.
12
+
13
+ #### Parameters
14
+
15
+ • **bits**: `number` = `Sha256.SIZE_256`
16
+
17
+ The number of bits.
18
+
19
+ #### Returns
20
+
21
+ [`Sha256`](Sha256.md)
22
+
23
+ ## Properties
24
+
25
+ ### SIZE\_256
26
+
27
+ > `readonly` `static` **SIZE\_256**: `number` = `256`
28
+
29
+ Sha256 256.
30
+
31
+ ***
32
+
33
+ ### SIZE\_224
34
+
35
+ > `readonly` `static` **SIZE\_224**: `number` = `224`
36
+
37
+ Sha256 224.
38
+
39
+ ## Methods
40
+
41
+ ### sum256()
42
+
43
+ > `static` **sum256**(`block`): `Uint8Array`
44
+
45
+ Perform Sum 256 on the block.
46
+
47
+ #### Parameters
48
+
49
+ • **block**: `Uint8Array`
50
+
51
+ The block to operate on.
52
+
53
+ #### Returns
54
+
55
+ `Uint8Array`
56
+
57
+ The sum 256 of the block.
58
+
59
+ ***
60
+
61
+ ### sum224()
62
+
63
+ > `static` **sum224**(`block`): `Uint8Array`
64
+
65
+ Perform Sum 224 on the block.
66
+
67
+ #### Parameters
68
+
69
+ • **block**: `Uint8Array`
70
+
71
+ The block to operate on.
72
+
73
+ #### Returns
74
+
75
+ `Uint8Array`
76
+
77
+ The sum 224 of the block.
78
+
79
+ ***
80
+
81
+ ### update()
82
+
83
+ > **update**(`block`): [`Sha256`](Sha256.md)
84
+
85
+ Update the hash with the block.
86
+
87
+ #### Parameters
88
+
89
+ • **block**: `Uint8Array`
90
+
91
+ The block to update the hash with.
92
+
93
+ #### Returns
94
+
95
+ [`Sha256`](Sha256.md)
96
+
97
+ The instance for chaining.
98
+
99
+ ***
100
+
101
+ ### digest()
102
+
103
+ > **digest**(): `Uint8Array`
104
+
105
+ Get the digest for the hash.
106
+
107
+ #### Returns
108
+
109
+ `Uint8Array`
110
+
111
+ The instance for chaining.
@@ -0,0 +1,167 @@
1
+ # Class: Sha512
2
+
3
+ Perform a SHA-512 hash on the block.
4
+
5
+ ## Constructors
6
+
7
+ ### new Sha512()
8
+
9
+ > **new Sha512**(`bits`): [`Sha512`](Sha512.md)
10
+
11
+ Create a new instance of Sha512.
12
+
13
+ #### Parameters
14
+
15
+ • **bits**: `number` = `Sha512.SIZE_512`
16
+
17
+ The number of bits.
18
+
19
+ #### Returns
20
+
21
+ [`Sha512`](Sha512.md)
22
+
23
+ ## Properties
24
+
25
+ ### SIZE\_224
26
+
27
+ > `static` **SIZE\_224**: `number` = `224`
28
+
29
+ Sha512 224.
30
+
31
+ ***
32
+
33
+ ### SIZE\_256
34
+
35
+ > `static` **SIZE\_256**: `number` = `256`
36
+
37
+ Sha512 256.
38
+
39
+ ***
40
+
41
+ ### SIZE\_384
42
+
43
+ > `static` **SIZE\_384**: `number` = `384`
44
+
45
+ Sha512 384.
46
+
47
+ ***
48
+
49
+ ### SIZE\_512
50
+
51
+ > `static` **SIZE\_512**: `number` = `512`
52
+
53
+ Sha512 512.
54
+
55
+ ## Methods
56
+
57
+ ### sum512()
58
+
59
+ > `static` **sum512**(`block`): `Uint8Array`
60
+
61
+ Perform Sum 512 on the block.
62
+
63
+ #### Parameters
64
+
65
+ • **block**: `Uint8Array`
66
+
67
+ The block to operate on.
68
+
69
+ #### Returns
70
+
71
+ `Uint8Array`
72
+
73
+ The sum 512 of the block.
74
+
75
+ ***
76
+
77
+ ### sum384()
78
+
79
+ > `static` **sum384**(`block`): `Uint8Array`
80
+
81
+ Perform Sum 384 on the block.
82
+
83
+ #### Parameters
84
+
85
+ • **block**: `Uint8Array`
86
+
87
+ The block to operate on.
88
+
89
+ #### Returns
90
+
91
+ `Uint8Array`
92
+
93
+ The sum 384 of the block.
94
+
95
+ ***
96
+
97
+ ### sum256()
98
+
99
+ > `static` **sum256**(`block`): `Uint8Array`
100
+
101
+ Perform Sum 256 on the block.
102
+
103
+ #### Parameters
104
+
105
+ • **block**: `Uint8Array`
106
+
107
+ The block to operate on.
108
+
109
+ #### Returns
110
+
111
+ `Uint8Array`
112
+
113
+ The sum 256 of the block.
114
+
115
+ ***
116
+
117
+ ### sum224()
118
+
119
+ > `static` **sum224**(`block`): `Uint8Array`
120
+
121
+ Perform Sum 224 on the block.
122
+
123
+ #### Parameters
124
+
125
+ • **block**: `Uint8Array`
126
+
127
+ The block to operate on.
128
+
129
+ #### Returns
130
+
131
+ `Uint8Array`
132
+
133
+ The sum 224 of the block.
134
+
135
+ ***
136
+
137
+ ### update()
138
+
139
+ > **update**(`block`): [`Sha512`](Sha512.md)
140
+
141
+ Update the hash with the block.
142
+
143
+ #### Parameters
144
+
145
+ • **block**: `Uint8Array`
146
+
147
+ The block to update the hash with.
148
+
149
+ #### Returns
150
+
151
+ [`Sha512`](Sha512.md)
152
+
153
+ The instance for chaining.
154
+
155
+ ***
156
+
157
+ ### digest()
158
+
159
+ > **digest**(): `Uint8Array`
160
+
161
+ Get the digest for the hash.
162
+
163
+ #### Returns
164
+
165
+ `Uint8Array`
166
+
167
+ The instance for chaining.