@kynesyslabs/demosdk 1.0.21 → 1.0.23

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 (180) hide show
  1. package/build/encryption/Cryptography.d.ts +18 -1
  2. package/build/encryption/Cryptography.js +182 -1
  3. package/build/encryption/Cryptography.js.map +1 -1
  4. package/build/encryption/Hashing.d.ts +1 -1
  5. package/build/encryption/Hashing.js +2 -1
  6. package/build/encryption/Hashing.js.map +1 -1
  7. package/build/encryption/index.d.ts +2 -2
  8. package/build/encryption/index.js +4 -2
  9. package/build/encryption/index.js.map +1 -1
  10. package/build/index.d.ts +1 -0
  11. package/build/index.js +2 -1
  12. package/build/index.js.map +1 -1
  13. package/build/multichain/core/solana.d.ts +16 -29
  14. package/build/multichain/core/solana.js +40 -126
  15. package/build/multichain/core/solana.js.map +1 -1
  16. package/build/multichain/core/types/defaultChain.d.ts +0 -18
  17. package/build/multichain/localsdk/index.d.ts +5 -4
  18. package/build/multichain/localsdk/index.js +3 -1
  19. package/build/multichain/localsdk/index.js.map +1 -1
  20. package/build/multichain/localsdk/solana.d.ts +1 -3
  21. package/build/multichain/localsdk/solana.js +5 -10
  22. package/build/multichain/localsdk/solana.js.map +1 -1
  23. package/build/multichain/websdk/index.d.ts +1 -0
  24. package/build/multichain/websdk/index.js +3 -1
  25. package/build/multichain/websdk/index.js.map +1 -1
  26. package/build/multichain/websdk/solana.d.ts +4 -0
  27. package/build/multichain/websdk/solana.js +11 -0
  28. package/build/multichain/websdk/solana.js.map +1 -0
  29. package/build/types/blockchain/Confirmation.d.ts +9 -0
  30. package/build/types/blockchain/Confirmation.js +23 -0
  31. package/build/types/blockchain/Confirmation.js.map +1 -0
  32. package/build/types/blockchain/WalletTypes.d.ts +3 -0
  33. package/build/types/blockchain/WalletTypes.js +3 -0
  34. package/build/types/blockchain/WalletTypes.js.map +1 -0
  35. package/build/utils/dataManipulation.d.ts +1 -0
  36. package/build/utils/dataManipulation.js +5 -1
  37. package/build/utils/dataManipulation.js.map +1 -1
  38. package/build/utils/getRemoteIP.d.ts +1 -0
  39. package/build/utils/getRemoteIP.js +19 -0
  40. package/build/utils/getRemoteIP.js.map +1 -0
  41. package/build/wallet/Wallet.d.ts +25 -0
  42. package/build/wallet/Wallet.js +94 -0
  43. package/build/wallet/Wallet.js.map +1 -0
  44. package/build/wallet/index.d.ts +1 -0
  45. package/build/wallet/index.js +28 -0
  46. package/build/wallet/index.js.map +1 -0
  47. package/build/websdk/DemosTransactions.d.ts +1 -1
  48. package/build/websdk/DemosTransactions.js +3 -2
  49. package/build/websdk/DemosTransactions.js.map +1 -1
  50. package/build/websdk/demos.d.ts +2 -2
  51. package/package.json +55 -57
  52. package/.eslintignore +0 -6
  53. package/.eslintrc.cjs +0 -31
  54. package/.gitattributes +0 -4
  55. package/.github/workflows/publish.yml +0 -43
  56. package/.github/workflows/test:multichain.yml +0 -35
  57. package/.gitignore +0 -8
  58. package/.prettierrc +0 -13
  59. package/build/tests/multichain/chainProviders.d.ts +0 -29
  60. package/build/tests/multichain/chainProviders.js +0 -34
  61. package/build/tests/multichain/chainProviders.js.map +0 -1
  62. package/build/tests/multichain/evm.test.d.ts +0 -1
  63. package/build/tests/multichain/evm.test.js +0 -53
  64. package/build/tests/multichain/evm.test.js.map +0 -1
  65. package/build/tests/multichain/ibc.test.d.ts +0 -1
  66. package/build/tests/multichain/ibc.test.js +0 -74
  67. package/build/tests/multichain/ibc.test.js.map +0 -1
  68. package/build/tests/multichain/index.d.ts +0 -1
  69. package/build/tests/multichain/index.js +0 -94
  70. package/build/tests/multichain/index.js.map +0 -1
  71. package/build/tests/multichain/multiversx.test.d.ts +0 -1
  72. package/build/tests/multichain/multiversx.test.js +0 -49
  73. package/build/tests/multichain/multiversx.test.js.map +0 -1
  74. package/build/tests/multichain/solana.spec.d.ts +0 -1
  75. package/build/tests/multichain/solana.spec.js +0 -50
  76. package/build/tests/multichain/solana.spec.js.map +0 -1
  77. package/build/tests/multichain/template.test.d.ts +0 -0
  78. package/build/tests/multichain/template.test.js +0 -33
  79. package/build/tests/multichain/template.test.js.map +0 -1
  80. package/build/tests/multichain/xrpl.test.d.ts +0 -1
  81. package/build/tests/multichain/xrpl.test.js +0 -57
  82. package/build/tests/multichain/xrpl.test.js.map +0 -1
  83. package/build/tests/utils/index.d.ts +0 -14
  84. package/build/tests/utils/index.js +0 -34
  85. package/build/tests/utils/index.js.map +0 -1
  86. package/build/tests/utils/wallets.d.ts +0 -21
  87. package/build/tests/utils/wallets.js +0 -48
  88. package/build/tests/utils/wallets.js.map +0 -1
  89. package/build/tests/utils.test.d.ts +0 -1
  90. package/build/tests/utils.test.js +0 -19
  91. package/build/tests/utils.test.js.map +0 -1
  92. package/documentation/multichain/README.md +0 -85
  93. package/documentation/multichain/ibc.md +0 -3
  94. package/documentation/multichain/solana.md +0 -13
  95. package/jest.config.ts +0 -20
  96. package/src/encryption/Cryptography.ts +0 -128
  97. package/src/encryption/FHE/index.ts +0 -35
  98. package/src/encryption/Hashing.ts +0 -20
  99. package/src/encryption/PQC/index.ts +0 -260
  100. package/src/encryption/index.ts +0 -5
  101. package/src/encryption/zK/index.ts +0 -1
  102. package/src/encryption/zK/interactive/index.ts +0 -47
  103. package/src/encryption/zK/primer.ts +0 -71
  104. package/src/index.ts +0 -8
  105. package/src/multichain/archive/btc.ts +0 -72
  106. package/src/multichain/archive/demos.ts +0 -51
  107. package/src/multichain/archive/tron.ts +0 -86
  108. package/src/multichain/archive/xlm.ts +0 -65
  109. package/src/multichain/core/README.md +0 -1
  110. package/src/multichain/core/evm.ts +0 -275
  111. package/src/multichain/core/ibc.ts +0 -318
  112. package/src/multichain/core/index.ts +0 -29
  113. package/src/multichain/core/multiversx.ts +0 -310
  114. package/src/multichain/core/solana.ts +0 -336
  115. package/src/multichain/core/types/defaultChain.ts +0 -254
  116. package/src/multichain/core/types/interfaces.ts +0 -102
  117. package/src/multichain/core/utils.ts +0 -22
  118. package/src/multichain/core/xrp.ts +0 -253
  119. package/src/multichain/index.ts +0 -3
  120. package/src/multichain/localsdk/README.md +0 -1
  121. package/src/multichain/localsdk/evm.ts +0 -77
  122. package/src/multichain/localsdk/ibc.ts +0 -25
  123. package/src/multichain/localsdk/index.ts +0 -4
  124. package/src/multichain/localsdk/multiversx.ts +0 -66
  125. package/src/multichain/localsdk/solana.ts +0 -37
  126. package/src/multichain/localsdk/xrp.ts +0 -56
  127. package/src/multichain/websdk/README.md +0 -1
  128. package/src/multichain/websdk/evm.ts +0 -9
  129. package/src/multichain/websdk/ibc.ts +0 -10
  130. package/src/multichain/websdk/index.ts +0 -4
  131. package/src/multichain/websdk/multiversx.ts +0 -84
  132. package/src/multichain/websdk/xrp.ts +0 -9
  133. package/src/tests/multichain/chainProviders.ts +0 -32
  134. package/src/tests/multichain/evm.test.ts +0 -64
  135. package/src/tests/multichain/ibc.test.ts +0 -93
  136. package/src/tests/multichain/index.ts +0 -105
  137. package/src/tests/multichain/multiversx.test.ts +0 -57
  138. package/src/tests/multichain/solana.spec.ts +0 -56
  139. package/src/tests/multichain/template.test.ts +0 -37
  140. package/src/tests/multichain/xrpl.test.ts +0 -71
  141. package/src/tests/utils/index.ts +0 -34
  142. package/src/tests/utils/wallets.ts +0 -46
  143. package/src/tests/utils.test.ts +0 -21
  144. package/src/types/blockchain/ISignature.ts +0 -6
  145. package/src/types/blockchain/Transaction.ts +0 -34
  146. package/src/types/blockchain/TxFee.ts +0 -5
  147. package/src/types/blockchain/ValidityData.ts +0 -15
  148. package/src/types/blockchain/addressInfo.ts +0 -7
  149. package/src/types/blockchain/blocks.ts +0 -29
  150. package/src/types/blockchain/genesisTypes.ts +0 -39
  151. package/src/types/blockchain/rawTransaction.ts +0 -27
  152. package/src/types/blockchain/statusNative.ts +0 -6
  153. package/src/types/blockchain/statusProperties.ts +0 -8
  154. package/src/types/communication/transmit.ts +0 -27
  155. package/src/types/gls/Operation.ts +0 -25
  156. package/src/types/gls/StateChange.ts +0 -33
  157. package/src/types/index.ts +0 -60
  158. package/src/types/network/ExecutionResult.ts +0 -9
  159. package/src/types/network/SecurityTypes.ts +0 -18
  160. package/src/types/peers/Peer.ts +0 -18
  161. package/src/types/web2/index.ts +0 -76
  162. package/src/types/xm/index.ts +0 -21
  163. package/src/utils/dataManipulation.ts +0 -37
  164. package/src/utils/index.ts +0 -1
  165. package/src/websdk/DemosTransactions.ts +0 -74
  166. package/src/websdk/DemosWebAuth.ts +0 -186
  167. package/src/websdk/Web2Transactions.ts +0 -41
  168. package/src/websdk/XMTransactions.ts +0 -140
  169. package/src/websdk/demos.ts +0 -461
  170. package/src/websdk/index.ts +0 -15
  171. package/src/websdk/rsa.ts +0 -85
  172. package/src/websdk/types/IBuffer.ts +0 -4
  173. package/src/websdk/types/KeyPair.ts +0 -9
  174. package/src/websdk/utils/bufferizer.ts +0 -16
  175. package/src/websdk/utils/forge_converter.ts +0 -72
  176. package/src/websdk/utils/required.ts +0 -44
  177. package/src/websdk/utils/sha256.ts +0 -13
  178. package/src/websdk/utils/skeletons.ts +0 -69
  179. package/tsconfig.json +0 -34
  180. package/yarn.lock +0 -3705
@@ -1,260 +0,0 @@
1
- /* INFO Enigma - An experimental wrapper for Post Quantum Cryptography in Typescript designed with ease of use in mind
2
-
3
- LICENSE
4
-
5
- © 2023 by KyneSys Labs, licensed under CC BY-NC-ND 4.0
6
-
7
- Full license text: https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode
8
- Human readable license: https://creativecommons.org/licenses/by-nc-nd/4.0/
9
-
10
- KyneSys Labs: https://www.kynesys.xyz/
11
-
12
- This module incorporates two Post Quantum Cryptography methods:
13
- - Rijndael: symmetric encryption algorithm considered the state of the art of its category
14
- - Argon2: quantum-safe hashing algorithm
15
- - McEliece: post-quantum cryptography algorithm that uses a keypair to share secrets between two parties.
16
- - Dilithium: post-quantum cryptography algorithm that uses a keypair to sign and verify messages.
17
-
18
- The Rijdael algorithm is a symmetric encryption algorithm and as many of the most used symmetric encryption algorithms
19
- is considered to be quantum-safe. While even standard AES-256 is considered to be quantum-safe, the Rijndael algorithm
20
- is considered to improve robustness, performance, and security when compared to standard AES-256 as AES specification
21
- is a subset of Rijdael algorithm itself.
22
-
23
- The Argon2 algorithm is a quantum-safe hashing algorithm that is designed to protect against various dehashing attacks.
24
- It is used to replace less secure hashing algorithms such as SHA-1, SHA-256, and so on.
25
-
26
- The McEliece algorithm is used to encrypt and decrypt messages, much like a symmetric classic encryption algorithm.
27
- Thanks to its post-quantum security, however, it is not possible to retrieve the secrets as easily as with a classic algorithm.
28
- We use McEliece to exchange a long-term secret between two parties. This secret will be the base to generate one-time secrets
29
- encrypted with McEliece itself that will be used to generate one-time symmetric keys.
30
-
31
- The Dilithium algorithm is used to sign and verify messages, much like algorithms like ed25519.
32
- Apart from providing post quantum security, the Dilithium algorithm is also capable of generating combined signed messages
33
- that can be used to verify signatures without sharing the initial message, as proofs of authenticity.
34
-
35
- Credits:
36
- - https://github.com/Snack-X for https://github.com/Snack-X/rijndael-js
37
- - https://github.com/ranisalt for https://github.com/ranisalt/node-argon2
38
- - https://github.com/cyph for its https://github.com/cyph/pqcrypto.js library (superdilithium, supersphincs and a lot of knowledge)
39
- - https://github.com/tniessen for its https://github.com/tniessen/node-mceliece-nist library (mceliece and a lot of knowledge too)
40
- - I can't find the ntru library developer unfortunately, feel free to contact me if its you
41
-
42
- */
43
- import argon2 from "argon2"
44
- // import { superSphincs } from "supersphincs" // Same as above, just replace the two strings
45
- import { McEliece } from "mceliece-nist"
46
- import Rijndael from "rijndael-js"
47
- import { superDilithium } from "superdilithium"
48
-
49
- // import {ntru} from "ntru" // Interchangeable with McEliece
50
-
51
- // INFO Interface to happily work with almost any keypair
52
- export interface IKeypair {
53
- privateKey: Uint8Array
54
- publicKey: Uint8Array
55
- }
56
-
57
- // INFO Main class
58
- export default class Enigma {
59
- signingKeyPair: IKeypair = null
60
- mcelieceKeypair: IKeypair = null
61
-
62
- private kem: McEliece = new McEliece("mceliece8192128")
63
-
64
- constructor() {}
65
-
66
- async init() {
67
- this.signingKeyPair = await superDilithium.keyPair()
68
- this.mcelieceKeypair = this.kem.keypair()
69
- }
70
-
71
- /* SECTION Signatures with superDilithium */
72
-
73
- async combinedSign(
74
- message: string,
75
- additionalData: string = null,
76
- ): Promise<Uint8Array> {
77
- let bufMessage = Buffer.from(message, "utf8")
78
- let signed: Uint8Array
79
- if (additionalData) {
80
- let bufAdditionalData = Buffer.from(additionalData, "utf8")
81
- signed = await superDilithium.sign(
82
- bufMessage,
83
- this.signingKeyPair.privateKey,
84
- bufAdditionalData,
85
- )
86
- } else {
87
- signed = await superDilithium.sign(
88
- bufMessage,
89
- this.signingKeyPair.privateKey,
90
- )
91
- }
92
- return signed
93
- }
94
-
95
- async combinedVerify(
96
- signed: Uint8Array,
97
- publicKey: Uint8Array,
98
- additionalData: string = null,
99
- ): Promise<Uint8Array> {
100
- let verifyData: Uint8Array
101
- if (additionalData) {
102
- let bufAdditionalData = Buffer.from(additionalData, "utf8")
103
- verifyData = await superDilithium.open(
104
- signed,
105
- publicKey,
106
- bufAdditionalData,
107
- )
108
- } else {
109
- verifyData = await superDilithium.open(signed, publicKey)
110
- }
111
- return verifyData
112
- }
113
-
114
- async sign(
115
- message: string | Uint8Array,
116
- additionalData: string | Uint8Array = null,
117
- ) {
118
- if (typeof message === "string") {
119
- message = Buffer.from(message, "utf8")
120
- }
121
- if (typeof additionalData === "string") {
122
- additionalData = Buffer.from(additionalData, "utf8")
123
- }
124
- // Signing
125
- let signed: Uint8Array
126
- if (additionalData) {
127
- signed = await superDilithium.signDetached(
128
- message,
129
- this.signingKeyPair.privateKey,
130
- additionalData,
131
- )
132
- } else {
133
- signed = await superDilithium.signDetached(
134
- message,
135
- this.signingKeyPair.privateKey,
136
- )
137
- }
138
- return signed
139
- }
140
-
141
- async verify(
142
- signature: Uint8Array,
143
- message: string | Uint8Array,
144
- publicKey: Uint8Array,
145
- additionalData: string | Uint8Array = null,
146
- ) {
147
- if (typeof message === "string") {
148
- message = Buffer.from(message, "utf8")
149
- }
150
- if (typeof additionalData === "string") {
151
- additionalData = Buffer.from(additionalData, "utf8")
152
- }
153
- // Verifying
154
- let verified: boolean
155
- if (additionalData) {
156
- verified = await superDilithium.verifyDetached(
157
- signature,
158
- message,
159
- publicKey,
160
- additionalData,
161
- )
162
- } else {
163
- verified = await superDilithium.verifyDetached(
164
- signature,
165
- message,
166
- publicKey,
167
- )
168
- }
169
- return verified
170
- }
171
-
172
- async exportSigningKeys(passphrase: string = null): Promise<any> {
173
- let storage: any
174
- if (passphrase) {
175
- storage = await superDilithium.exportKeys(
176
- this.signingKeyPair,
177
- passphrase,
178
- )
179
- } else {
180
- storage = await superDilithium.exportKeys(this.signingKeyPair)
181
- }
182
- return storage
183
- }
184
-
185
- async importSigningKeys(
186
- storage: any,
187
- passphrase: string = null,
188
- ): Promise<any> {
189
- if (passphrase) {
190
- this.signingKeyPair = await superDilithium.importKeys(
191
- storage,
192
- passphrase,
193
- )
194
- } else {
195
- this.signingKeyPair = await superDilithium.importKeys(storage)
196
- }
197
- return this.signingKeyPair
198
- }
199
-
200
- /* SECTION Keys generation and incapsulation with McEliece */
201
-
202
- // Incapsulate a secret with a public key
203
- async generateSecrets(peerPublicKey: any) {
204
- let { key, encryptedKey } = await this.kem.generateKey(peerPublicKey)
205
- let normalizedResult = {
206
- secret: key,
207
- shared: encryptedKey,
208
- }
209
- return normalizedResult
210
- }
211
-
212
- // Decapsulate a secret from a shared secret
213
- async deriveSharedSecret(shared: any) {
214
- let secret = await this.kem.decryptKey(
215
- this.mcelieceKeypair.privateKey,
216
- shared,
217
- )
218
- return secret
219
- }
220
-
221
- /* SECTION Hashing with Argon2 */
222
-
223
- async hash(input: string | Buffer): Promise<string> {
224
- if (typeof input === "string") {
225
- input = Buffer.from(input, "utf8")
226
- }
227
- let hash = await argon2.hash(input)
228
- return hash
229
- }
230
-
231
- async checkHash(input: string | Buffer, hash: string): Promise<boolean> {
232
- if (typeof input === "string") {
233
- input = Buffer.from(input, "utf8")
234
- }
235
- if (await argon2.verify(hash, input)) {
236
- return true
237
- } else {
238
- return false
239
- }
240
- }
241
-
242
- /* SECTION Symmetric encryption and decryption with Rijndael */
243
-
244
- async encrypt(input: string, key: string): Promise<Buffer> {
245
- // Key can be 16/24/32 bytes long (128/192/256 bit)
246
- let cipher = new Rijndael(key, "cbc")
247
- let ciphertext = Buffer.from(
248
- cipher.encrypt(input, "256", "Ut enim ad minim veniam, quis no"),
249
- ) // TODO Custom iv same block size
250
- return ciphertext
251
- }
252
-
253
- async decrypt(input: Buffer, key: string): Promise<Buffer> {
254
- let cipher = new Rijndael(key, "cbc")
255
- let plainbuffer = Buffer.from(
256
- cipher.decrypt(input, "256", "Ut enim ad minim veniam, quis no"),
257
- )
258
- return plainbuffer
259
- }
260
- }
@@ -1,5 +0,0 @@
1
- export * as FHE from './FHE'
2
- export * as PQC from './PQC'
3
- export * as zK from './zK'
4
- export * as Cryptography from './Cryptography'
5
- export * as Hashing from './Hashing'
@@ -1 +0,0 @@
1
- export * as interactive from './interactive' // interactive.Prover and interactive.Verifier
@@ -1,47 +0,0 @@
1
- import bigInt from "big-integer"
2
- import generateLargePrime from "@/encryption/zK/primer"
3
-
4
- export class Prover {
5
- private secret: bigInt.BigInteger
6
- public modulus: any
7
- private randomValue: any
8
-
9
- constructor(prime1: any, prime2: any, secret: bigInt.BigInteger) {
10
- this.modulus = prime1.multiply(prime2)
11
- this.secret = secret
12
- }
13
-
14
- generateCommitment(): any {
15
- this.randomValue = bigInt.randBetween(2, this.modulus.subtract(2))
16
- return this.randomValue.modPow(2, this.modulus)
17
- }
18
-
19
- respondToChallenge(challenge: number): any {
20
- return challenge === 0
21
- ? this.randomValue
22
- : this.randomValue.multiply(this.secret).mod(this.modulus)
23
- }
24
- }
25
-
26
- export class Verifier {
27
- private modulus: any
28
- private commitment: any
29
-
30
- constructor(modulus: any) {
31
- this.modulus = modulus
32
- }
33
-
34
- generateChallenge(commitment: any): number {
35
- this.commitment = commitment
36
- return Math.round(Math.random())
37
- }
38
-
39
- verifyResponse(response: any, challenge: number): boolean {
40
- const responseSquared = response.modPow(2, this.modulus)
41
- if (challenge === 0) {
42
- return responseSquared.equals(this.commitment)
43
- } else {
44
- return !responseSquared.equals(this.commitment)
45
- }
46
- }
47
- }
@@ -1,71 +0,0 @@
1
- import bigInt, { BigInteger } from "big-integer"
2
-
3
- function isSmallPrimeDivisorPresent(n: BigInteger): boolean {
4
- const smallPrimes = [
5
- 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
6
- 71, 73, 79, 83, 89, 97,
7
- ]
8
- for (const prime of smallPrimes) {
9
- if (n.mod(prime).isZero()) {
10
- return true
11
- }
12
- }
13
- return false
14
- }
15
-
16
- function millerRabinTest(n: BigInteger, k: number): boolean {
17
- if (n.leq(1) || n.equals(2)) return n.equals(2)
18
- if (n.isEven()) return false
19
-
20
- // Optimization: Check for small prime divisors first
21
- if (isSmallPrimeDivisorPresent(n)) return false
22
-
23
- let r = 0
24
- let d = n.minus(1)
25
- const two = bigInt(2)
26
-
27
- // Precompute values
28
- const nMinusOne = n.minus(1)
29
- const nMinusTwo = n.minus(2)
30
-
31
- while (d.isEven()) {
32
- r++
33
- d = d.divide(two)
34
- }
35
-
36
- for (let i = 0; i < k; i++) {
37
- const a = bigInt.randBetween(two, nMinusTwo)
38
- let x = a.modPow(d, n)
39
- if (x.equals(1) || x.equals(nMinusOne)) continue
40
-
41
- let continueLoop = false
42
- for (let j = 0; j < r - 1; j++) {
43
- x = x.modPow(two, n)
44
- if (x.equals(nMinusOne)) {
45
- continueLoop = true
46
- break
47
- }
48
- }
49
- if (continueLoop) continue
50
- return false
51
- }
52
- return true
53
- }
54
-
55
- export default function generateLargePrime(
56
- bits: number,
57
- testRounds: number,
58
- ): BigInteger {
59
- if (bits < 2) throw new Error("Bit-length must be >= 2")
60
-
61
- // Precompute powers of two
62
- const twoPowBitsMinusOne = bigInt(2).pow(bits - 1)
63
- const twoPowBits = bigInt(2).pow(bits)
64
-
65
- let prime: BigInteger
66
- do {
67
- prime = bigInt.randBetween(twoPowBitsMinusOne, twoPowBits.subtract(1))
68
- } while (!millerRabinTest(prime, testRounds))
69
-
70
- return prime
71
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- // Common types and constants
2
- export * as types from './types'
3
- // Basic cryptographic and data manipulation functions
4
- export * as encryption from './encryption'
5
- export * as utils from './utils'
6
- // Specific features of the SDK
7
- export * as xmlocalsdk from './multichain/localsdk'
8
- export * as xmwebsdk from './multichain/websdk'
@@ -1,72 +0,0 @@
1
- import BIP32Factory, { BIP32Interface } from "bip32"
2
- import * as bip39 from "bip39"
3
- import * as bitcoin from "bitcoinjs-lib"
4
- import * as ecc from "tiny-secp256k1"
5
-
6
- import defaultChainAsync from "./types/defaultChainAsync"
7
-
8
- const bip32 = BIP32Factory(ecc)
9
-
10
- // NOTE BIP32 implementation follows:
11
- // LINK https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts
12
-
13
- export default class BTC extends defaultChainAsync {
14
- constructor(rpc_url: string) {
15
- super(rpc_url)
16
- this.name = "BTC"
17
- }
18
-
19
- async connect(rpc_url: string): Promise<boolean> {
20
- throw new Error("Method not implemented.")
21
- }
22
- async disconnect(): Promise<any> {
23
- throw new Error("Method not implemented.")
24
- }
25
- async getBalance(address: string): Promise<string> {
26
- const response = await fetch(
27
- `https://blockchain.info/q/addressbalance/${address}`,
28
- )
29
- const balance = await response.text()
30
- return balance
31
- }
32
-
33
- pay(receiver: string, amount: string): Promise<any> {
34
- throw new Error("Method not implemented.")
35
- }
36
- async info(account: BIP32Interface): Promise<string> {
37
- let address = bitcoin.payments.p2pkh({
38
- pubkey: account.publicKey,
39
- }).address!
40
- return JSON.stringify(address)
41
- }
42
-
43
- createWallet(): any {
44
- // TODO Generate mnemonic
45
- let mnemonic
46
- let path = "m/0'/0/0"
47
- let seed = bip39.mnemonicToSeedSync(mnemonic)
48
- let root = bip32.fromSeed(seed)
49
- this.wallet = root.derivePath(path) // REVIEW is this right?
50
- }
51
-
52
- // INFO Accepting base58 encoded private keys like:
53
- // tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK
54
- // NOTE Alternatively you can pass in a mnemonic phrase to generate the private key.
55
- connectWallet(privateKey: string, mnemonic: boolean = false) {
56
- if (!mnemonic) {
57
- this.wallet = bip32.fromBase58(privateKey)
58
- } else {
59
- // Generating the seed and the private key from the mnemonic
60
- let seed = bip39.mnemonicToSeedSync(privateKey)
61
- let node = bip32.fromSeed(seed)
62
- let strng = node.toBase58()
63
- this.wallet = bip32.fromBase58(strng)
64
- }
65
- }
66
- signTransaction(raw_transaction: any): Promise<any> {
67
- throw new Error("Method not implemented.")
68
- }
69
- sendTransaction(signed_transaction: any) {
70
- throw new Error("Method not implemented.")
71
- }
72
- }
@@ -1,51 +0,0 @@
1
- import DefaultChainAsync from "./types/defaultChainAsync";
2
-
3
- export default class DEMOS extends DefaultChainAsync {
4
-
5
- provider = null
6
- wallet = null
7
- rpc_url = null
8
- connected = false
9
-
10
- constructor(rpc_url = null) {
11
- super(rpc_url)
12
- this.provider = null
13
- this.wallet = null
14
- if (rpc_url) {
15
- this.setRPC(rpc_url)
16
- }
17
- }
18
-
19
- // SECTION Unimplemented methods
20
-
21
- connect(rpc_url: string): Promise<any> {
22
- throw new Error("Method not implemented.");
23
- }
24
-
25
- async setRPC(rpc_url: string) {
26
- throw new Error("Method not implemented.");
27
- }
28
-
29
- getBalance(address: string): Promise<string> {
30
- throw new Error("Method not implemented.");
31
- }
32
- prepareTransfer(receiver: string, amount: string): Promise<any> {
33
- throw new Error("Method not implemented.");
34
- }
35
- preparePay(receiver: string, amount: string): Promise<any> {
36
- throw new Error("Method not implemented.");
37
- }
38
- getEmptyTransaction() {
39
- throw new Error("Method not implemented.");
40
- }
41
- getAddress(): string {
42
- throw new Error("Method not implemented.");
43
- }
44
- connectWallet(privateKey: string) {
45
- throw new Error("Method not implemented.");
46
- }
47
- signTransaction(raw_transaction: any): Promise<any> {
48
- throw new Error("Method not implemented.");
49
- }
50
-
51
- }
@@ -1,86 +0,0 @@
1
- import required from '../../utils/required'
2
- const TronWeb = require('tronweb')
3
- import DefaultChainAsync from './types/defaultChainAsync'
4
-
5
- export default class TRON extends DefaultChainAsync {
6
-
7
- provider = null
8
- wallet = null
9
- rpc_url = null
10
- connected = false
11
-
12
- // NOTE We init TRON with await TRON.create(rpc_url)
13
- // This is necessary to ensure that the provider is connected
14
- // if the user specifies the rpc_url in the constructor,
15
- // as we cannot use await in the constructor
16
- constructor (rpc_url = null) {
17
- super(rpc_url)
18
- if (rpc_url) {
19
- this.setRPC(rpc_url)
20
- }
21
- this.wallet = null
22
- this.provider = null
23
- }
24
-
25
- // INFO Set of methods for connecting to an RPC while
26
- // retaining a granular control over the instance status
27
- async setRPC (rpc_url: string) {
28
- this.rpc_url = rpc_url
29
- this.provider = new TronWeb({
30
- fullHost: this.rpc_url
31
- })
32
- }
33
-
34
- async connect () {
35
- return this.provider
36
- }
37
-
38
- static async create (rpc_url = null) {
39
- const instance = new TRON(rpc_url)
40
- if (rpc_url) { await instance.connect() }
41
- return instance
42
- }
43
-
44
- // INFO Connecting a wallet through a private key (string)
45
- async connectWallet (privateKey: string, api_key = '') {
46
- required(this.provider, true)
47
-
48
- this.wallet = new TronWeb({
49
- fullHost: 'https://api.shasta.trongrid.io',
50
- privateKey,
51
- headers: { 'TRON-PRO-API-KEY': api_key }
52
- })
53
- }
54
-
55
- // INFO Signing a transaction
56
- // with a private key or by using our stored wallet
57
- async signTransaction (transaction: Transaction, privateKey = null) {
58
- // TODO
59
- }
60
-
61
- // SECTION Specific methods
62
-
63
- // INFO transfer and pay are the same
64
- async prepareTransfer (address: any, amount: any) {
65
- await this.preparePay(address, amount)
66
- }
67
-
68
- async preparePay (address: string, amount: string) {
69
- required(this.wallet, true)
70
- // TODO
71
- }
72
-
73
- // INFO Generic empty tx skeleton for this chain
74
- async getEmptyTransaction () {
75
- // TODO
76
- }
77
-
78
- // SECTION Unimplemented methods
79
-
80
- getBalance(address: string): Promise<string> {
81
- throw new Error('Method not implemented.')
82
- }
83
- getAddress(): string {
84
- throw new Error('Method not implemented.')
85
- }
86
- }
@@ -1,65 +0,0 @@
1
- /* LICENSE
2
-
3
- © 2023 by KyneSys Labs, licensed under CC BY-NC-ND 4.0
4
-
5
- Full license text: https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode
6
- Human readable license: https://creativecommons.org/licenses/by-nc-nd/4.0/
7
-
8
- KyneSys Labs: https://www.kynesys.xyz/
9
-
10
- */
11
-
12
- // LINK https://github.com/stellar/js-stellar-sdk/tree/master/docs/reference
13
-
14
- import required from "src/utilities/required"
15
- import * as StellarSdk from "stellar-sdk"
16
-
17
- import Server from "../../../src/libs/network/server"
18
- import defaultChainAsync from "./types/defaultChainAsync"
19
-
20
- // TODO Find a way to make things in the next link much more unified
21
- // LINK https://github.com/stellar/js-stellar-base/blob/master/docs/reference/building-transactions.md
22
- export default class XLM extends defaultChainAsync {
23
- constructor(rpcURL: string) {
24
- super(rpcURL)
25
- this.name = "xlm"
26
- }
27
-
28
- public async connect(rpcURL: string): Promise<boolean> {
29
- console.log("stellar not yet implemented. check the code")
30
- process.exit(0)
31
- // this.provider = new StellarSdk(rpcURL) // 'https://horizon-testnet.stellar.org' // FIXME
32
- return true
33
- }
34
-
35
- public async disconnect(): Promise<any> {
36
- throw new Error("Method not implemented.")
37
- }
38
-
39
- createWallet(): any {}
40
-
41
- // INFO Loading a keypair from a private key string
42
- connectWallet(privateKey: string) {
43
- this.wallet = StellarSdk.Keypair.fromSecret(privateKey)
44
- }
45
- getBalance(address: string): Promise<string> {
46
- throw new Error("Method not implemented.")
47
- }
48
- pay(receiver: string, amount: string): Promise<any> {
49
- throw new Error("Method not implemented.")
50
- }
51
- info(): Promise<string> {
52
- throw new Error("Method not implemented.")
53
- }
54
-
55
- // REVIEW Signing a pre built transaction
56
- async signTransaction(raw_transaction: any): Promise<any> {
57
- required(this.wallet, "Wallet not connected")
58
- let signed_tx = await raw_transaction.sign(this.wallet)
59
- return signed_tx
60
- }
61
-
62
- sendTransaction(transactions: any) {
63
- throw new Error("Method not implemented.")
64
- }
65
- }
@@ -1 +0,0 @@
1
- # Multichain SDKs Core