@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,76 +0,0 @@
1
- import forge from "node-forge"
2
-
3
- // NOTE
4
- // In case of POST requests, the data is the only parameter thus 'name' is ignored
5
- // In case of GET requests, we can have multiple parameters, thus 'name' is used to identify them
6
- export interface IParam {
7
- name: string // Ignored in POST requests
8
- value: any
9
- }
10
-
11
- // INFO Properties of a typical request as the client would send it
12
- // NOTE This should be the thing we receive from the handler as a request
13
- // NOTE Basically is the comlink message
14
- export interface IWeb2Payload {
15
- type: "web2Request"
16
- message: IWeb2Request
17
- sender: any
18
- receiver: any
19
- timestamp: any
20
- data: any
21
- extra: any
22
- }
23
-
24
- // INFO A web2 result interface
25
- export interface IWeb2Result {
26
- status: number
27
- statusText: string
28
- data: any
29
- }
30
-
31
- // INFO A complete web2 request
32
- export interface IWeb2Request {
33
- raw: IRawWeb2Request
34
- result: any
35
- attestations: {}
36
- hash: string
37
- signature?: forge.pki.ed25519.BinaryBuffer
38
- }
39
-
40
- export enum EnumWeb2Methods {
41
- GET = "GET",
42
- POST = "POST",
43
- PUT = "PUT",
44
- DELETE = "DELETE",
45
- PATCH = "PATCH"
46
- }
47
-
48
- // INFO A request without any attestations or identity data
49
- export interface IRawWeb2Request {
50
- action: string
51
- parameters: IParam[]
52
- requestedParameters: [] | null
53
- method: EnumWeb2Methods,
54
- url: string
55
- headers: any
56
- minAttestations: number
57
- // Handling the various stages of an IWeb2Request
58
- stage: {
59
- // The one that will handle the response too
60
- origin: {
61
- identity: forge.pki.ed25519.BinaryBuffer
62
- connection_url: string
63
- }
64
- // Starting from 0, each attestation it is increased
65
- hop_number: number
66
- }
67
- }
68
-
69
- // ANCHOR Useful interfaces
70
- export interface IWeb2Attestation {
71
- hash: string
72
- timestamp: number
73
- identity: forge.pki.PublicKey
74
- signature: forge.pki.ed25519.BinaryBuffer
75
- valid: boolean
76
- }
@@ -1,21 +0,0 @@
1
-
2
- export interface ITask {
3
- type: string
4
- params: any // TODO Define a decent type for this and use it everywhere
5
- // TODO AND NOTE
6
- // Here the client should send
7
- // the signed transactions that it requires
8
- signedPayloads: any[]
9
- }
10
- export interface IOperation {
11
- chain: string
12
- subchain: string
13
- is_evm: boolean
14
- rpc: string
15
- task: ITask
16
- }
17
-
18
- export interface XMScript {
19
- operations: { [key: string]: IOperation },
20
- operations_order: string[]
21
- }
@@ -1,37 +0,0 @@
1
- export async function ObjectToHex(obj: any): Promise<string> {
2
- return Buffer.from(JSON.stringify(obj)).toString('hex')
3
- }
4
-
5
- export async function HexToObject(hex: string): Promise<any> {
6
- return JSON.parse(Buffer.from(hex, 'hex').toString('utf8'))
7
- }
8
-
9
- /* REVIEW Could we possibly ditch the below functions? */
10
-
11
- // INFO forgeBuffer comes in as the raw result of forge methods
12
- export function ForgeToHex(forgeBuffer: any) {
13
- console.log("[forge to string encoded]")
14
- //console.log(forgeBuffer)
15
- let rebuffer = Buffer.from(forgeBuffer)
16
- forgeBuffer = rebuffer.toString("hex")
17
- console.log("DECODED INTO:")
18
- console.log("0x" + forgeBuffer)
19
- return "0x" + forgeBuffer
20
- }
21
-
22
- // INFO finalArray must come out as an acceptable input for forge methods
23
- // NOTE The above and the below must be revertible with each other
24
- export function HexToForge(forgeString: string) {
25
- forgeString = forgeString.slice(2)
26
- let finalArray = new Uint8Array(64)
27
- console.log("[string to forge encoded]")
28
- //console.log(forgeString)
29
- for (let i = 0; i < forgeString.length; i += 2) {
30
- const hexValue = forgeString.substr(i, 2)
31
- const decimalValue = parseInt(hexValue, 16)
32
- finalArray[i / 2] = decimalValue
33
- }
34
- console.log("ENCODED INTO:")
35
- //console.log(finalArray)
36
- return finalArray
37
- }
@@ -1 +0,0 @@
1
- export * as dataManipulation from './dataManipulation'
@@ -1,74 +0,0 @@
1
- import forge from 'node-forge'
2
-
3
- import { demos } from './demos'
4
- import { sha256 } from './utils/sha256'
5
- import * as skeletons from './utils/skeletons'
6
- import { DemosWebAuth } from './DemosWebAuth'
7
-
8
- import type { ValidityData, Transaction } from '@/types'
9
-
10
- export const DemosTransactions = {
11
- // REVIEW All this part
12
- // NOTE A courtesy to get a skeleton of transactions
13
- empty: function () {
14
- return skeletons.transaction
15
- },
16
- // NOTE Building a transaction without signing or hashing it
17
- prepare: async function (data: any) {
18
- // sourcery skip: inline-immediately-returned-variable
19
- const thisTx = skeletons.transaction
20
- // if (!data.timestamp) data.timestamp = Date.now()
21
- // Assigning the transaction data to our object
22
- // thisTx.content = data
23
- return thisTx
24
- },
25
- // NOTE Signing a transaction after hashing it
26
- sign: async function (raw_tx: Transaction, private_key: Uint8Array | null = null): Promise<Transaction> {
27
- // If necessary, the private key is loaded from the state
28
- if (!private_key) {
29
- const id = DemosWebAuth.getInstance().keypair
30
- private_key = id!.privateKey as Uint8Array
31
- console.log('Private key loaded from state')
32
- } else {
33
- console.log('Private key provided')
34
- }
35
- console.log(private_key)
36
- // Setting the public key
37
- raw_tx.content.from = DemosWebAuth.getInstance().keypair!.publicKey as Uint8Array
38
- // Hashing the content of the transaction
39
- raw_tx.hash = await sha256(JSON.stringify(raw_tx.content))
40
- // Signing the hash of the content
41
- let signatureData = forge.pki.ed25519.sign({
42
- message: raw_tx.hash,
43
- encoding: 'utf8',
44
- privateKey: private_key
45
- }) // REVIEW if it is working right
46
- raw_tx.signature = {
47
- type: 'ed25519',
48
- data: signatureData
49
- }
50
- // TODO Remove debug: error checking
51
- let verified = forge.pki.ed25519.verify({
52
- message: raw_tx.hash,
53
- encoding: 'utf8',
54
- signature: signatureData,
55
- publicKey: DemosWebAuth.getInstance().keypair!.publicKey as Uint8Array
56
- })
57
- console.log('Signature verified: ' + verified)
58
-
59
- return raw_tx // Hashed and signed
60
- },
61
- // NOTE Sending a transaction after signing it
62
- confirm: async function (signedPayload: Transaction) {
63
- let response = await demos.confirm(signedPayload);
64
- response = JSON.parse(response);
65
- return response;
66
- },
67
- broadcast: async function (validityData: ValidityData) {
68
- // ValidityData does not need to be signed as it already contains a signature (in the Transaction object)
69
- // and is sent as a ComLink (thus authenticated and signed by the sender)
70
- let response = await demos.broadcast(validityData);
71
- response = JSON.parse(response);
72
- return response;
73
- },
74
- }
@@ -1,186 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- // @ts-ignore
3
- import forge from 'node-forge';
4
- import { required } from './utils/required';
5
- import * as forge_converter from './utils/forge_converter';
6
- import { RSA } from './rsa';
7
- import { IKeyPair, IStringifiedKeyPair } from './types/KeyPair';
8
-
9
- // TODO Could this be an universal "Sign in with DEMOS" ? Maybe
10
-
11
- // INFO Enabling DEMOS wallet connections in the browser exposing a singleton
12
- // NOTE All the methods below return an array of [boolean, string | any] where any can be the result of the method
13
- export class DemosWebAuth {
14
- static _instance = <DemosWebAuth | null>null;
15
- loggedIn = false;
16
- keypair = <IKeyPair | null>null;
17
- stringified_keypair = <IStringifiedKeyPair | null>null;
18
-
19
- constructor() {
20
- this.loggedIn = false;
21
- this.keypair = null;
22
- this.stringified_keypair = null;
23
- }
24
-
25
- /**
26
- * Description placeholder
27
- * @date 14/9/2023 - 13:52:34
28
- *
29
- * @static
30
- * @returns {DemosWebAuth}
31
- */
32
- static getInstance() {
33
- if (!this._instance) {
34
- this._instance = new DemosWebAuth();
35
- }
36
- return this._instance;
37
- }
38
-
39
- async create(seed = "") {
40
- if (!seed) {
41
- seed = forge.random.getBytesSync(32);
42
- }
43
- console.log('[CREATE WALLET] Creating wallet...');
44
- console.log('[CREATE WALLET] Seed: ' + seed);
45
- let result = [true, {}];
46
- try {
47
- this.keypair = {
48
- privateKey: null,
49
- publicKey: null
50
- };
51
- this.keypair = forge.pki.ed25519.generateKeyPair({ seed });
52
- console.log(this.keypair);
53
- this.loggedIn = true;
54
- console.log('[CREATE WALLET] Keypair created!');
55
- // Stringify the keypair
56
- console.log('[CREATE WALLET] Stringifying keypair...');
57
- this.stringified_keypair = {
58
- privateKey: forge_converter.forgeToString(this.keypair.privateKey),
59
- publicKey: forge_converter.forgeToString(this.keypair.publicKey)
60
- };
61
- result = [true, this.stringified_keypair];
62
- console.log(this.stringified_keypair);
63
- } catch (e) {
64
- // @ts-expect-error
65
- result = [false, '[CREATE WALLET ERROR] ' + e.message];
66
- }
67
- return result;
68
- }
69
-
70
- // NOTE We just have to accept valid private keys and derive the public key from them
71
- async login(privKey: boolean | Uint8Array) {
72
- if (typeof privKey === 'string') {
73
- console.log('[LOGIN] Converting private key from string...');
74
- privKey = forge_converter.stringToForge(privKey);
75
- if (!privKey) {
76
- return [false, 'Cannot convert private key from that string!'];
77
- }
78
- console.log(privKey);
79
- console.log('[LOGIN] Private key converted!');
80
- }
81
- console.log('[LOGIN WALLET] Logging in...');
82
- if (!required(privKey, false)) {
83
- return [false, 'You need to provide a private key!'];
84
- }
85
- // Serializing the private key as a string
86
-
87
- // console.log("[LOGIN WALLET] Serializing private key...")
88
- // this.keypair.privateKey = forge_converter.stringToForge(this.stringified_keypair.privateKey)
89
- // console.log(this.keypair.privateKey)
90
-
91
- this.keypair = {
92
- privateKey: privKey as Uint8Array,
93
- publicKey: null
94
- };
95
-
96
- // Logging in avoiding crashes on wrong private keys
97
- try {
98
- console.log('[LOGIN WALLET] Deriving public key from private key...');
99
- this.keypair.publicKey = forge.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privKey as Uint8Array });
100
- this.stringified_keypair = {
101
- privateKey: forge_converter.forgeToString(this.keypair.privateKey),
102
- publicKey: forge_converter.forgeToString(this.keypair.publicKey)
103
- };
104
- this.loggedIn = true;
105
-
106
- return [true, 'Successfully logged in!'];
107
- } catch (e) {
108
- console.log(e);
109
- return [false, '[LOGIN ERROR] Cannot derive publicKey!'];
110
- }
111
- }
112
-
113
- /**
114
- * @description Disconnects a wallet from the Demos chain
115
- * @returns {Promise<[boolean, string]>}
116
- **/
117
- async logout() {
118
- if (!required(this.keypair, false)) {
119
- return [true, 'You are already logged out!'];
120
- }
121
- this.loggedIn = false;
122
- this.keypair = null;
123
- this.stringified_keypair = null;
124
- return [true, 'Successfully logged out!'];
125
- }
126
-
127
- async sign(message: any) {
128
- if (!required(this.keypair || this.stringified_keypair, false)) {
129
- return [false, 'You need to login first!'];
130
- }
131
- // If needed, we derive the keys from the strings
132
- if (!this.keypair) {
133
- console.log('[SIGN WALLET] Deriving buffer keys from strings...');
134
- this.keypair = {
135
- privateKey: forge_converter.stringToForge(this.stringified_keypair?.privateKey),
136
- publicKey: forge_converter.stringToForge(this.stringified_keypair?.publicKey)
137
- };
138
- }
139
- let result = [true, {}];
140
- try {
141
- const sign_result = forge.pki.ed25519.sign({
142
- message: message,
143
- privateKey: this.keypair!.privateKey as Uint8Array
144
- });
145
-
146
- result = [true, sign_result];
147
- } catch (e: any) {
148
- result = [false, '[SIGN ERROR] ' + e.message];
149
- }
150
- return result; // Is already a [boolean, string]
151
- }
152
-
153
- async verify(message: any, s_signature: any, s_publicKey: any) {
154
- let result = [true, ''];
155
- // Deriving the buffers from the strings
156
- const publicKey = forge_converter.stringToForge(s_publicKey);
157
- const signature = forge_converter.stringToForge(s_signature);
158
-
159
- if (!signature){
160
- return [false, 'Invalid signature'];
161
- }
162
-
163
- if (!publicKey){
164
- return [false, 'Invalid public key'];
165
- }
166
-
167
- try {
168
- const verify_result = forge.pki.ed25519.verify({
169
- message: message,
170
- signature: signature,
171
- publicKey: publicKey
172
- });
173
-
174
- result = [true, verify_result];
175
- } catch (e: any) {
176
- result = [false, '[VERIFY ERROR] ' + e.message];
177
- }
178
- return result; // Is already a [boolean, string]
179
- }
180
-
181
- rsa() {
182
- return RSA.getInstance();
183
- }
184
- }
185
-
186
- // export default DemosWebAuth;
@@ -1,41 +0,0 @@
1
- // INFO This module exposes methods to quickly send Web2 requests to the network
2
-
3
- import * as skeletons from './utils/skeletons'
4
- // import demos from '../demos'
5
- import { DemosTransactions } from './DemosTransactions';
6
- import type { IWeb2Request, Transaction } from '@/types';
7
-
8
- // INFO Web2 Endpoints
9
- export async function prepareWeb2Payload (
10
- action = 'GET',
11
- url = 'https://icanhazip.com',
12
- parameters = [],
13
- requestedParameters = null,
14
- headers = null,
15
- minAttestations = 2
16
- ): Promise<Transaction> {
17
- // Generating an empty one and filling it
18
- const web2_payload:IWeb2Request = skeletons.web2_request
19
- web2_payload.raw.action = action
20
- web2_payload.raw.url = url
21
- web2_payload.raw.parameters = parameters
22
- web2_payload.raw.headers = headers
23
- web2_payload.raw.minAttestations = minAttestations
24
- // Ensuring content is a known property
25
- web2_payload.attestations = new Map()
26
- web2_payload.hash = ''
27
- web2_payload.signature = ''
28
- web2_payload.result = ''
29
-
30
- console.log('[Web2Transactions] Payload:')
31
- console.log(web2_payload)
32
- // REVIEW Finish upgrading to the new transaction system
33
- // Creating a web2 payload
34
- let web2_tx: Transaction = DemosTransactions.empty()
35
- web2_tx.content.type = "web2Request"
36
- web2_tx.content.data = ["web2Request", web2_payload]
37
- // Signing the transaction
38
- web2_tx = await DemosTransactions.sign(web2_tx)
39
- // Returning the transaction
40
- return web2_tx
41
- }
@@ -1,140 +0,0 @@
1
- // INFO Use the src/features/multichain/chainscript/chainscript.chs for the specs
2
- // NOTE This module is meant to be used with the demos websdk
3
-
4
- import type { Transaction, XMScript } from "@/types";
5
- import { DemosTransactions } from "./DemosTransactions";
6
-
7
- // INFO Using the methods below to create, manage and send chainscript-like scripts
8
- const XMTransactions = {
9
- schemas: {
10
- base_operation: {
11
- chain: '',
12
- subchain: '',
13
- is_evm: false,
14
- rpc: '',
15
- conditional: false,
16
- task: {
17
- type: '',
18
- params: {},
19
- signedPayloads: <any[]>[]
20
- }
21
- },
22
- condition_operation: {
23
- operator: '',
24
- statement: '',
25
- callback: '',
26
- alternative: ''
27
- }
28
- },
29
-
30
- data: {
31
- // NOTE This is a list of all operations that have been loaded in the current session
32
- loaded_operations: <{[key: string]: any}>{},
33
- operations_index: <(string|number)[]>[]
34
- },
35
-
36
- task: {},
37
-
38
- operation: {
39
- // ANCHOR Setters
40
-
41
- // NOTE Creating and adding a new operation to the current session list
42
- // megabudino was here: I added the conditional parameter; changed operation.task = task to not overwrite
43
- create: function (name: string | number, chain: string, subchain: string, is_evm: boolean, rpc: string, task: { type: string; params: {}; signedPayloads: any[] }, conditional = false) {
44
- // TODO Bugfix: implement a name
45
- const operation = { ...XMTransactions.schemas.base_operation }
46
- operation.chain = chain
47
- operation.subchain = subchain
48
- operation.is_evm = is_evm
49
- operation.rpc = rpc
50
- operation.conditional = conditional
51
- operation.task = task
52
- XMTransactions.data.loaded_operations[name] = operation
53
- XMTransactions.data.operations_index.push(name)
54
- return operation
55
- },
56
-
57
- // megabudino was here: this is the function that creates the condition operation
58
- create_condition: function (name: string | number, operator: string, statement: string, callback: string, alternative: string) {
59
- const condition = { ...XMTransactions.schemas.condition_operation }
60
- condition.operator = operator
61
- condition.statement = statement
62
- condition.callback = callback
63
- condition.alternative = alternative
64
- XMTransactions.data.loaded_operations[name] = condition
65
- XMTransactions.data.operations_index.push(name)
66
- return condition
67
- },
68
-
69
- // megabudino was here: this is the function to push signed payloads to the task
70
- push_signed_payload: function (name: string | number, signed_payload: any) {
71
- XMTransactions.data.loaded_operations[name].task.signedPayloads.push(signed_payload)
72
- },
73
-
74
- // NOTE Deleting an operation from the current session list
75
- delete: function (name: string | number) {
76
- delete XMTransactions.data.loaded_operations[name]
77
- const index = XMTransactions.data.operations_index.indexOf(name)
78
- XMTransactions.data.operations_index.splice(index, 1)
79
- },
80
-
81
- clear: function () {
82
- XMTransactions.data.loaded_operations = {}
83
- XMTransactions.data.operations_index = []
84
- },
85
-
86
- // NOTE Changing operation order for an operation from the current session list
87
- reorder: function (name: any, index: number) {
88
- // FIXME Security: check boundaries to avoid circling
89
- const operation_current = XMTransactions.data.operations_index.indexOf(name)
90
- // Deleting and...
91
- XMTransactions.data.operations_index.splice(operation_current, 1)
92
- // ...inserting it at the new index
93
- XMTransactions.data.operations_index.splice(index, 0, name)
94
- },
95
-
96
- // NOTE Updating an operation from the current session list
97
- // megabudino was here: I added the conditional parameter; changed operation.task = task to not overwrite
98
- update: function (name: string | number, chain: string, subchain: string, is_evm: boolean, rpc: string, task: { type: string; params: {} }, conditional: boolean) {
99
- const operation = { ...XMTransactions.schemas.base_operation }
100
- operation.chain = chain
101
- operation.subchain = subchain
102
- operation.is_evm = is_evm
103
- operation.rpc = rpc
104
- operation.task.type = task.type
105
- operation.task.params = task.params
106
- operation.conditional = conditional
107
- XMTransactions.data.loaded_operations[name] = operation
108
- },
109
-
110
- // ANCHOR Getters
111
-
112
- // NOTE Getting all the operations from the current session list
113
- get: function () {
114
- return XMTransactions.data.loaded_operations
115
- },
116
-
117
- // NOTE Getting an operation from the current session list by name
118
- get_by_name: function (name: string | number) {
119
- return XMTransactions.data.loaded_operations[name]
120
- },
121
-
122
- get_ordered_index: function () {
123
- return XMTransactions.data.operations_index
124
- }
125
-
126
- }
127
-
128
- }
129
-
130
- async function prepareXMPayload(xm_payload: XMScript): Promise<Transaction> {
131
- var xm_transaction: Transaction = DemosTransactions.empty()
132
- xm_transaction.content.type = "crosschainOperation"
133
- xm_transaction.content.data = ["crosschainOperation", xm_payload]
134
- // Signing the transaction
135
- xm_transaction = await DemosTransactions.sign(xm_transaction)
136
- // Returning the transaction
137
- return xm_transaction
138
- }
139
-
140
- export { XMTransactions, prepareXMPayload }