@kynesyslabs/demosdk 2.5.13 → 2.6.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.
- package/build/index.d.ts +1 -0
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/ipfs/IPFSOperations.d.ts +272 -0
- package/build/ipfs/IPFSOperations.js +293 -0
- package/build/ipfs/IPFSOperations.js.map +1 -0
- package/build/ipfs/index.d.ts +3 -0
- package/build/ipfs/index.js +7 -0
- package/build/ipfs/index.js.map +1 -0
- package/build/types/blockchain/Transaction.d.ts +3 -2
- package/build/types/blockchain/Transaction.js.map +1 -1
- package/build/types/blockchain/TransactionSubtypes/IPFSTransaction.d.ts +92 -0
- package/build/types/blockchain/TransactionSubtypes/IPFSTransaction.js +49 -0
- package/build/types/blockchain/TransactionSubtypes/IPFSTransaction.js.map +1 -0
- package/build/types/blockchain/TransactionSubtypes/index.d.ts +3 -1
- package/build/types/blockchain/TransactionSubtypes/index.js +1 -0
- package/build/types/blockchain/TransactionSubtypes/index.js.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.js +7 -1
- package/build/types/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.escrow = exports.storage = exports.instantMessaging = exports.bridge = exports.web2 = exports.abstraction = exports.websdk = exports.l2ps = exports.demoswork = exports.wallet = exports.xmcore = exports.xmwebsdk = exports.xmlocalsdk = exports.utils = exports.encryption = exports.types = void 0;
|
|
36
|
+
exports.ipfs = exports.escrow = exports.storage = exports.instantMessaging = exports.bridge = exports.web2 = exports.abstraction = exports.websdk = exports.l2ps = exports.demoswork = exports.wallet = exports.xmcore = exports.xmwebsdk = exports.xmlocalsdk = exports.utils = exports.encryption = exports.types = void 0;
|
|
37
37
|
// Common types and constants
|
|
38
38
|
exports.types = __importStar(require("./types"));
|
|
39
39
|
// Basic cryptographic and data manipulation functions
|
|
@@ -54,4 +54,5 @@ exports.bridge = __importStar(require("./bridge"));
|
|
|
54
54
|
exports.instantMessaging = __importStar(require("./instant_messaging"));
|
|
55
55
|
exports.storage = __importStar(require("./storage"));
|
|
56
56
|
exports.escrow = __importStar(require("./escrow"));
|
|
57
|
+
exports.ipfs = __importStar(require("./ipfs"));
|
|
57
58
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA6B;AAC7B,iDAAgC;AAChC,sDAAsD;AACtD,2DAA0C;AAC1C,iDAAgC;AAEhC,gCAAgC;AAChC,oEAAmD;AACnD,gEAA+C;AAC/C,4DAA2C,CAAC,gCAAgC;AAE5E,mDAAkC;AAClC,yDAAwC;AAExC,+CAA8B;AAE9B,mDAAkC;AAClC,6DAA4C;AAC5C,2DAA0C;AAE1C,qCAAqC;AACrC,mDAAkC;AAElC,wEAAuD;AAEvD,qDAAoC;AAEpC,mDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA6B;AAC7B,iDAAgC;AAChC,sDAAsD;AACtD,2DAA0C;AAC1C,iDAAgC;AAEhC,gCAAgC;AAChC,oEAAmD;AACnD,gEAA+C;AAC/C,4DAA2C,CAAC,gCAAgC;AAE5E,mDAAkC;AAClC,yDAAwC;AAExC,+CAA8B;AAE9B,mDAAkC;AAClC,6DAA4C;AAC5C,2DAA0C;AAE1C,qCAAqC;AACrC,mDAAkC;AAElC,wEAAuD;AAEvD,qDAAoC;AAEpC,mDAAkC;AAElC,+CAA8B"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IPFS Operations for Demos Network SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides payload creators for IPFS transactions and helper utilities.
|
|
5
|
+
* Works with the Demos transaction system for add, pin, and unpin operations.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview IPFS operations module for SDK
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { ipfs } from '@kynesyslabs/demosdk'
|
|
12
|
+
*
|
|
13
|
+
* // Create add payload for transaction
|
|
14
|
+
* const addPayload = ipfs.IPFSOperations.createAddPayload(
|
|
15
|
+
* Buffer.from('Hello IPFS!'),
|
|
16
|
+
* 'hello.txt'
|
|
17
|
+
* )
|
|
18
|
+
*
|
|
19
|
+
* // Create pin payload for existing CID
|
|
20
|
+
* const pinPayload = ipfs.IPFSOperations.createPinPayload(
|
|
21
|
+
* 'QmExampleCID...'
|
|
22
|
+
* )
|
|
23
|
+
*
|
|
24
|
+
* // Create unpin payload
|
|
25
|
+
* const unpinPayload = ipfs.IPFSOperations.createUnpinPayload(
|
|
26
|
+
* 'QmExampleCID...'
|
|
27
|
+
* )
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { IPFSAddPayload, IPFSPinPayload, IPFSUnpinPayload, IPFSPayload } from "../types/blockchain/TransactionSubtypes/IPFSTransaction";
|
|
31
|
+
/**
|
|
32
|
+
* IPFS configuration constants
|
|
33
|
+
*/
|
|
34
|
+
export declare const IPFS_CONSTANTS: {
|
|
35
|
+
/** Maximum content size for direct upload (1GB) */
|
|
36
|
+
readonly MAX_CONTENT_SIZE: number;
|
|
37
|
+
/** CIDv0 pattern (Qm followed by base58 characters) */
|
|
38
|
+
readonly CID_V0_PATTERN: RegExp;
|
|
39
|
+
/** CIDv1 patterns (bafy or bafk prefix with base32 characters) */
|
|
40
|
+
readonly CID_V1_PATTERN: RegExp;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Options for the add operation
|
|
44
|
+
*/
|
|
45
|
+
export interface AddOptions {
|
|
46
|
+
/** Optional filename for the content */
|
|
47
|
+
filename?: string;
|
|
48
|
+
/** Optional metadata to associate with the pin */
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Options for the pin operation
|
|
53
|
+
*/
|
|
54
|
+
export interface PinOptions {
|
|
55
|
+
/** Duration in blocks (0 = indefinite) */
|
|
56
|
+
duration?: number;
|
|
57
|
+
/** Optional metadata to associate with the pin */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Response from IPFS status query
|
|
62
|
+
*/
|
|
63
|
+
export interface IPFSStatusResponse {
|
|
64
|
+
healthy: boolean;
|
|
65
|
+
peerId?: string;
|
|
66
|
+
peerCount?: number;
|
|
67
|
+
timestamp: number;
|
|
68
|
+
error?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Response from IPFS add operation
|
|
72
|
+
*/
|
|
73
|
+
export interface IPFSAddResponse {
|
|
74
|
+
success: boolean;
|
|
75
|
+
cid?: string;
|
|
76
|
+
size?: number;
|
|
77
|
+
error?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Response from IPFS get operation
|
|
81
|
+
*/
|
|
82
|
+
export interface IPFSGetResponse {
|
|
83
|
+
success: boolean;
|
|
84
|
+
cid: string;
|
|
85
|
+
content?: string;
|
|
86
|
+
size?: number;
|
|
87
|
+
base64: boolean;
|
|
88
|
+
error?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Pin information from account state
|
|
92
|
+
*/
|
|
93
|
+
export interface PinInfo {
|
|
94
|
+
cid: string;
|
|
95
|
+
size: number;
|
|
96
|
+
timestamp: number;
|
|
97
|
+
expiresAt?: number;
|
|
98
|
+
metadata?: Record<string, unknown>;
|
|
99
|
+
wasFree?: boolean;
|
|
100
|
+
freeBytes?: number;
|
|
101
|
+
costPaid?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Response from pins query
|
|
105
|
+
*/
|
|
106
|
+
export interface IPFSPinsResponse {
|
|
107
|
+
success: boolean;
|
|
108
|
+
address: string;
|
|
109
|
+
pins: PinInfo[];
|
|
110
|
+
count: number;
|
|
111
|
+
totalPinnedBytes: number;
|
|
112
|
+
earnedRewards: string;
|
|
113
|
+
paidCosts: string;
|
|
114
|
+
error?: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* IPFS Operations class for creating payloads and utility functions
|
|
118
|
+
*
|
|
119
|
+
* This class provides static methods to create transaction payloads for IPFS operations.
|
|
120
|
+
* The payloads can be used with the Demos transaction system.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { ipfs, websdk } from '@kynesyslabs/demosdk'
|
|
125
|
+
*
|
|
126
|
+
* // Initialize Demos client
|
|
127
|
+
* const demos = new websdk.Demos({ rpcUrl: 'https://rpc.demos.network' })
|
|
128
|
+
*
|
|
129
|
+
* // Create add payload
|
|
130
|
+
* const addPayload = ipfs.IPFSOperations.createAddPayload(
|
|
131
|
+
* Buffer.from('My content'),
|
|
132
|
+
* 'myfile.txt'
|
|
133
|
+
* )
|
|
134
|
+
*
|
|
135
|
+
* // Build and send transaction (pseudocode - actual tx flow depends on integration)
|
|
136
|
+
* // The payload goes in transaction.content.data as ['ipfs', payload]
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare class IPFSOperations {
|
|
140
|
+
/**
|
|
141
|
+
* Create a payload for IPFS_ADD operation
|
|
142
|
+
*
|
|
143
|
+
* Uploads content to IPFS and automatically pins it to the sender's account.
|
|
144
|
+
*
|
|
145
|
+
* @param content - Content to upload (Buffer, Uint8Array, or string)
|
|
146
|
+
* @param options - Optional filename and metadata
|
|
147
|
+
* @returns IPFSAddPayload for transaction creation
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* // Simple text upload
|
|
152
|
+
* const payload = IPFSOperations.createAddPayload(
|
|
153
|
+
* 'Hello, IPFS!',
|
|
154
|
+
* { filename: 'hello.txt' }
|
|
155
|
+
* )
|
|
156
|
+
*
|
|
157
|
+
* // Binary content
|
|
158
|
+
* const imageBuffer = fs.readFileSync('image.png')
|
|
159
|
+
* const imagePayload = IPFSOperations.createAddPayload(
|
|
160
|
+
* imageBuffer,
|
|
161
|
+
* { filename: 'image.png', metadata: { type: 'image/png' } }
|
|
162
|
+
* )
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
static createAddPayload(content: Buffer | Uint8Array | string, options?: AddOptions): IPFSAddPayload;
|
|
166
|
+
/**
|
|
167
|
+
* Create a payload for IPFS_PIN operation
|
|
168
|
+
*
|
|
169
|
+
* Pins an existing CID to the sender's account.
|
|
170
|
+
*
|
|
171
|
+
* @param cid - Content Identifier to pin
|
|
172
|
+
* @param options - Optional duration and metadata
|
|
173
|
+
* @returns IPFSPinPayload for transaction creation
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // Pin indefinitely
|
|
178
|
+
* const payload = IPFSOperations.createPinPayload('QmExample...')
|
|
179
|
+
*
|
|
180
|
+
* // Pin with duration (blocks)
|
|
181
|
+
* const timedPayload = IPFSOperations.createPinPayload('QmExample...', {
|
|
182
|
+
* duration: 1000000, // ~30 days at 2.5s blocks
|
|
183
|
+
* metadata: { source: 'user-upload' }
|
|
184
|
+
* })
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
static createPinPayload(cid: string, options?: PinOptions): IPFSPinPayload;
|
|
188
|
+
/**
|
|
189
|
+
* Create a payload for IPFS_UNPIN operation
|
|
190
|
+
*
|
|
191
|
+
* Removes a pin from the sender's account.
|
|
192
|
+
*
|
|
193
|
+
* @param cid - Content Identifier to unpin
|
|
194
|
+
* @returns IPFSUnpinPayload for transaction creation
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const payload = IPFSOperations.createUnpinPayload('QmExample...')
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
static createUnpinPayload(cid: string): IPFSUnpinPayload;
|
|
202
|
+
/**
|
|
203
|
+
* Validate a CID format
|
|
204
|
+
*
|
|
205
|
+
* Supports both CIDv0 (Qm...) and CIDv1 (bafy.../bafk...) formats.
|
|
206
|
+
*
|
|
207
|
+
* @param cid - Content Identifier to validate
|
|
208
|
+
* @returns true if CID is valid format
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* IPFSOperations.isValidCID('QmExample...') // true for valid CIDv0
|
|
213
|
+
* IPFSOperations.isValidCID('bafyExample...') // true for valid CIDv1
|
|
214
|
+
* IPFSOperations.isValidCID('invalid') // false
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
static isValidCID(cid: string): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Validate content size
|
|
220
|
+
*
|
|
221
|
+
* @param content - Content to validate
|
|
222
|
+
* @returns true if content size is within limit
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const largeBuffer = Buffer.alloc(2 * 1024 * 1024 * 1024) // 2GB
|
|
227
|
+
* IPFSOperations.isValidContentSize(largeBuffer) // false
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
static isValidContentSize(content: Buffer | Uint8Array | string): boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Get content size in bytes
|
|
233
|
+
*
|
|
234
|
+
* @param content - Content to measure
|
|
235
|
+
* @returns Size in bytes
|
|
236
|
+
*/
|
|
237
|
+
static getContentSize(content: Buffer | Uint8Array | string): number;
|
|
238
|
+
/**
|
|
239
|
+
* Encode content to base64
|
|
240
|
+
*
|
|
241
|
+
* @param content - Content to encode
|
|
242
|
+
* @returns Base64 encoded string
|
|
243
|
+
*/
|
|
244
|
+
static encodeContent(content: Buffer | Uint8Array | string): string;
|
|
245
|
+
/**
|
|
246
|
+
* Decode base64 content to Buffer
|
|
247
|
+
*
|
|
248
|
+
* @param base64Content - Base64 encoded content
|
|
249
|
+
* @returns Decoded Buffer
|
|
250
|
+
*/
|
|
251
|
+
static decodeContent(base64Content: string): Buffer;
|
|
252
|
+
/**
|
|
253
|
+
* Decode base64 content to string
|
|
254
|
+
*
|
|
255
|
+
* @param base64Content - Base64 encoded content
|
|
256
|
+
* @param encoding - Text encoding (default: 'utf-8')
|
|
257
|
+
* @returns Decoded string
|
|
258
|
+
*/
|
|
259
|
+
static decodeContentAsString(base64Content: string, encoding?: BufferEncoding): string;
|
|
260
|
+
/**
|
|
261
|
+
* Check if payload is an add operation
|
|
262
|
+
*/
|
|
263
|
+
static isAddPayload(payload: IPFSPayload): payload is IPFSAddPayload;
|
|
264
|
+
/**
|
|
265
|
+
* Check if payload is a pin operation
|
|
266
|
+
*/
|
|
267
|
+
static isPinPayload(payload: IPFSPayload): payload is IPFSPinPayload;
|
|
268
|
+
/**
|
|
269
|
+
* Check if payload is an unpin operation
|
|
270
|
+
*/
|
|
271
|
+
static isUnpinPayload(payload: IPFSPayload): payload is IPFSUnpinPayload;
|
|
272
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IPFS Operations for Demos Network SDK
|
|
4
|
+
*
|
|
5
|
+
* Provides payload creators for IPFS transactions and helper utilities.
|
|
6
|
+
* Works with the Demos transaction system for add, pin, and unpin operations.
|
|
7
|
+
*
|
|
8
|
+
* @fileoverview IPFS operations module for SDK
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { ipfs } from '@kynesyslabs/demosdk'
|
|
13
|
+
*
|
|
14
|
+
* // Create add payload for transaction
|
|
15
|
+
* const addPayload = ipfs.IPFSOperations.createAddPayload(
|
|
16
|
+
* Buffer.from('Hello IPFS!'),
|
|
17
|
+
* 'hello.txt'
|
|
18
|
+
* )
|
|
19
|
+
*
|
|
20
|
+
* // Create pin payload for existing CID
|
|
21
|
+
* const pinPayload = ipfs.IPFSOperations.createPinPayload(
|
|
22
|
+
* 'QmExampleCID...'
|
|
23
|
+
* )
|
|
24
|
+
*
|
|
25
|
+
* // Create unpin payload
|
|
26
|
+
* const unpinPayload = ipfs.IPFSOperations.createUnpinPayload(
|
|
27
|
+
* 'QmExampleCID...'
|
|
28
|
+
* )
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.IPFSOperations = exports.IPFS_CONSTANTS = void 0;
|
|
33
|
+
// REVIEW: IPFS Operations class for Demos Network SDK
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Constants
|
|
36
|
+
// ============================================================================
|
|
37
|
+
/**
|
|
38
|
+
* IPFS configuration constants
|
|
39
|
+
*/
|
|
40
|
+
exports.IPFS_CONSTANTS = {
|
|
41
|
+
/** Maximum content size for direct upload (1GB) */
|
|
42
|
+
MAX_CONTENT_SIZE: 1024 * 1024 * 1024,
|
|
43
|
+
/** CIDv0 pattern (Qm followed by base58 characters) */
|
|
44
|
+
CID_V0_PATTERN: /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/,
|
|
45
|
+
/** CIDv1 patterns (bafy or bafk prefix with base32 characters) */
|
|
46
|
+
CID_V1_PATTERN: /^(bafy|bafk|bafz|bafb)[a-z2-7]{50,}$/i,
|
|
47
|
+
};
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// Main Class
|
|
50
|
+
// ============================================================================
|
|
51
|
+
/**
|
|
52
|
+
* IPFS Operations class for creating payloads and utility functions
|
|
53
|
+
*
|
|
54
|
+
* This class provides static methods to create transaction payloads for IPFS operations.
|
|
55
|
+
* The payloads can be used with the Demos transaction system.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { ipfs, websdk } from '@kynesyslabs/demosdk'
|
|
60
|
+
*
|
|
61
|
+
* // Initialize Demos client
|
|
62
|
+
* const demos = new websdk.Demos({ rpcUrl: 'https://rpc.demos.network' })
|
|
63
|
+
*
|
|
64
|
+
* // Create add payload
|
|
65
|
+
* const addPayload = ipfs.IPFSOperations.createAddPayload(
|
|
66
|
+
* Buffer.from('My content'),
|
|
67
|
+
* 'myfile.txt'
|
|
68
|
+
* )
|
|
69
|
+
*
|
|
70
|
+
* // Build and send transaction (pseudocode - actual tx flow depends on integration)
|
|
71
|
+
* // The payload goes in transaction.content.data as ['ipfs', payload]
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
class IPFSOperations {
|
|
75
|
+
// ========================================================================
|
|
76
|
+
// Payload Creators (for transactions)
|
|
77
|
+
// ========================================================================
|
|
78
|
+
/**
|
|
79
|
+
* Create a payload for IPFS_ADD operation
|
|
80
|
+
*
|
|
81
|
+
* Uploads content to IPFS and automatically pins it to the sender's account.
|
|
82
|
+
*
|
|
83
|
+
* @param content - Content to upload (Buffer, Uint8Array, or string)
|
|
84
|
+
* @param options - Optional filename and metadata
|
|
85
|
+
* @returns IPFSAddPayload for transaction creation
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Simple text upload
|
|
90
|
+
* const payload = IPFSOperations.createAddPayload(
|
|
91
|
+
* 'Hello, IPFS!',
|
|
92
|
+
* { filename: 'hello.txt' }
|
|
93
|
+
* )
|
|
94
|
+
*
|
|
95
|
+
* // Binary content
|
|
96
|
+
* const imageBuffer = fs.readFileSync('image.png')
|
|
97
|
+
* const imagePayload = IPFSOperations.createAddPayload(
|
|
98
|
+
* imageBuffer,
|
|
99
|
+
* { filename: 'image.png', metadata: { type: 'image/png' } }
|
|
100
|
+
* )
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
static createAddPayload(content, options = {}) {
|
|
104
|
+
// Convert content to base64
|
|
105
|
+
let base64Content;
|
|
106
|
+
if (typeof content === "string") {
|
|
107
|
+
base64Content = Buffer.from(content).toString("base64");
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Both Buffer and Uint8Array can be converted via Buffer.from
|
|
111
|
+
base64Content = Buffer.from(content).toString("base64");
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
operation: "IPFS_ADD",
|
|
115
|
+
content: base64Content,
|
|
116
|
+
filename: options.filename,
|
|
117
|
+
metadata: options.metadata,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a payload for IPFS_PIN operation
|
|
122
|
+
*
|
|
123
|
+
* Pins an existing CID to the sender's account.
|
|
124
|
+
*
|
|
125
|
+
* @param cid - Content Identifier to pin
|
|
126
|
+
* @param options - Optional duration and metadata
|
|
127
|
+
* @returns IPFSPinPayload for transaction creation
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* // Pin indefinitely
|
|
132
|
+
* const payload = IPFSOperations.createPinPayload('QmExample...')
|
|
133
|
+
*
|
|
134
|
+
* // Pin with duration (blocks)
|
|
135
|
+
* const timedPayload = IPFSOperations.createPinPayload('QmExample...', {
|
|
136
|
+
* duration: 1000000, // ~30 days at 2.5s blocks
|
|
137
|
+
* metadata: { source: 'user-upload' }
|
|
138
|
+
* })
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
static createPinPayload(cid, options = {}) {
|
|
142
|
+
// Validate CID format
|
|
143
|
+
if (!this.isValidCID(cid)) {
|
|
144
|
+
throw new Error(`Invalid CID format: ${cid}`);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
operation: "IPFS_PIN",
|
|
148
|
+
cid,
|
|
149
|
+
duration: options.duration,
|
|
150
|
+
metadata: options.metadata,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a payload for IPFS_UNPIN operation
|
|
155
|
+
*
|
|
156
|
+
* Removes a pin from the sender's account.
|
|
157
|
+
*
|
|
158
|
+
* @param cid - Content Identifier to unpin
|
|
159
|
+
* @returns IPFSUnpinPayload for transaction creation
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const payload = IPFSOperations.createUnpinPayload('QmExample...')
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
static createUnpinPayload(cid) {
|
|
167
|
+
// Validate CID format
|
|
168
|
+
if (!this.isValidCID(cid)) {
|
|
169
|
+
throw new Error(`Invalid CID format: ${cid}`);
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
operation: "IPFS_UNPIN",
|
|
173
|
+
cid,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
// ========================================================================
|
|
177
|
+
// Validation Utilities
|
|
178
|
+
// ========================================================================
|
|
179
|
+
/**
|
|
180
|
+
* Validate a CID format
|
|
181
|
+
*
|
|
182
|
+
* Supports both CIDv0 (Qm...) and CIDv1 (bafy.../bafk...) formats.
|
|
183
|
+
*
|
|
184
|
+
* @param cid - Content Identifier to validate
|
|
185
|
+
* @returns true if CID is valid format
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* IPFSOperations.isValidCID('QmExample...') // true for valid CIDv0
|
|
190
|
+
* IPFSOperations.isValidCID('bafyExample...') // true for valid CIDv1
|
|
191
|
+
* IPFSOperations.isValidCID('invalid') // false
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
static isValidCID(cid) {
|
|
195
|
+
if (!cid || typeof cid !== "string") {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
return (exports.IPFS_CONSTANTS.CID_V0_PATTERN.test(cid) ||
|
|
199
|
+
exports.IPFS_CONSTANTS.CID_V1_PATTERN.test(cid));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Validate content size
|
|
203
|
+
*
|
|
204
|
+
* @param content - Content to validate
|
|
205
|
+
* @returns true if content size is within limit
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const largeBuffer = Buffer.alloc(2 * 1024 * 1024 * 1024) // 2GB
|
|
210
|
+
* IPFSOperations.isValidContentSize(largeBuffer) // false
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
static isValidContentSize(content) {
|
|
214
|
+
let size;
|
|
215
|
+
if (typeof content === "string") {
|
|
216
|
+
size = Buffer.byteLength(content);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
size = content.length;
|
|
220
|
+
}
|
|
221
|
+
return size <= exports.IPFS_CONSTANTS.MAX_CONTENT_SIZE;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get content size in bytes
|
|
225
|
+
*
|
|
226
|
+
* @param content - Content to measure
|
|
227
|
+
* @returns Size in bytes
|
|
228
|
+
*/
|
|
229
|
+
static getContentSize(content) {
|
|
230
|
+
if (typeof content === "string") {
|
|
231
|
+
return Buffer.byteLength(content);
|
|
232
|
+
}
|
|
233
|
+
return content.length;
|
|
234
|
+
}
|
|
235
|
+
// ========================================================================
|
|
236
|
+
// Content Encoding Utilities
|
|
237
|
+
// ========================================================================
|
|
238
|
+
/**
|
|
239
|
+
* Encode content to base64
|
|
240
|
+
*
|
|
241
|
+
* @param content - Content to encode
|
|
242
|
+
* @returns Base64 encoded string
|
|
243
|
+
*/
|
|
244
|
+
static encodeContent(content) {
|
|
245
|
+
if (typeof content === "string") {
|
|
246
|
+
return Buffer.from(content).toString("base64");
|
|
247
|
+
}
|
|
248
|
+
// Both Buffer and Uint8Array can be converted via Buffer.from
|
|
249
|
+
return Buffer.from(content).toString("base64");
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Decode base64 content to Buffer
|
|
253
|
+
*
|
|
254
|
+
* @param base64Content - Base64 encoded content
|
|
255
|
+
* @returns Decoded Buffer
|
|
256
|
+
*/
|
|
257
|
+
static decodeContent(base64Content) {
|
|
258
|
+
return Buffer.from(base64Content, "base64");
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Decode base64 content to string
|
|
262
|
+
*
|
|
263
|
+
* @param base64Content - Base64 encoded content
|
|
264
|
+
* @param encoding - Text encoding (default: 'utf-8')
|
|
265
|
+
* @returns Decoded string
|
|
266
|
+
*/
|
|
267
|
+
static decodeContentAsString(base64Content, encoding = "utf-8") {
|
|
268
|
+
return Buffer.from(base64Content, "base64").toString(encoding);
|
|
269
|
+
}
|
|
270
|
+
// ========================================================================
|
|
271
|
+
// Type Guards
|
|
272
|
+
// ========================================================================
|
|
273
|
+
/**
|
|
274
|
+
* Check if payload is an add operation
|
|
275
|
+
*/
|
|
276
|
+
static isAddPayload(payload) {
|
|
277
|
+
return payload.operation === "IPFS_ADD";
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Check if payload is a pin operation
|
|
281
|
+
*/
|
|
282
|
+
static isPinPayload(payload) {
|
|
283
|
+
return payload.operation === "IPFS_PIN";
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Check if payload is an unpin operation
|
|
287
|
+
*/
|
|
288
|
+
static isUnpinPayload(payload) {
|
|
289
|
+
return payload.operation === "IPFS_UNPIN";
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exports.IPFSOperations = IPFSOperations;
|
|
293
|
+
//# sourceMappingURL=IPFSOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPFSOperations.js","sourceRoot":"","sources":["../../../src/ipfs/IPFSOperations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AASH,sDAAsD;AAEtD,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;GAEG;AACU,QAAA,cAAc,GAAG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SGetResponse, PinInfo, IPFSPinsResponse, } from "./IPFSOperations";
|
|
3
|
+
export type { IPFSOperationType, IPFSAddPayload, IPFSPinPayload, IPFSUnpinPayload, IPFSPayload, } from "../types/blockchain/TransactionSubtypes/IPFSTransaction";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IPFS_CONSTANTS = exports.IPFSOperations = void 0;
|
|
4
|
+
var IPFSOperations_1 = require("./IPFSOperations");
|
|
5
|
+
Object.defineProperty(exports, "IPFSOperations", { enumerable: true, get: function () { return IPFSOperations_1.IPFSOperations; } });
|
|
6
|
+
Object.defineProperty(exports, "IPFS_CONSTANTS", { enumerable: true, get: function () { return IPFSOperations_1.IPFS_CONSTANTS; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ipfs/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiE;AAAxD,gHAAA,cAAc,OAAA;AAAE,gHAAA,cAAc,OAAA"}
|
|
@@ -16,9 +16,10 @@ import { ContractDeployPayload } from "./TransactionSubtypes/ContractDeployTrans
|
|
|
16
16
|
import { ContractCallPayload } from "./TransactionSubtypes/ContractCallTransaction";
|
|
17
17
|
import { D402PaymentPayload } from "./TransactionSubtypes/D402PaymentTransaction";
|
|
18
18
|
import { EscrowPayload } from "./TransactionSubtypes/EscrowTransaction";
|
|
19
|
-
|
|
19
|
+
import { IPFSPayload } from "./TransactionSubtypes/IPFSTransaction";
|
|
20
|
+
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];
|
|
20
21
|
export interface TransactionContent {
|
|
21
|
-
type: "web2Request" | "crosschainOperation" | "subnet" | "native" | "demoswork" | "genesis" | "NODE_ONLINE" | "identity" | "instantMessaging" | "nativeBridge" | "l2psEncryptedTx" | "storage" | "storageProgram" | "l2ps_hash_update" | "contractDeploy" | "contractCall" | "d402_payment" | "escrow";
|
|
22
|
+
type: "web2Request" | "crosschainOperation" | "subnet" | "native" | "demoswork" | "genesis" | "NODE_ONLINE" | "identity" | "instantMessaging" | "nativeBridge" | "l2psEncryptedTx" | "storage" | "storageProgram" | "l2ps_hash_update" | "contractDeploy" | "contractCall" | "d402_payment" | "escrow" | "ipfs";
|
|
22
23
|
from: string;
|
|
23
24
|
from_ed25519_address: string;
|
|
24
25
|
to: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../../src/types/blockchain/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../../src/types/blockchain/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAiGA,uCAAuC;AACvC,wDAAqC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IPFS Transaction Types
|
|
3
|
+
*
|
|
4
|
+
* Defines transaction types for IPFS operations on the Demos Network.
|
|
5
|
+
* - IPFS_ADD: Upload content and auto-pin
|
|
6
|
+
* - IPFS_PIN: Pin existing CID
|
|
7
|
+
* - IPFS_UNPIN: Remove pin from account
|
|
8
|
+
*
|
|
9
|
+
* @fileoverview IPFS transaction type definitions for SDK
|
|
10
|
+
*/
|
|
11
|
+
import { Transaction, TransactionContent } from "../Transaction";
|
|
12
|
+
/**
|
|
13
|
+
* IPFS operation type constants
|
|
14
|
+
*/
|
|
15
|
+
export type IPFSOperationType = "IPFS_ADD" | "IPFS_PIN" | "IPFS_UNPIN";
|
|
16
|
+
/**
|
|
17
|
+
* Payload for IPFS_ADD operation
|
|
18
|
+
*
|
|
19
|
+
* Uploads content to IPFS and automatically pins it to the sender's account.
|
|
20
|
+
* Content is base64 encoded for JSON compatibility.
|
|
21
|
+
*/
|
|
22
|
+
export interface IPFSAddPayload {
|
|
23
|
+
/** The IPFS operation type */
|
|
24
|
+
operation: "IPFS_ADD";
|
|
25
|
+
/** Base64-encoded content to upload */
|
|
26
|
+
content: string;
|
|
27
|
+
/** Optional filename for the content */
|
|
28
|
+
filename?: string;
|
|
29
|
+
/** Optional metadata to associate with the pin */
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Payload for IPFS_PIN operation
|
|
34
|
+
*
|
|
35
|
+
* Pins an existing CID to the sender's account.
|
|
36
|
+
* Used when content already exists on IPFS and user wants to ensure availability.
|
|
37
|
+
*/
|
|
38
|
+
export interface IPFSPinPayload {
|
|
39
|
+
/** The IPFS operation type */
|
|
40
|
+
operation: "IPFS_PIN";
|
|
41
|
+
/** Content Identifier to pin */
|
|
42
|
+
cid: string;
|
|
43
|
+
/** Optional duration in blocks (0 = indefinite) */
|
|
44
|
+
duration?: number;
|
|
45
|
+
/** Optional metadata to associate with the pin */
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Payload for IPFS_UNPIN operation
|
|
50
|
+
*
|
|
51
|
+
* Removes a pin from the sender's account.
|
|
52
|
+
* Content may still exist on IPFS but sender no longer pays for hosting.
|
|
53
|
+
*/
|
|
54
|
+
export interface IPFSUnpinPayload {
|
|
55
|
+
/** The IPFS operation type */
|
|
56
|
+
operation: "IPFS_UNPIN";
|
|
57
|
+
/** Content Identifier to unpin */
|
|
58
|
+
cid: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Union type for all IPFS payloads
|
|
62
|
+
*/
|
|
63
|
+
export type IPFSPayload = IPFSAddPayload | IPFSPinPayload | IPFSUnpinPayload;
|
|
64
|
+
/**
|
|
65
|
+
* Transaction content type for IPFS operations
|
|
66
|
+
*/
|
|
67
|
+
export type IPFSTransactionContent = Omit<TransactionContent, "type" | "data"> & {
|
|
68
|
+
type: "ipfs";
|
|
69
|
+
data: ["ipfs", IPFSPayload];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Complete IPFS transaction interface
|
|
73
|
+
*/
|
|
74
|
+
export interface IPFSTransaction extends Omit<Transaction, "content"> {
|
|
75
|
+
content: IPFSTransactionContent;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if a payload is an IPFS_ADD operation
|
|
79
|
+
*/
|
|
80
|
+
export declare function isIPFSAddPayload(payload: IPFSPayload): payload is IPFSAddPayload;
|
|
81
|
+
/**
|
|
82
|
+
* Check if a payload is an IPFS_PIN operation
|
|
83
|
+
*/
|
|
84
|
+
export declare function isIPFSPinPayload(payload: IPFSPayload): payload is IPFSPinPayload;
|
|
85
|
+
/**
|
|
86
|
+
* Check if a payload is an IPFS_UNPIN operation
|
|
87
|
+
*/
|
|
88
|
+
export declare function isIPFSUnpinPayload(payload: IPFSPayload): payload is IPFSUnpinPayload;
|
|
89
|
+
/**
|
|
90
|
+
* Check if any payload is an IPFS payload
|
|
91
|
+
*/
|
|
92
|
+
export declare function isIPFSPayload(payload: unknown): payload is IPFSPayload;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IPFS Transaction Types
|
|
4
|
+
*
|
|
5
|
+
* Defines transaction types for IPFS operations on the Demos Network.
|
|
6
|
+
* - IPFS_ADD: Upload content and auto-pin
|
|
7
|
+
* - IPFS_PIN: Pin existing CID
|
|
8
|
+
* - IPFS_UNPIN: Remove pin from account
|
|
9
|
+
*
|
|
10
|
+
* @fileoverview IPFS transaction type definitions for SDK
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.isIPFSAddPayload = isIPFSAddPayload;
|
|
14
|
+
exports.isIPFSPinPayload = isIPFSPinPayload;
|
|
15
|
+
exports.isIPFSUnpinPayload = isIPFSUnpinPayload;
|
|
16
|
+
exports.isIPFSPayload = isIPFSPayload;
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Type Guards
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Check if a payload is an IPFS_ADD operation
|
|
22
|
+
*/
|
|
23
|
+
function isIPFSAddPayload(payload) {
|
|
24
|
+
return payload.operation === "IPFS_ADD";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if a payload is an IPFS_PIN operation
|
|
28
|
+
*/
|
|
29
|
+
function isIPFSPinPayload(payload) {
|
|
30
|
+
return payload.operation === "IPFS_PIN";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if a payload is an IPFS_UNPIN operation
|
|
34
|
+
*/
|
|
35
|
+
function isIPFSUnpinPayload(payload) {
|
|
36
|
+
return payload.operation === "IPFS_UNPIN";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if any payload is an IPFS payload
|
|
40
|
+
*/
|
|
41
|
+
function isIPFSPayload(payload) {
|
|
42
|
+
if (!payload || typeof payload !== "object")
|
|
43
|
+
return false;
|
|
44
|
+
const p = payload;
|
|
45
|
+
return (p.operation === "IPFS_ADD" ||
|
|
46
|
+
p.operation === "IPFS_PIN" ||
|
|
47
|
+
p.operation === "IPFS_UNPIN");
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=IPFSTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPFSTransaction.js","sourceRoot":"","sources":["../../../../../src/types/blockchain/TransactionSubtypes/IPFSTransaction.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAsGH,4CAEC;AAKD,4CAEC;AAKD,gDAEC;AAKD,sCAQC;AApCD,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,SAAgB,gBAAgB,CAAC,OAAoB;IACjD,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU,CAAA;AAC3C,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,OAAoB;IACjD,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU,CAAA;AAC3C,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAoB;IACnD,OAAO,OAAO,CAAC,SAAS,KAAK,YAAY,CAAA;AAC7C,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,OAAgB;IAC1C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IACzD,MAAM,CAAC,GAAG,OAAkC,CAAA;IAC5C,OAAO,CACH,CAAC,CAAC,SAAS,KAAK,UAAU;QAC1B,CAAC,CAAC,SAAS,KAAK,UAAU;QAC1B,CAAC,CAAC,SAAS,KAAK,YAAY,CAC/B,CAAA;AACL,CAAC"}
|
|
@@ -13,6 +13,7 @@ export * from './ContractDeployTransaction';
|
|
|
13
13
|
export * from './ContractCallTransaction';
|
|
14
14
|
export * from './D402PaymentTransaction';
|
|
15
15
|
export * from './EscrowTransaction';
|
|
16
|
+
export * from './IPFSTransaction';
|
|
16
17
|
import { L2PSTransaction } from './L2PSTransaction';
|
|
17
18
|
import { L2PSHashTransaction } from './L2PSHashTransaction';
|
|
18
19
|
import { Web2Transaction } from './Web2Transaction';
|
|
@@ -28,4 +29,5 @@ import { ContractDeployTransaction } from './ContractDeployTransaction';
|
|
|
28
29
|
import { ContractCallTransaction } from './ContractCallTransaction';
|
|
29
30
|
import { D402PaymentTransaction } from './D402PaymentTransaction';
|
|
30
31
|
import { EscrowTransaction } from './EscrowTransaction';
|
|
31
|
-
|
|
32
|
+
import { IPFSTransaction } from './IPFSTransaction';
|
|
33
|
+
export type SpecificTransaction = L2PSTransaction | L2PSHashTransaction | Web2Transaction | CrosschainTransaction | NativeTransaction | DemosworkTransaction | IdentityTransaction | InstantMessagingTransaction | NativeBridgeTransaction | StorageTransaction | StorageProgramTransaction | ContractDeployTransaction | ContractCallTransaction | D402PaymentTransaction | EscrowTransaction | IPFSTransaction;
|
|
@@ -29,4 +29,5 @@ __exportStar(require("./ContractDeployTransaction"), exports);
|
|
|
29
29
|
__exportStar(require("./ContractCallTransaction"), exports);
|
|
30
30
|
__exportStar(require("./D402PaymentTransaction"), exports);
|
|
31
31
|
__exportStar(require("./EscrowTransaction"), exports);
|
|
32
|
+
__exportStar(require("./IPFSTransaction"), exports);
|
|
32
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/blockchain/TransactionSubtypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,wDAAqC;AACrC,oDAAiC;AACjC,0DAAuC;AACvC,sDAAmC;AACnC,yDAAsC;AACtC,wDAAqC;AACrC,gEAA6C;AAC7C,4DAAyC;AACzC,uDAAoC;AACpC,8DAA2C;AAC3C,8DAA2C;AAC3C,4DAAyC;AACzC,2DAAwC;AACxC,sDAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/blockchain/TransactionSubtypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,wDAAqC;AACrC,oDAAiC;AACjC,0DAAuC;AACvC,sDAAmC;AACnC,yDAAsC;AACtC,wDAAqC;AACrC,gEAA6C;AAC7C,4DAAyC;AACzC,uDAAoC;AACpC,8DAA2C;AAC3C,8DAA2C;AAC3C,4DAAyC;AACzC,2DAAwC;AACxC,sDAAmC;AACnC,oDAAiC"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -3,7 +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 { L2PSTransaction, Web2Transaction, CrosschainTransaction, NativeTransaction, DemosworkTransaction, IdentityTransaction, InstantMessagingTransaction, NativeBridgeTransaction, SpecificTransaction, } from "./blockchain/TransactionSubtypes";
|
|
6
|
+
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
7
|
export { INativePayload } from "./native/INativePayload";
|
|
8
8
|
export { InstantMessagingPayload } from "./instantMessaging";
|
|
9
9
|
export { TxFee } from "./blockchain/TxFee";
|
package/build/types/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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 = 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 = void 0;
|
|
4
|
+
// Export all specific transaction types
|
|
5
|
+
var TransactionSubtypes_1 = require("./blockchain/TransactionSubtypes");
|
|
6
|
+
Object.defineProperty(exports, "isIPFSAddPayload", { enumerable: true, get: function () { return TransactionSubtypes_1.isIPFSAddPayload; } });
|
|
7
|
+
Object.defineProperty(exports, "isIPFSPinPayload", { enumerable: true, get: function () { return TransactionSubtypes_1.isIPFSPinPayload; } });
|
|
8
|
+
Object.defineProperty(exports, "isIPFSUnpinPayload", { enumerable: true, get: function () { return TransactionSubtypes_1.isIPFSUnpinPayload; } });
|
|
9
|
+
Object.defineProperty(exports, "isIPFSPayload", { enumerable: true, get: function () { return TransactionSubtypes_1.isIPFSPayload; } });
|
|
4
10
|
var ValidityData_1 = require("./blockchain/ValidityData");
|
|
5
11
|
Object.defineProperty(exports, "CValidityData", { enumerable: true, get: function () { return ValidityData_1.CValidityData; } });
|
|
6
12
|
// web2
|
package/build/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;
|
|
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"}
|
package/package.json
CHANGED