@yellow-org/sdk 1.2.1 → 1.3.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/dist/utils.js CHANGED
@@ -67,6 +67,8 @@ function parseChannelStatus(status) {
67
67
  return core.ChannelStatus.Open;
68
68
  case 'challenged':
69
69
  return core.ChannelStatus.Challenged;
70
+ case 'closing':
71
+ return core.ChannelStatus.Closing;
70
72
  case 'closed':
71
73
  return core.ChannelStatus.Closed;
72
74
  default:
@@ -205,30 +207,69 @@ export function transformSignedAppStateUpdateToRPC(signed) {
205
207
  };
206
208
  }
207
209
  export function transformAppSessionInfo(raw) {
210
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
211
+ throw new Error('Invalid app session: expected object payload');
212
+ }
213
+ const allocations = raw.allocations;
214
+ if (!Array.isArray(allocations)) {
215
+ throw new Error('Invalid app session allocations: expected allocations to be an array');
216
+ }
208
217
  return {
209
218
  appSessionId: raw.app_session_id,
210
219
  appDefinition: transformAppDefinitionFromRPC(raw.app_definition),
211
220
  isClosed: raw.status === 'closed',
212
221
  sessionData: raw.session_data || '',
213
222
  version: BigInt(raw.version),
214
- allocations: (raw.allocations || []).map((a) => ({
215
- participant: a.participant,
216
- asset: a.asset,
217
- amount: new Decimal(a.amount),
218
- })),
223
+ allocations: allocations.map(transformAppAllocationFromRPC),
224
+ };
225
+ }
226
+ function transformAppAllocationFromRPC(raw, index) {
227
+ const context = `app session allocation[${index}]`;
228
+ if (!raw || typeof raw.participant !== 'string') {
229
+ throw new Error(`Invalid ${context}: missing required string field participant`);
230
+ }
231
+ if (typeof raw.asset !== 'string') {
232
+ throw new Error(`Invalid ${context}: missing required string field asset`);
233
+ }
234
+ if (typeof raw.amount !== 'string') {
235
+ throw new Error(`Invalid ${context}: missing required string field amount`);
236
+ }
237
+ return {
238
+ participant: raw.participant,
239
+ asset: raw.asset,
240
+ amount: new Decimal(raw.amount),
219
241
  };
220
242
  }
221
243
  export function transformAppDefinitionFromRPC(raw) {
244
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
245
+ throw new Error('Invalid app definition: missing required fields (application_id, nonce)');
246
+ }
222
247
  if (!raw.application_id || raw.nonce === undefined || raw.nonce === null) {
223
248
  throw new Error('Invalid app definition: missing required fields (application_id, nonce)');
224
249
  }
250
+ if (!Array.isArray(raw.participants)) {
251
+ throw new Error('Invalid app definition: expected participants to be an array');
252
+ }
253
+ if (raw.quorum === undefined || raw.quorum === null) {
254
+ throw new Error('Invalid app definition: missing required field quorum');
255
+ }
225
256
  return {
226
257
  applicationId: raw.application_id,
227
- participants: (raw.participants || []).map((p) => ({
228
- walletAddress: p.wallet_address,
229
- signatureWeight: p.signature_weight,
230
- })),
258
+ participants: raw.participants.map(transformAppParticipantFromRPC),
231
259
  quorum: raw.quorum,
232
260
  nonce: BigInt(raw.nonce),
233
261
  };
234
262
  }
263
+ function transformAppParticipantFromRPC(raw, index) {
264
+ const context = `app definition participant[${index}]`;
265
+ if (!raw || typeof raw.wallet_address !== 'string') {
266
+ throw new Error(`Invalid ${context}: missing required string field wallet_address`);
267
+ }
268
+ if (typeof raw.signature_weight !== 'number') {
269
+ throw new Error(`Invalid ${context}: missing required numeric field signature_weight`);
270
+ }
271
+ return {
272
+ walletAddress: raw.wallet_address,
273
+ signatureWeight: raw.signature_weight,
274
+ };
275
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yellow-org/sdk",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "The Yellow SDK empowers developers to build high-performance, scalable web3 applications using state channels. It's designed to provide near-instant transactions and significantly improved user experiences by minimizing direct blockchain interactions.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,6 +11,7 @@
11
11
  ],
12
12
  "scripts": {
13
13
  "build": "npm run test && tsc",
14
+ "build:ci": "tsc",
14
15
  "codegen-abi": "npx tsx scripts/codegen-abi.ts",
15
16
  "build:prod": "npm run test && tsc -p tsconfig.prod.json",
16
17
  "build:full": "npm run build",
@@ -21,6 +22,7 @@
21
22
  "lint": "eslint src test --ext .ts",
22
23
  "typecheck": "tsc --noEmit",
23
24
  "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.config.cjs",
25
+ "drift:check": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.config.cjs --runTestsByPath test/unit/rpc-drift.test.ts test/unit/rpc-dto-drift.test.ts test/unit/public-api-drift.test.ts test/unit/abi-drift.test.ts test/unit/app-signing-drift.test.ts test/unit/transform-drift.test.ts",
24
26
  "test:types": "npm run validate",
25
27
  "dev": "npm run watch",
26
28
  "dev:docs": "npm run docs:tutorials && npm run watch",
@@ -62,7 +64,7 @@
62
64
  "abitype": "^1.2.3",
63
65
  "decimal.js": "^10.4.3",
64
66
  "jest-util": "^30.3.0",
65
- "viem": "^2.46.1",
67
+ "viem": "^2.50.4",
66
68
  "zod": "^4.3.6"
67
69
  },
68
70
  "devDependencies": {
@@ -80,10 +82,14 @@
80
82
  "ethers": "6.16.0",
81
83
  "glob": "^13.0.3",
82
84
  "jest": "^30.2.0",
83
- "prettier": "3.8.1",
85
+ "prettier": "3.8.3",
84
86
  "rimraf": "^6.1.3",
85
87
  "ts-jest": "^29.1.2",
86
88
  "ts-node": "^10.9.2",
87
- "typescript": "^5.3.0"
89
+ "typescript": "^6.0.3",
90
+ "ws": "8.21.0"
91
+ },
92
+ "overrides": {
93
+ "ws": "8.21.0"
88
94
  }
89
95
  }