@kynesyslabs/demosdk 2.7.10 → 2.8.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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Custom Charges Types
3
+ *
4
+ * Defines types for variable-cost operations that require user consent
5
+ * before execution. Used in the confirm/execute two-step transaction flow
6
+ * to provide cost transparency.
7
+ *
8
+ * @fileoverview Custom charges type definitions for cost estimation
9
+ */
10
+ /**
11
+ * Cost breakdown for IPFS operations
12
+ *
13
+ * Provides detailed cost calculation components so users can understand
14
+ * what they're paying for.
15
+ */
16
+ export interface IPFSCostBreakdown {
17
+ /** Base cost for the operation in DEM wei */
18
+ base_cost: string;
19
+ /** Cost based on file size in DEM wei */
20
+ size_cost: string;
21
+ /** Cost based on storage duration in DEM wei (optional for indefinite pins) */
22
+ duration_cost?: string;
23
+ /** Any additional costs (network fees, etc.) */
24
+ additional_costs?: Record<string, string>;
25
+ }
26
+ /**
27
+ * IPFS custom charges configuration
28
+ *
29
+ * Included in transaction content to specify maximum cost user agrees to pay.
30
+ * Node will validate that actual cost does not exceed max_cost_dem.
31
+ */
32
+ export interface IPFSCustomCharges {
33
+ /** Maximum cost user is willing to pay (in DEM wei as string for BigInt safety) */
34
+ max_cost_dem: string;
35
+ /** File size in bytes - used for cost calculation validation */
36
+ file_size_bytes: number;
37
+ /** IPFS operation type */
38
+ operation: "IPFS_ADD" | "IPFS_PIN" | "IPFS_UNPIN";
39
+ /** Optional duration in blocks (for PIN operations) */
40
+ duration_blocks?: number;
41
+ /** Optional cost breakdown from ipfsQuote (for reference) */
42
+ estimated_breakdown?: IPFSCostBreakdown;
43
+ }
44
+ /**
45
+ * Custom charges container for transaction content
46
+ *
47
+ * Extensible structure to support various operation types that require
48
+ * cost estimation. Each field is optional and specific to operation type.
49
+ *
50
+ * @example
51
+ * // IPFS operation with custom charges
52
+ * const tx: TransactionContent = {
53
+ * type: "ipfs",
54
+ * // ... other fields
55
+ * custom_charges: {
56
+ * ipfs: {
57
+ * max_cost_dem: "1000000000000000000",
58
+ * file_size_bytes: 1024,
59
+ * operation: "IPFS_ADD"
60
+ * }
61
+ * }
62
+ * }
63
+ */
64
+ export interface CustomCharges {
65
+ /** IPFS operation cost configuration */
66
+ ipfs?: IPFSCustomCharges;
67
+ }
68
+ /**
69
+ * Custom charges response in ValidityData
70
+ *
71
+ * Returned by confirmTx to show actual costs vs maximum user agreed to pay.
72
+ * Allows user to review and abort if actual cost is higher than expected.
73
+ */
74
+ export interface ValidityDataCustomCharges {
75
+ /** Charge type identifier */
76
+ type: "ipfs_storage" | "ipfs_bandwidth" | "compute" | string;
77
+ /** What user signed as maximum (from TX custom_charges) */
78
+ max_cost_dem: string;
79
+ /** What node will actually charge (must be <= max_cost_dem) */
80
+ actual_cost_dem: string;
81
+ /** Detailed breakdown of actual costs */
82
+ breakdown: IPFSCostBreakdown;
83
+ }
84
+ /**
85
+ * Check if custom charges include IPFS configuration
86
+ */
87
+ export declare function hasIPFSCustomCharges(charges: CustomCharges | undefined): charges is CustomCharges & {
88
+ ipfs: IPFSCustomCharges;
89
+ };
90
+ /**
91
+ * Validate that actual cost does not exceed maximum
92
+ */
93
+ export declare function isValidCharge(maxCostDem: string, actualCostDem: string): boolean;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * Custom Charges Types
4
+ *
5
+ * Defines types for variable-cost operations that require user consent
6
+ * before execution. Used in the confirm/execute two-step transaction flow
7
+ * to provide cost transparency.
8
+ *
9
+ * @fileoverview Custom charges type definitions for cost estimation
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.hasIPFSCustomCharges = hasIPFSCustomCharges;
13
+ exports.isValidCharge = isValidCharge;
14
+ // ============================================================================
15
+ // Type Guards
16
+ // ============================================================================
17
+ /**
18
+ * Check if custom charges include IPFS configuration
19
+ */
20
+ function hasIPFSCustomCharges(charges) {
21
+ return charges?.ipfs !== undefined;
22
+ }
23
+ /**
24
+ * Validate that actual cost does not exceed maximum
25
+ */
26
+ function isValidCharge(maxCostDem, actualCostDem) {
27
+ try {
28
+ const max = BigInt(maxCostDem);
29
+ const actual = BigInt(actualCostDem);
30
+ return actual <= max;
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ }
36
+ //# sourceMappingURL=CustomCharges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomCharges.js","sourceRoot":"","sources":["../../../../src/types/blockchain/CustomCharges.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAkHH,oDAIC;AAKD,sCAWC;AA3BD,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,SAAgB,oBAAoB,CAChC,OAAkC;IAElC,OAAO,OAAO,EAAE,IAAI,KAAK,SAAS,CAAA;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CACzB,UAAkB,EAClB,aAAqB;IAErB,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;QAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;QACpC,OAAO,MAAM,IAAI,GAAG,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAA;IAChB,CAAC;AACL,CAAC"}
@@ -17,6 +17,7 @@ import { ContractCallPayload } from "./TransactionSubtypes/ContractCallTransacti
17
17
  import { D402PaymentPayload } from "./TransactionSubtypes/D402PaymentTransaction";
18
18
  import { EscrowPayload } from "./TransactionSubtypes/EscrowTransaction";
19
19
  import { IPFSPayload } from "./TransactionSubtypes/IPFSTransaction";
20
+ import { CustomCharges } from "./CustomCharges";
20
21
  export type TransactionContentData = ["web2Request", IWeb2Payload] | ["crosschainOperation", XMScript] | ["native", INativePayload] | ["demoswork", DemoScript] | ["l2psEncryptedTx", L2PSEncryptedPayload] | ["identity", IdentityPayload] | ["instantMessaging", InstantMessagingPayload] | ["nativeBridge", NativeBridgeTxPayload] | ["storage", StoragePayload] | ["storageProgram", StorageProgramPayload] | ["l2ps_hash_update", L2PSHashPayload] | ["contractDeploy", ContractDeployPayload] | ["contractCall", ContractCallPayload] | ["d402_payment", D402PaymentPayload] | ["escrow", EscrowPayload] | ["ipfs", IPFSPayload];
21
22
  export interface TransactionContent {
22
23
  type: "web2Request" | "crosschainOperation" | "subnet" | "native" | "demoswork" | "genesis" | "NODE_ONLINE" | "identity" | "instantMessaging" | "nativeBridge" | "l2psEncryptedTx" | "storage" | "storageProgram" | "l2ps_hash_update" | "contractDeploy" | "contractCall" | "d402_payment" | "escrow" | "ipfs";
@@ -29,6 +30,7 @@ export interface TransactionContent {
29
30
  nonce: number;
30
31
  timestamp: number;
31
32
  transaction_fee: TxFee;
33
+ custom_charges?: CustomCharges;
32
34
  }
33
35
  export interface Transaction {
34
36
  content: TransactionContent;
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../../src/types/blockchain/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAiGA,uCAAuC;AACvC,wDAAqC"}
1
+ {"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../../src/types/blockchain/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAqGA,uCAAuC;AACvC,wDAAqC"}
@@ -1,6 +1,7 @@
1
1
  import { Operation } from "../gls/Operation";
2
2
  import { Transaction } from "./Transaction";
3
3
  import { SigningAlgorithm } from "../cryptography";
4
+ import { ValidityDataCustomCharges } from "./CustomCharges";
4
5
  export interface ValidityData {
5
6
  data: {
6
7
  valid: boolean;
@@ -8,6 +9,7 @@ export interface ValidityData {
8
9
  message: string;
9
10
  gas_operation: Operation;
10
11
  transaction: Transaction;
12
+ custom_charges?: ValidityDataCustomCharges;
11
13
  };
12
14
  signature: {
13
15
  type: SigningAlgorithm;
@@ -25,6 +27,7 @@ export declare class CValidityData implements ValidityData {
25
27
  message: string;
26
28
  gas_operation: Operation;
27
29
  transaction: Transaction;
30
+ custom_charges?: ValidityDataCustomCharges;
28
31
  };
29
32
  signature: {
30
33
  type: SigningAlgorithm;
@@ -1 +1 @@
1
- {"version":3,"file":"ValidityData.js","sourceRoot":"","sources":["../../../../src/types/blockchain/ValidityData.ts"],"names":[],"mappings":";;;AA2BA,2DAA2D;AAC3D,MAAa,aAAa;CAqDzB;AArDD,sCAqDC"}
1
+ {"version":3,"file":"ValidityData.js","sourceRoot":"","sources":["../../../../src/types/blockchain/ValidityData.ts"],"names":[],"mappings":";;;AA+BA,2DAA2D;AAC3D,MAAa,aAAa;CAuDzB;AAvDD,sCAuDC"}
@@ -3,6 +3,7 @@ export { Block, BlockContent, NativeTablesHashes, GenesisBlock } from "./blockch
3
3
  export { ISignature } from "./blockchain/ISignature";
4
4
  export { RawTransaction } from "./blockchain/rawTransaction";
5
5
  export { Transaction, TransactionContent, TransactionContentData, } from "./blockchain/Transaction";
6
+ export { type CustomCharges, type IPFSCustomCharges, type IPFSCostBreakdown, type ValidityDataCustomCharges, hasIPFSCustomCharges, isValidCharge, } from "./blockchain/CustomCharges";
6
7
  export { L2PSTransaction, Web2Transaction, CrosschainTransaction, NativeTransaction, DemosworkTransaction, IdentityTransaction, InstantMessagingTransaction, NativeBridgeTransaction, SpecificTransaction, IPFSTransaction, type IPFSTransactionContent, type IPFSPayload, type IPFSAddPayload, type IPFSPinPayload, type IPFSUnpinPayload, type IPFSOperationType, isIPFSAddPayload, isIPFSPinPayload, isIPFSUnpinPayload, isIPFSPayload, } from "./blockchain/TransactionSubtypes";
7
8
  export { INativePayload } from "./native/INativePayload";
8
9
  export { InstantMessagingPayload } from "./instantMessaging";
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isTransactionDataType = exports.isTransactionType = exports.SupportedTokens = exports.SupportedChains = exports.ChainProviders = exports.RPCResponseSkeleton = exports.stepKeysEnum = exports.XmStepResult = exports.DataTypes = exports.EnumWeb2Actions = exports.CValidityData = exports.isIPFSPayload = exports.isIPFSUnpinPayload = exports.isIPFSPinPayload = exports.isIPFSAddPayload = void 0;
3
+ exports.isTransactionDataType = exports.isTransactionType = exports.SupportedTokens = exports.SupportedChains = exports.ChainProviders = exports.RPCResponseSkeleton = exports.stepKeysEnum = exports.XmStepResult = exports.DataTypes = exports.EnumWeb2Actions = exports.CValidityData = exports.isIPFSPayload = exports.isIPFSUnpinPayload = exports.isIPFSPinPayload = exports.isIPFSAddPayload = exports.isValidCharge = exports.hasIPFSCustomCharges = void 0;
4
+ // REVIEW: Phase 9 - Custom charges for variable-cost operations
5
+ var CustomCharges_1 = require("./blockchain/CustomCharges");
6
+ Object.defineProperty(exports, "hasIPFSCustomCharges", { enumerable: true, get: function () { return CustomCharges_1.hasIPFSCustomCharges; } });
7
+ Object.defineProperty(exports, "isValidCharge", { enumerable: true, get: function () { return CustomCharges_1.isValidCharge; } });
4
8
  // Export all specific transaction types
5
9
  var TransactionSubtypes_1 = require("./blockchain/TransactionSubtypes");
6
10
  Object.defineProperty(exports, "isIPFSAddPayload", { enumerable: true, get: function () { return TransactionSubtypes_1.isIPFSAddPayload; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;AAmBA,wCAAwC;AACxC,wEAsByC;AAJrC,uHAAA,gBAAgB,OAAA;AAChB,uHAAA,gBAAgB,OAAA;AAChB,yHAAA,kBAAkB,OAAA;AAClB,oHAAA,aAAa,OAAA;AAUjB,0DAAuE;AAA9D,6GAAA,aAAa,OAAA;AA6CtB,OAAO;AACP,+BAce;AADX,uGAAA,eAAe,OAAA;AAgBnB,mDAA4D;AAAnD,sGAAA,SAAS,OAAA;AAOlB,2CAQ0B;AAHtB,qGAAA,YAAY,OAAA;AAEZ,qGAAA,YAAY,OAAA;AAGhB,2CAU4B;AADxB,0GAAA,aAAa,OAAuB;AAgBxC,gDAI2B;AAHvB,2GAAA,cAAc,OAAA;AACd,4GAAA,eAAe,OAAA;AACf,4GAAA,eAAe,OAAA;AAanB,+BAA+B;AAC/B,gEAG+C;AAF3C,0GAAA,iBAAiB,OAAA;AACjB,8GAAA,qBAAqB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;AAmBA,gEAAgE;AAChE,4DAOmC;AAF/B,qHAAA,oBAAoB,OAAA;AACpB,8GAAA,aAAa,OAAA;AAGjB,wCAAwC;AACxC,wEAsByC;AAJrC,uHAAA,gBAAgB,OAAA;AAChB,uHAAA,gBAAgB,OAAA;AAChB,yHAAA,kBAAkB,OAAA;AAClB,oHAAA,aAAa,OAAA;AAUjB,0DAAuE;AAA9D,6GAAA,aAAa,OAAA;AA6CtB,OAAO;AACP,+BAce;AADX,uGAAA,eAAe,OAAA;AAgBnB,mDAA4D;AAAnD,sGAAA,SAAS,OAAA;AAOlB,2CAQ0B;AAHtB,qGAAA,YAAY,OAAA;AAEZ,qGAAA,YAAY,OAAA;AAGhB,2CAU4B;AADxB,0GAAA,aAAa,OAAuB;AAgBxC,gDAI2B;AAHvB,2GAAA,cAAc,OAAA;AACd,4GAAA,eAAe,OAAA;AACf,4GAAA,eAAe,OAAA;AAanB,+BAA+B;AAC/B,gEAG+C;AAF3C,0GAAA,iBAAiB,OAAA;AACjB,8GAAA,qBAAqB,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kynesyslabs/demosdk",
3
- "version": "2.7.10",
3
+ "version": "2.8.1",
4
4
  "description": "Demosdk is a JavaScript/TypeScript SDK that provides a unified interface for interacting with Demos network",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",