@linealqorum/js 0.0.0-stage → 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 (151) hide show
  1. package/package.json +16 -5
  2. package/src/artifact-service.js +94 -0
  3. package/src/artifacts/artifacts.d.ts +13 -0
  4. package/src/artifacts/build-info/solc-0_8_30-e703f2fe389268a2246aec69fef2175182b7b532.json +392 -0
  5. package/src/artifacts/build-info/solc-0_8_30-e703f2fe389268a2246aec69fef2175182b7b532.output.json +1 -0
  6. package/src/artifacts/contracts/Counter.sol/Counter.json +60 -0
  7. package/src/artifacts/contracts/Counter.sol/artifacts.d.ts +27 -0
  8. package/src/artifacts/contracts/core/BaseAccount.sol/BaseAccount.json +116 -0
  9. package/src/artifacts/contracts/core/BaseAccount.sol/artifacts.d.ts +27 -0
  10. package/src/artifacts/contracts/core/BasePaymaster.sol/BasePaymaster.json +281 -0
  11. package/src/artifacts/contracts/core/BasePaymaster.sol/artifacts.d.ts +27 -0
  12. package/src/artifacts/contracts/core/EntryPoint.sol/EntryPoint.json +1019 -0
  13. package/src/artifacts/contracts/core/EntryPoint.sol/artifacts.d.ts +27 -0
  14. package/src/artifacts/contracts/core/EntryPointSimulations.sol/EntryPointSimulations.json +1324 -0
  15. package/src/artifacts/contracts/core/EntryPointSimulations.sol/artifacts.d.ts +27 -0
  16. package/src/artifacts/contracts/core/Groth16Verifier.sol/Groth16Verifier.json +48 -0
  17. package/src/artifacts/contracts/core/Groth16Verifier.sol/artifacts.d.ts +27 -0
  18. package/src/artifacts/contracts/core/Helpers.sol/artifacts.d.ts +0 -0
  19. package/src/artifacts/contracts/core/LinealDeployer.sol/LinealDeployer.json +51 -0
  20. package/src/artifacts/contracts/core/LinealDeployer.sol/artifacts.d.ts +27 -0
  21. package/src/artifacts/contracts/core/NonceManager.sol/NonceManager.json +75 -0
  22. package/src/artifacts/contracts/core/NonceManager.sol/artifacts.d.ts +27 -0
  23. package/src/artifacts/contracts/core/SenderCreator.sol/SenderCreator.json +33 -0
  24. package/src/artifacts/contracts/core/SenderCreator.sol/artifacts.d.ts +27 -0
  25. package/src/artifacts/contracts/core/StakeManager.sol/StakeManager.json +299 -0
  26. package/src/artifacts/contracts/core/StakeManager.sol/artifacts.d.ts +27 -0
  27. package/src/artifacts/contracts/core/UserOperationLib.sol/UserOperationLib.json +53 -0
  28. package/src/artifacts/contracts/core/UserOperationLib.sol/artifacts.d.ts +27 -0
  29. package/src/artifacts/contracts/economy/Liquidity/LinealDex.sol/LinealDex.json +530 -0
  30. package/src/artifacts/contracts/economy/Liquidity/LinealDex.sol/artifacts.d.ts +27 -0
  31. package/src/artifacts/contracts/economy/Liquidity/LinealLiquidity.sol/LinealLiquidity.json +876 -0
  32. package/src/artifacts/contracts/economy/Liquidity/LinealLiquidity.sol/artifacts.d.ts +27 -0
  33. package/src/artifacts/contracts/economy/Liquidity/LinealMilestones.sol/ILinealCitizens.json +46 -0
  34. package/src/artifacts/contracts/economy/Liquidity/LinealMilestones.sol/LinealMilestones.json +986 -0
  35. package/src/artifacts/contracts/economy/Liquidity/LinealMilestones.sol/artifacts.d.ts +43 -0
  36. package/src/artifacts/contracts/economy/Liquidity/LinealSeed.sol/LinealSeed.json +808 -0
  37. package/src/artifacts/contracts/economy/Liquidity/LinealSeed.sol/artifacts.d.ts +27 -0
  38. package/src/artifacts/contracts/economy/accounts/LinealAccount.sol/LinealAccount.json +591 -0
  39. package/src/artifacts/contracts/economy/accounts/LinealAccount.sol/artifacts.d.ts +27 -0
  40. package/src/artifacts/contracts/economy/accounts/LinealAccountFactory.sol/LinealAccountFactory.json +101 -0
  41. package/src/artifacts/contracts/economy/accounts/LinealAccountFactory.sol/artifacts.d.ts +27 -0
  42. package/src/artifacts/contracts/economy/accounts/callback/TokenCallbackHandler.sol/TokenCallbackHandler.json +145 -0
  43. package/src/artifacts/contracts/economy/accounts/callback/TokenCallbackHandler.sol/artifacts.d.ts +27 -0
  44. package/src/artifacts/contracts/economy/banks/LinealBank.sol/IBankDeposit.json +56 -0
  45. package/src/artifacts/contracts/economy/banks/LinealBank.sol/ICitizensAccounts.json +33 -0
  46. package/src/artifacts/contracts/economy/banks/LinealBank.sol/IInstitutionIdentity.json +27 -0
  47. package/src/artifacts/contracts/economy/banks/LinealBank.sol/ILinealTransactions.json +53 -0
  48. package/src/artifacts/contracts/economy/banks/LinealBank.sol/LinealBank.json +1072 -0
  49. package/src/artifacts/contracts/economy/banks/LinealBank.sol/artifacts.d.ts +91 -0
  50. package/src/artifacts/contracts/economy/banks/LinealQantum.sol/LinealQantum.json +496 -0
  51. package/src/artifacts/contracts/economy/banks/LinealQantum.sol/artifacts.d.ts +27 -0
  52. package/src/artifacts/contracts/economy/banks/LinealTransaction.sol/ILinealBank.json +27 -0
  53. package/src/artifacts/contracts/economy/banks/LinealTransaction.sol/LinealTransactions.json +1352 -0
  54. package/src/artifacts/contracts/economy/banks/LinealTransaction.sol/artifacts.d.ts +43 -0
  55. package/src/artifacts/contracts/economy/interfaces/ICLPStablecoin.sol/ICLPStablecoin.json +459 -0
  56. package/src/artifacts/contracts/economy/interfaces/ICLPStablecoin.sol/artifacts.d.ts +27 -0
  57. package/src/artifacts/contracts/economy/interfaces/IDEXRouter.sol/IDEXRouter.json +117 -0
  58. package/src/artifacts/contracts/economy/interfaces/IDEXRouter.sol/artifacts.d.ts +27 -0
  59. package/src/artifacts/contracts/economy/interfaces/IFeeSplitter.sol/IFeeSplitter.json +40 -0
  60. package/src/artifacts/contracts/economy/interfaces/IFeeSplitter.sol/artifacts.d.ts +27 -0
  61. package/src/artifacts/contracts/economy/interfaces/IIncomeToken.sol/IIncomeToken.json +197 -0
  62. package/src/artifacts/contracts/economy/interfaces/IIncomeToken.sol/artifacts.d.ts +27 -0
  63. package/src/artifacts/contracts/economy/interfaces/ILinealIdentity.sol/ILinealIdentity.json +90 -0
  64. package/src/artifacts/contracts/economy/interfaces/ILinealIdentity.sol/artifacts.d.ts +27 -0
  65. package/src/artifacts/contracts/economy/interfaces/IMetricsAdapter.sol/IMetricsAdapter.json +32 -0
  66. package/src/artifacts/contracts/economy/interfaces/IMetricsAdapter.sol/artifacts.d.ts +27 -0
  67. package/src/artifacts/contracts/economy/interfaces/IQorumsToken.sol/IQorumsToken.json +267 -0
  68. package/src/artifacts/contracts/economy/interfaces/IQorumsToken.sol/artifacts.d.ts +27 -0
  69. package/src/artifacts/contracts/economy/paymasters/LinealPaymaster.sol/LinealPaymaster.json +487 -0
  70. package/src/artifacts/contracts/economy/paymasters/LinealPaymaster.sol/artifacts.d.ts +27 -0
  71. package/src/artifacts/contracts/economy/paymasters/LinealRouter.sol/LinealRouter.json +945 -0
  72. package/src/artifacts/contracts/economy/paymasters/LinealRouter.sol/artifacts.d.ts +27 -0
  73. package/src/artifacts/contracts/economy/token/LinealToken.sol/LinealToken.json +1567 -0
  74. package/src/artifacts/contracts/economy/token/LinealToken.sol/artifacts.d.ts +27 -0
  75. package/src/artifacts/contracts/governance/LinealQorum.sol/LinealQorum.json +567 -0
  76. package/src/artifacts/contracts/governance/LinealQorum.sol/artifacts.d.ts +27 -0
  77. package/src/artifacts/contracts/institution/LinealCitizens.sol/LinealCitizens.json +986 -0
  78. package/src/artifacts/contracts/institution/LinealCitizens.sol/artifacts.d.ts +27 -0
  79. package/src/artifacts/contracts/institution/LinealInstitution.sol/LinealInstitution.json +1607 -0
  80. package/src/artifacts/contracts/institution/LinealInstitution.sol/artifacts.d.ts +27 -0
  81. package/src/artifacts/contracts/institution/LinealTender.sol/LinealTender.json +1055 -0
  82. package/src/artifacts/contracts/institution/LinealTender.sol/artifacts.d.ts +27 -0
  83. package/src/artifacts/contracts/interfaces/IAccount.sol/IAccount.json +90 -0
  84. package/src/artifacts/contracts/interfaces/IAccount.sol/artifacts.d.ts +27 -0
  85. package/src/artifacts/contracts/interfaces/IAccountExecute.sol/IAccountExecute.json +79 -0
  86. package/src/artifacts/contracts/interfaces/IAccountExecute.sol/artifacts.d.ts +27 -0
  87. package/src/artifacts/contracts/interfaces/IAggregator.sol/IAggregator.json +211 -0
  88. package/src/artifacts/contracts/interfaces/IAggregator.sol/artifacts.d.ts +27 -0
  89. package/src/artifacts/contracts/interfaces/IEntryPoint.sol/IEntryPoint.json +809 -0
  90. package/src/artifacts/contracts/interfaces/IEntryPoint.sol/artifacts.d.ts +27 -0
  91. package/src/artifacts/contracts/interfaces/IEntryPointSimulations.sol/IEntryPointSimulations.json +1097 -0
  92. package/src/artifacts/contracts/interfaces/IEntryPointSimulations.sol/artifacts.d.ts +27 -0
  93. package/src/artifacts/contracts/interfaces/IMetricsAdapter.sol/IMetricsAdapter.json +32 -0
  94. package/src/artifacts/contracts/interfaces/IMetricsAdapter.sol/artifacts.d.ts +27 -0
  95. package/src/artifacts/contracts/interfaces/INonceManager.sol/INonceManager.json +51 -0
  96. package/src/artifacts/contracts/interfaces/INonceManager.sol/artifacts.d.ts +27 -0
  97. package/src/artifacts/contracts/interfaces/IPaymaster.sol/IPaymaster.json +123 -0
  98. package/src/artifacts/contracts/interfaces/IPaymaster.sol/artifacts.d.ts +27 -0
  99. package/src/artifacts/contracts/interfaces/IQorumsToken.sol/IQorumsToken.json +267 -0
  100. package/src/artifacts/contracts/interfaces/IQorumsToken.sol/artifacts.d.ts +27 -0
  101. package/src/artifacts/contracts/interfaces/IStakeManager.sol/IStakeManager.json +256 -0
  102. package/src/artifacts/contracts/interfaces/IStakeManager.sol/artifacts.d.ts +27 -0
  103. package/src/artifacts/contracts/interfaces/PackedUserOperation.sol/artifacts.d.ts +0 -0
  104. package/src/artifacts/contracts/kernel/LinealEconomy.sol/LinealEconomicKernel.json +743 -0
  105. package/src/artifacts/contracts/kernel/LinealEconomy.sol/artifacts.d.ts +27 -0
  106. package/src/artifacts/contracts/social/LinealStorage.sol/PostBoard.json +1317 -0
  107. package/src/artifacts/contracts/social/LinealStorage.sol/artifacts.d.ts +27 -0
  108. package/src/artifacts/contracts/test.sol/LinealSecureStorage.json +634 -0
  109. package/src/artifacts/contracts/test.sol/artifacts.d.ts +27 -0
  110. package/src/artifacts/contracts/utils/Exec.sol/Exec.json +13 -0
  111. package/src/artifacts/contracts/utils/Exec.sol/artifacts.d.ts +27 -0
  112. package/src/artifacts/contracts/utils/IOracle.sol/IOracle.json +60 -0
  113. package/src/artifacts/contracts/utils/IOracle.sol/artifacts.d.ts +27 -0
  114. package/src/artifacts/contracts/utils/OracleHelper.sol/OracleHelper.json +84 -0
  115. package/src/artifacts/contracts/utils/OracleHelper.sol/artifacts.d.ts +27 -0
  116. package/src/artifacts/contracts/utils/UniswapHelper.sol/UniswapHelper.json +132 -0
  117. package/src/artifacts/contracts/utils/UniswapHelper.sol/artifacts.d.ts +27 -0
  118. package/src/contract-service.js +53 -0
  119. package/src/database/mongodb.js +181 -0
  120. package/src/index.js +11 -0
  121. package/src/middleware/actionMiddleware.js +17 -0
  122. package/src/middleware/actionsMiddleware.js +18 -0
  123. package/src/middleware/authMachineMiddleware.js +34 -0
  124. package/src/middleware/middleware.js +36 -0
  125. package/src/middleware/onlyQorum.js +57 -0
  126. package/src/middleware/onlyServer.js +36 -0
  127. package/src/middleware/readStateMiddleware.js +19 -0
  128. package/src/middleware/unauthorizeMiddleware.js +37 -0
  129. package/src/middleware/userOperation.js +25 -0
  130. package/src/operation-service.js +71 -0
  131. package/src/schemas/abiFolderSchema.js +9 -0
  132. package/src/schemas/abiSchema.js +16 -0
  133. package/src/schemas/applicationSchema.js +32 -0
  134. package/src/schemas/authorizedWalletSchema.js +9 -0
  135. package/src/schemas/deploySchema.js +11 -0
  136. package/src/schemas/expenseSchema.js +17 -0
  137. package/src/schemas/feeSchema.js +17 -0
  138. package/src/schemas/fixedExpenseSchema.js +18 -0
  139. package/src/schemas/fixedFeeSchema.js +17 -0
  140. package/src/schemas/identitySchema.js +33 -0
  141. package/src/schemas/institutionSchema.js +28 -0
  142. package/src/schemas/onlyQorumSchema.js +27 -0
  143. package/src/schemas/onlyServerSchema.js +26 -0
  144. package/src/schemas/serverWalletSchema.js +9 -0
  145. package/src/schemas/subaccountSchema.js +31 -0
  146. package/src/schemas/tenderSchema.js +36 -0
  147. package/src/schemas/transactionSchema.js +29 -0
  148. package/src/schemas/userOperationSchema.js +15 -0
  149. package/src/schemas/valuationSchema.js +10 -0
  150. package/src/signer-client.js +280 -0
  151. package/README.md +0 -3
@@ -0,0 +1,17 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Honorario pagado por una institución a una persona o cargo.
4
+ const feeSchema = new mongoose.Schema({
5
+ wallet: { type: String, default: null },
6
+ userId: { type: String, default: null },
7
+ contractAddress: { type: String, required: true, unique: true }, // contrato propio del registro (off-chain)
8
+ institutionAddress: { type: String, required: true, index: true }, // institución a la que pertenece
9
+ nombre: { type: String, required: true },
10
+ cargo: { type: String, default: 'Sin cargo' },
11
+ periodo: { type: String, default: null }, // Ej. "Octubre 2026"
12
+ monto: { type: Number, required: true, min: 0 },
13
+ fecha: { type: String, default: null }, // YYYY-MM-DD (fecha de emisión)
14
+ estado: { type: String, enum: ['Pagado', 'Pendiente', 'En revisión'], default: 'Pendiente' },
15
+ }, { timestamps: true });
16
+
17
+ module.exports = mongoose.model('Fee', feeSchema);
@@ -0,0 +1,18 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Gasto fijo / recurrente de una institución.
4
+ const fixedExpenseSchema = new mongoose.Schema({
5
+ wallet: { type: String, default: null },
6
+ userId: { type: String, default: null },
7
+ contractAddress: { type: String, required: true, unique: true }, // contrato propio del registro (off-chain)
8
+ institutionAddress: { type: String, required: true, index: true }, // institución a la que pertenece
9
+ concepto: { type: String, required: true },
10
+ categoria: { type: String, default: 'General' },
11
+ responsable: { type: String, default: 'Tesorería' },
12
+ monto: { type: Number, required: true, min: 0 },
13
+ diaCobro: { type: Number, min: 1, max: 31, default: 1 },
14
+ frecuencia: { type: String, enum: ['Mensual', 'Trimestral', 'Anual'], default: 'Mensual' },
15
+ estado: { type: String, enum: ['Activo', 'Pausado'], default: 'Activo' },
16
+ }, { timestamps: true });
17
+
18
+ module.exports = mongoose.model('FixedExpense', fixedExpenseSchema);
@@ -0,0 +1,17 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Honorario fijo / recurrente pagado por una institución (personal full-time).
4
+ const fixedFeeSchema = new mongoose.Schema({
5
+ wallet: { type: String, default: null },
6
+ userId: { type: String, default: null },
7
+ contractAddress: { type: String, required: true, unique: true }, // contrato propio del registro (off-chain)
8
+ institutionAddress: { type: String, required: true, index: true }, // institución a la que pertenece
9
+ nombre: { type: String, required: true },
10
+ cargo: { type: String, default: 'Sin cargo' },
11
+ monto: { type: Number, required: true, min: 0 }, // monto por período
12
+ diaPago: { type: Number, min: 1, max: 31, default: 1 },
13
+ frecuencia: { type: String, enum: ['Mensual', 'Trimestral', 'Anual'], default: 'Mensual' },
14
+ estado: { type: String, enum: ['Activo', 'Pausado'], default: 'Activo' },
15
+ }, { timestamps: true });
16
+
17
+ module.exports = mongoose.model('FixedFee', fixedFeeSchema);
@@ -0,0 +1,33 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const identitySchema = new mongoose.Schema({
4
+ tokenId: { type: Number },
5
+ username: { type: String, required: true },
6
+ wallet: { type: String, required: true },
7
+ imageURI: { type: String }, // S3 key
8
+ subAccountId: { type: String }, // S3 key
9
+ createdAt: { type: Date, default: Date.now },
10
+ active: { type: Boolean, default: true },
11
+ contractAddress: { type: String },
12
+ receipt: { type: {} },
13
+ status: { type: String, enum: ['pending', 'executed', 'failed'], default: 'pending' },
14
+ body: { type: Object },
15
+ signCount: { type: Number, default: 0 },
16
+ required: { type: Number, default: 3 },
17
+ steps: [{
18
+ server: String,
19
+ status: { type: String, enum: ['waiting', 'signing', 'signed', 'failed'], default: 'waiting' },
20
+ receipt: Object,
21
+ error: String,
22
+ signedAt: Date,
23
+ claimedAt: Date,
24
+ _id: false,
25
+ }],
26
+ signatures: [{
27
+ wallet: String,
28
+ receipt: Object,
29
+ signedAt: { type: Date, default: Date.now },
30
+ }],
31
+ });
32
+
33
+ module.exports = { identitySchema };
@@ -0,0 +1,28 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const institutionSchema = new mongoose.Schema({
4
+ name: { type: String, required: true },
5
+ description: { type: String },
6
+ contractAddress: { type: String },
7
+ userWallet: {type: String},
8
+ bankAddress: { type: String },
9
+ tokenAddress: { type: String },
10
+ receipt: { type: {} },
11
+ bps: { type: Number, default: 0 },
12
+ isMatriz: { type: Boolean, default: false },
13
+ bannerUri: { type: String },
14
+ args: {type: {}},
15
+ avatarUri: { type: String },
16
+ createdBy: { type: String, required: true },
17
+ app: { type: String, required: false },
18
+ boardMembers: [{ type: String }],
19
+ active: { type: Boolean, default: true },
20
+ createdAt: { type: Date, default: Date.now },
21
+ });
22
+
23
+ const authorizedServerSchema = new mongoose.Schema({
24
+ institutional: { type: [], required: true },
25
+ qorum: { type: [], required: true }
26
+ });
27
+
28
+ module.exports = { institutionSchema, authorizedServerSchema };
@@ -0,0 +1,27 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const onlyQorumSchema = new mongoose.Schema({
4
+ contractName: { type: String, required: true },
5
+ contractAddress: { type: String, required: true },
6
+ functionName: { type: String, required: true },
7
+ args: { type: [], default: [] },
8
+ signCount: { type: Number, default: 0 },
9
+ required: { type: Number, default: 3 },
10
+ steps: [{
11
+ users: { type: [String], default: [] },
12
+ server: String,
13
+ status: { type: String, enum: ['waiting', 'signing', 'signed', 'failed'], default: 'waiting' },
14
+ receipt: Object,
15
+ error: String,
16
+ signedAt: Date,
17
+ claimedAt: Date,
18
+ _id: false,
19
+ }],
20
+ signatures: [{
21
+ wallet: String,
22
+ receipt: Object,
23
+ signedAt: { type: Date, default: Date.now },
24
+ }],
25
+ });
26
+
27
+ module.exports = { onlyQorumSchema };
@@ -0,0 +1,26 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const onlyServerSchema = new mongoose.Schema({
4
+ contractName: { type: String, required: true },
5
+ contractAddress: { type: String, required: true },
6
+ functionName: { type: String, required: true },
7
+ args: { type: [], default: [] },
8
+ signCount: { type: Number, default: 0 },
9
+ required: { type: Number, default: 3 },
10
+ steps: [{
11
+ server: String,
12
+ status: { type: String, enum: ['waiting', 'signing', 'signed', 'failed'], default: 'waiting' },
13
+ receipt: Object,
14
+ error: String,
15
+ signedAt: Date,
16
+ claimedAt: Date,
17
+ _id: false,
18
+ }],
19
+ signatures: [{
20
+ wallet: String,
21
+ receipt: Object,
22
+ signedAt: { type: Date, default: Date.now },
23
+ }],
24
+ });
25
+
26
+ module.exports = { onlyServerSchema };
@@ -0,0 +1,9 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const authorizedWalletSchema = new mongoose.Schema({
4
+ address: { type: String, required: true },
5
+ authorized: { type: Boolean, default: true },
6
+ });
7
+
8
+ const AuthorizedServer = mongoose.model('AuthorizedServer', authorizedWalletSchema);
9
+ module.exports = { authorizedWalletSchema, AuthorizedServer };
@@ -0,0 +1,31 @@
1
+ const mongoose = require('mongoose');
2
+ const subaccountSchema = new mongoose.Schema({
3
+ wallet: { type: String, required: true },
4
+ userId: { type: String },
5
+ contractAddress: { type: String, required: true },
6
+ name: { type: String, required: true },
7
+ subAccountId: { type: String, default: null }, // bytes32 on-chain (reemplaza a `id`)
8
+ amount: { type: Number, default: 0 },
9
+ active: { type: Boolean, default: true },
10
+ createdAt: { type: Date, default: Date.now },
11
+ receipt: { type: {} },
12
+ status: { type: String, enum: ['pending', 'executed', 'failed'], default: 'pending' },
13
+ body: { type: Object },
14
+ signCount: { type: Number, default: 0 },
15
+ required: { type: Number, default: 3 },
16
+ steps: [{
17
+ server: String,
18
+ status: { type: String, enum: ['waiting', 'signing', 'signed', 'failed'], default: 'waiting' },
19
+ receipt: Object,
20
+ error: String,
21
+ signedAt: Date,
22
+ claimedAt: Date,
23
+ _id: false,
24
+ }],
25
+ signatures: [{
26
+ wallet: String,
27
+ receipt: Object,
28
+ signedAt: { type: Date, default: Date.now },
29
+ }],
30
+ });
31
+ module.exports = mongoose.model('Subaccount', subaccountSchema);
@@ -0,0 +1,36 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const tenderSchema = new mongoose.Schema({
4
+ tokenId: { type: Number },
5
+ title: { type: String, required: true },
6
+ description: { type: String, required: true },
7
+ imageURI: { type: String }, // S3 key
8
+ documentURL: { type: String }, // S3 key
9
+ createdAt: { type: Date, default: Date.now },
10
+ active: { type: Boolean, default: true },
11
+ // Quién la creó (institución)
12
+ budget: {type: String},
13
+ authorWallet: { type: String },
14
+ contractAddress: { type: String },
15
+ receipt: { type: {} },
16
+ status: { type: String, enum: ['pending', 'executed', 'failed'], default: 'pending' },
17
+ body: { type: Object },
18
+ signCount: { type: Number, default: 0 },
19
+ required: { type: Number, default: 3 },
20
+ steps: [{
21
+ server: String,
22
+ status: { type: String, enum: ['waiting', 'signing', 'signed', 'failed'], default: 'waiting' },
23
+ receipt: Object,
24
+ error: String,
25
+ signedAt: Date,
26
+ claimedAt: Date,
27
+ _id: false,
28
+ }],
29
+ signatures: [{
30
+ wallet: String,
31
+ receipt: Object,
32
+ signedAt: { type: Date, default: Date.now },
33
+ }],
34
+ });
35
+
36
+ module.exports = { tenderSchema };
@@ -0,0 +1,29 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const transactionSchema = new mongoose.Schema({
4
+ contractAddress: { type: String, required: true },
5
+ senderId: { type: String, required: true }, // bytes32 on-chain
6
+ recipientId: { type: String, required: true }, // bytes32 on-chain
7
+ amount: { type: Number, required: true },
8
+ tokenAddress: { type: String },
9
+ tokenSymbol: { type: String },
10
+ description: { type: String },
11
+ createdBy: { type: String },
12
+ userId: { type: String },
13
+ body: { type: Object },
14
+ status: { type: String, enum: ['pending', 'executed', 'failed'], default: 'pending' },
15
+ signCount: { type: Number, default: 0 },
16
+ required: { type: Number, default: 3 },
17
+ steps: [{
18
+ server: String,
19
+ status: { type: String, enum: ['waiting', 'signing', 'signed', 'failed'], default: 'waiting' },
20
+ receipt: Object,
21
+ error: String,
22
+ signedAt: Date,
23
+ claimedAt: Date,
24
+ _id: false,
25
+ }],
26
+ createdAt: { type: Date, default: Date.now },
27
+ });
28
+
29
+ module.exports = mongoose.model('Transactions', transactionSchema);
@@ -0,0 +1,15 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const userOperationSchema = new mongoose.Schema({
4
+ wallet: { type: String, required: true },
5
+ contractAddress: { type: String, required: true },
6
+ title: { type: String, required: true },
7
+ description: { type: String, required: true },
8
+ amount: { type: Number, required: true },
9
+ images: [{ type: String }],
10
+ videoURL: { type: String, default: null },
11
+ status: { type: String, enum: ['En revisión', 'Aprobada', 'Rechazada'], default: 'En revisión' },
12
+ createdAt: { type: Date, default: Date.now },
13
+ });
14
+
15
+ module.exports = { userOperationSchema };
@@ -0,0 +1,10 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Honorario pagado por una institución a una persona o cargo.
4
+ const valuationSchema = new mongoose.Schema({
5
+ contractAddress: { type: String, default: null },
6
+ date: { type: String, default: null }, // YYYY-MM-DD (fecha de emisión)
7
+ valuation: { type: Number, default: null },
8
+ }, { timestamps: true });
9
+
10
+ module.exports = mongoose.model('Valuation', valuationSchema);
@@ -0,0 +1,280 @@
1
+ const nodeMachineId = require('node-machine-id');
2
+
3
+ const {machineId} = nodeMachineId;
4
+ const TRAIN = ['demos', 'nomos', 'kritos', 'ekklesia'];
5
+ class Signer {
6
+
7
+ authorizedAddress = [];
8
+ authorizedDomains = [];
9
+ token = "";
10
+ TRAIN_INSTITUTION = ['agora', 'tecne', 'ethos', 'ache'];
11
+ SERVER_NAME = process.env.SERVER_NAME;
12
+ SERVER_DOMAIN = process.env.SERVER_DIMAIN;
13
+
14
+ constructor() {
15
+ this._init().then();
16
+ }
17
+
18
+ async _init() {
19
+ this.token = await machineId();
20
+ this.authorizedDomains.push("qorum.one");
21
+ this.authorizedDomains.push(this.SERVER_DOMAIN);
22
+ this.TRAIN_INSTITUTION = this.TRAIN_INSTITUTION.filter(name => name !== this.SERVER_NAME);
23
+ }
24
+
25
+ getToken() {
26
+ return this.token;
27
+ }
28
+
29
+ async connectMachine() {
30
+ const train = ["4000", "4001", "4002", "4003"];
31
+ return await this.initDevPoolRequest(train, "GET","wallet/me", this.token);
32
+ }
33
+
34
+ async getUserWallet(token) {
35
+ return await this.initPoolRequest("wallet/me", token);
36
+ }
37
+
38
+ async getDevUserWallet(token) {
39
+ const train = ["4000", "4001", "4002", "4003"];
40
+ console.log(token);
41
+ return await this.initDevPoolRequest(train, "GET","wallet/me", token);
42
+ }
43
+
44
+ async post(url, body, token, signal) {
45
+ const response = await fetch(url, {
46
+ method: "POST",
47
+ signal,
48
+ body: JSON.stringify(body),
49
+ headers: {
50
+ 'Content-Type': 'application/json',
51
+ "q-user-token": token,
52
+ "q-server-token": this.token,
53
+ "q-institution-id": this.institutionId
54
+ }
55
+ });
56
+
57
+ const text = await response.text();
58
+ if (!response.ok) {
59
+ const err = new Error(`Failed to get signer: ${response.status} ${response.statusText} ${text}`);
60
+ err.status = response.status;
61
+ throw err;
62
+ }
63
+ return text ? JSON.parse(text) : null;
64
+ }
65
+
66
+ async onlyServerPost(url, body, signal) {
67
+ const response = await fetch(url, {
68
+ method: "POST",
69
+ signal,
70
+ body: JSON.stringify(body),
71
+ headers: {
72
+ 'Content-Type': 'application/json',
73
+ "q-server-token": this.token,
74
+ "q-institution-id": this.institutionId
75
+ }
76
+ });
77
+
78
+ const text = await response.text();
79
+ if (!response.ok) {
80
+ const err = new Error(`Failed to get signer: ${response.status} ${response.statusText} ${text}`);
81
+ err.status = response.status;
82
+ throw err;
83
+ }
84
+ return text ? JSON.parse(text) : null;
85
+ }
86
+
87
+ async get(url, token, signal) {
88
+ const response = await fetch(url, {
89
+ method: "GET",
90
+ signal,
91
+ headers: {
92
+ "q-user-token": token,
93
+ "q-institution-id": "qorum"
94
+ }
95
+ });
96
+ const text = await response.text();
97
+ if (!response.ok) {
98
+ const err = new Error(`Failed to get signer: ${response.status} ${text}`);
99
+ err.status = response.status;
100
+ throw err;
101
+ }
102
+ return text ? JSON.parse(text) : null;
103
+ }
104
+
105
+ async onlyServersGet(url, signal) {
106
+ const response = await fetch(url, {
107
+ method: "GET",
108
+ signal,
109
+ headers: {
110
+ "q-server-token": this.token,
111
+ "q-institution-id": this.institutionId
112
+ }
113
+ });
114
+ const text = await response.text();
115
+ if (!response.ok) {
116
+ const err = new Error(`Failed to get signer: ${response.status} ${text}`);
117
+ err.status = response.status;
118
+ throw err;
119
+ }
120
+ return text ? JSON.parse(text) : null;
121
+ }
122
+
123
+ async getGenesisDomains() {
124
+ return this.authorizedDomains;
125
+ }
126
+
127
+ async initPoolRequest(servers, method = 'GET', endpoint, body = {}, token) {
128
+ const domain = await this.getGenesisDomains();
129
+ let lastError;
130
+
131
+ for (const name of servers) {
132
+ if (domain === 'qorum.one') {
133
+ const url = `https://${name}.${domain}/${endpoint}`;
134
+ const controller = new AbortController();
135
+ // Sin timeout en POST: abortar una petición en curso la repetiría en otro servidor
136
+ const timer = method === 'GET' ? setTimeout(() => controller.abort(), 8000) : null;
137
+ try {
138
+
139
+ const _response = method === 'GET'
140
+ ? await this.get(url, token, controller.signal)
141
+ : await this.post(url, body, token, controller.signal);
142
+ const server = name;
143
+ return {
144
+ server,
145
+ receipt: _response.receipt,
146
+ }
147
+ } catch (error) {
148
+ lastError = error;
149
+ const retryable = error.status === undefined || error.status >= 500;
150
+ console.warn(`Falló ${url}:`, error.message);
151
+ if (!retryable) throw error; // 4xx: no seguir
152
+ } finally {
153
+ if (timer) clearTimeout(timer);
154
+ }
155
+ }
156
+ }
157
+ throw lastError ?? new Error('Ningún servidor respondió');
158
+ }
159
+
160
+ async initDevPoolRequest(servers, method = 'GET', endpoint, token) {
161
+ const domain = "http://localhost";
162
+ let lastError;
163
+
164
+ for (const name of servers) {
165
+ const url = `${domain}:${name}/${endpoint}`;
166
+ const controller = new AbortController();
167
+ // Sin timeout en POST: abortar una petición en curso la repetiría en otro servidor
168
+ const timer = method === 'GET' ? setTimeout(() => controller.abort(), 8000) : null;
169
+ try {
170
+
171
+ const res = method === 'GET'
172
+ ? await this.get(url, token, controller.signal)
173
+ : await this.post(url, body, token, controller.signal);
174
+ const server = name;
175
+ return {
176
+ server,
177
+ res
178
+ }
179
+ } catch (error) {
180
+ lastError = error;
181
+ const retryable = error.status === undefined || error.status >= 500;
182
+ console.warn(`Falló ${url}:`, error.message);
183
+ if (!retryable) throw error; // 4xx: no seguir
184
+ } finally {
185
+ if (timer) clearTimeout(timer);
186
+ }
187
+ }
188
+ }
189
+
190
+ async initServerRequest(method = 'GET', endpoint, body = {}) {
191
+ const domains = await this.getGenesisDomains();
192
+ let lastError;
193
+
194
+ for (const domain of domains) {
195
+ if (domain === 'qorum.one') {
196
+ for (const name of TRAIN) {
197
+ const url = `https://${name}.${domain}/${endpoint}`;
198
+ const controller = new AbortController();
199
+ // Sin timeout en POST: abortar una petición en curso la repetiría en otro servidor
200
+ const timer =
201
+ method === 'GET'
202
+ ? setTimeout(() => controller.abort(), 8000)
203
+ : null;
204
+ try {
205
+ const _response =
206
+ method === 'GET'
207
+ ? await this.onlyServersGet(url, controller.signal)
208
+ : await this.onlyServerPost(url, body, controller.signal);
209
+ const server = name;
210
+ return {
211
+ server,
212
+ receipt: _response.receipt,
213
+ };
214
+ } catch (error) {
215
+ lastError = error;
216
+ const retryable =
217
+ error.status === undefined || error.status >= 500;
218
+ console.warn(`Falló ${url}:`, error.message);
219
+ if (!retryable) throw error; // 4xx: no seguir
220
+ } finally {
221
+ if (timer) clearTimeout(timer);
222
+ }
223
+ }
224
+ } else {
225
+ for (const name of TRAIN_INSTITUTION) {
226
+ const url = `https://${name}.${domain}/${endpoint}`;
227
+ const controller = new AbortController();
228
+ // Sin timeout en POST: abortar una petición en curso la repetiría en otro servidor
229
+ const timer =
230
+ method === 'GET'
231
+ ? setTimeout(() => controller.abort(), 8000)
232
+ : null;
233
+ try {
234
+ const _response =
235
+ method === 'GET'
236
+ ? await this.onlyServersGet(url, controller.signal)
237
+ : await this.onlyServerPost(
238
+ url,
239
+ body,
240
+ controller.signal,
241
+ );
242
+ const server = name;
243
+ return {
244
+ server,
245
+ receipt: _response.receipt,
246
+ };
247
+ } catch (error) {
248
+ lastError = error;
249
+ const retryable =
250
+ error.status === undefined || error.status >= 500;
251
+ console.warn(`Falló ${url}:`, error.message);
252
+ if (!retryable) throw error; // 4xx: no seguir
253
+ } finally {
254
+ if (timer) clearTimeout(timer);
255
+ }
256
+ }
257
+ }
258
+
259
+ }
260
+
261
+ throw lastError ?? new Error('Ningún servidor respondió');
262
+ }
263
+
264
+ addAuthorizedAddress(address) {
265
+ if (address.length > 0) {
266
+ for (let i = 0; i < address; i++) {
267
+ if (!this.authorizedAddress.includes(address[i])) {
268
+ this.authorizedAddress.push(address[i]);
269
+ }
270
+ }
271
+ }
272
+ }
273
+
274
+ isAuthorizedAddress(address) {
275
+ return this.authorizedAddress.includes(address);
276
+ };
277
+
278
+ }
279
+
280
+ module.exports = { Signer };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.