@wishknish/knishio-client-ts 0.7.4 → 0.7.7

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 (43) hide show
  1. package/dist/index.cjs +2702 -1033
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +339 -106
  4. package/dist/index.d.ts +339 -106
  5. package/dist/index.iife.js +22052 -19964
  6. package/dist/index.iife.js.map +1 -1
  7. package/dist/index.js +2699 -1034
  8. package/dist/index.js.map +1 -1
  9. package/package.json +10 -4
  10. package/src/AuthToken.ts +8 -2
  11. package/src/KnishIOClient.ts +346 -51
  12. package/src/constants.ts +5 -3
  13. package/src/core/Atom.ts +167 -100
  14. package/src/core/AtomMeta.ts +11 -28
  15. package/src/core/Meta.ts +18 -15
  16. package/src/core/Molecule.ts +607 -141
  17. package/src/core/Wallet.ts +19 -24
  18. package/src/index.ts +8 -0
  19. package/src/instance/rules/Rule.ts +128 -19
  20. package/src/libraries/CheckMolecule.ts +88 -1
  21. package/src/libraries/crypto.ts +14 -30
  22. package/src/libraries/strings.ts +26 -25
  23. package/src/mutation/MutationAppendRequest.ts +52 -0
  24. package/src/mutation/MutationCreateRule.ts +2 -2
  25. package/src/mutation/MutationPeering.ts +37 -0
  26. package/src/mutation/MutationRequestAuthorization.ts +3 -3
  27. package/src/query/QueryActiveSession.ts +0 -1
  28. package/src/query/QueryContinuId.ts +8 -0
  29. package/src/query/QueryMetaTypeViaMolecule.ts +221 -0
  30. package/src/query/QueryWalletList.ts +2 -2
  31. package/src/response/ResponseAppendRequest.ts +17 -0
  32. package/src/response/ResponseBalance.ts +8 -3
  33. package/src/response/ResponseContinuId.ts +1 -1
  34. package/src/response/ResponseMetaType.ts +32 -19
  35. package/src/response/ResponseMetaTypeViaMolecule.ts +224 -0
  36. package/src/response/ResponsePeering.ts +17 -0
  37. package/src/response/ResponsePolicy.ts +2 -3
  38. package/src/response/ResponseProposeMolecule.ts +0 -1
  39. package/src/response/ResponseRequestAuthorization.ts +32 -2
  40. package/src/response/ResponseRequestAuthorizationGuest.ts +25 -1
  41. package/src/response/ResponseWalletList.ts +1 -1
  42. package/src/types/guards.ts +18 -5
  43. package/src/types/index.ts +3 -3
@@ -111,12 +111,36 @@ export default class ResponseRequestAuthorizationGuest extends Response {
111
111
  }
112
112
 
113
113
  /**
114
- * Returns timestamp
114
+ * Returns raw time value from payload
115
115
  */
116
116
  time(): any {
117
117
  return this.payloadKey('time')
118
118
  }
119
119
 
120
+ /**
121
+ * Returns the expiration timestamp as Unix seconds.
122
+ * Handles both server formats:
123
+ * - PHP server: time = lifetime in ms, expiresAt = Unix timestamp in payload
124
+ * - Rust server: time = Unix timestamp in seconds
125
+ */
126
+ expiresAt(): number {
127
+ try {
128
+ const ea = this.payloadKey('expiresAt')
129
+ if (ea) {
130
+ return Number(ea)
131
+ }
132
+ } catch (_e) {
133
+ // Not available in payload, fall back
134
+ }
135
+
136
+ const timeValue = Number(this.time())
137
+ if (timeValue >= 1577836800) {
138
+ return timeValue
139
+ }
140
+
141
+ return Math.floor(Date.now() / 1000) + Math.floor(timeValue / 1000)
142
+ }
143
+
120
144
  /**
121
145
  * Returns public key
122
146
  */
@@ -125,7 +125,7 @@ export default class ResponseWalletList extends Response {
125
125
  }
126
126
  }
127
127
 
128
- wallet.balance = Number(data.amount)
128
+ wallet.balance = String(data.amount != null ? data.amount : 0)
129
129
  wallet.pubkey = data.pubkey
130
130
  wallet.createdAt = data.createdAt
131
131
 
@@ -115,8 +115,8 @@ export function assertExhaustive<T>(
115
115
  * Exhaustive isotope type guard with compile-time checking
116
116
  */
117
117
  export function isAtomIsotope(value: unknown): value is AtomIsotope {
118
- return typeof value === 'string' &&
119
- (['C', 'V', 'U', 'T', 'M', 'I', 'R', 'B', 'F'] as const).includes(value as AtomIsotope)
118
+ return typeof value === 'string' &&
119
+ (['C', 'V', 'U', 'T', 'M', 'I', 'R', 'B', 'F', 'P', 'A'] as const).includes(value as AtomIsotope)
120
120
  }
121
121
 
122
122
  /**
@@ -158,6 +158,14 @@ export function isFuseIsotope(value: unknown): value is 'F' {
158
158
  return value === 'F'
159
159
  }
160
160
 
161
+ export function isPeerIsotope(value: unknown): value is 'P' {
162
+ return value === 'P'
163
+ }
164
+
165
+ export function isAppendIsotope(value: unknown): value is 'A' {
166
+ return value === 'A'
167
+ }
168
+
161
169
  /**
162
170
  * Exhaustive isotope handler with compile-time completeness
163
171
  */
@@ -173,6 +181,8 @@ export function handleIsotope<T>(
173
181
  readonly R: () => T
174
182
  readonly B: () => T
175
183
  readonly F: () => T
184
+ readonly P: () => T
185
+ readonly A: () => T
176
186
  }
177
187
  ): T {
178
188
  switch (isotope) {
@@ -185,6 +195,8 @@ export function handleIsotope<T>(
185
195
  case 'R': return handlers.R()
186
196
  case 'B': return handlers.B()
187
197
  case 'F': return handlers.F()
198
+ case 'P': return handlers.P()
199
+ case 'A': return handlers.A()
188
200
  default: return assertNever(isotope)
189
201
  }
190
202
  }
@@ -378,11 +390,10 @@ export function isCellSlug(value: unknown): value is CellSlug {
378
390
  }
379
391
 
380
392
  /**
381
- * Batch ID validation (UUID format)
393
+ * Batch ID validation (64-char hex string, matching JS SDK)
382
394
  */
383
395
  export function isBatchId(value: unknown): value is BatchId {
384
- return typeof value === 'string' &&
385
- /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)
396
+ return typeof value === 'string' && /^[a-f0-9]{64}$/i.test(value)
386
397
  }
387
398
 
388
399
  // =============================================================================
@@ -594,6 +605,8 @@ export const Guards = {
594
605
  rule: isRuleIsotope,
595
606
  buffer: isBufferIsotope,
596
607
  fuse: isFuseIsotope,
608
+ peer: isPeerIsotope,
609
+ append: isAppendIsotope,
597
610
  handle: handleIsotope
598
611
  },
599
612
 
@@ -172,8 +172,8 @@ export interface AtomMetaData extends MetaData {
172
172
  export interface AtomParams {
173
173
  position?: string | null
174
174
  walletAddress?: WalletAddress | null
175
- isotope?: AtomIsotope
176
- token?: TokenSlug | string
175
+ isotope?: AtomIsotope | null
176
+ token?: TokenSlug | string | null
177
177
  value?: string | number | null
178
178
  batchId?: BatchId | string | null
179
179
  metaType?: MetaType | string | null
@@ -182,7 +182,7 @@ export interface AtomParams {
182
182
  otsFragment?: string | null
183
183
  index?: number | null
184
184
  createdAt?: string | null
185
- version?: number | null
185
+ version?: string | number | null | undefined
186
186
  }
187
187
 
188
188
  export interface WalletParams {