@wishknish/knishio-client-ts 0.7.6 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishknish/knishio-client-ts",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "productName": "Knish.IO TypeScript SDK Client",
5
5
  "description": "TypeScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs with enhanced type safety.",
6
6
  "license": "GPL-3.0-or-later",
@@ -433,6 +433,28 @@ export default class KnishIOClient {
433
433
  secret = secret || this.getSecret()
434
434
  bundle = bundle || this.getBundle()
435
435
 
436
+ // For non-USER source wallets (V/B isotopes), capture the current USER
437
+ // ContinuID position BEFORE overwriting the client's remainder wallet.
438
+ // This position is needed by addContinuIdAtom() for previousPosition metadata.
439
+ let continuIdPosition: string | null = null
440
+ if (sourceWallet && sourceWallet.token !== 'USER') {
441
+ if (this.lastMoleculeQuery &&
442
+ this.getRemainderWallet() &&
443
+ this.getRemainderWallet()?.token === 'USER' &&
444
+ this.lastMoleculeQuery.response() &&
445
+ this.lastMoleculeQuery.response()?.success()
446
+ ) {
447
+ // Carry-forward: use last successful USER remainder wallet position
448
+ continuIdPosition = this.getRemainderWallet()?.position || null
449
+ this.log('info', `KnishIOClient::createMolecule() - Captured USER ContinuID position ${continuIdPosition?.substring(0, 16)}... for non-USER source wallet`)
450
+ } else {
451
+ // Query server for current ContinuID position
452
+ const userWallet = await this.getSourceWallet()
453
+ continuIdPosition = userWallet?.position || null
454
+ this.log('info', `KnishIOClient::createMolecule() - Queried USER ContinuID position ${continuIdPosition?.substring(0, 16)}... for non-USER source wallet`)
455
+ }
456
+ }
457
+
436
458
  // Sets the source wallet as the last remainder wallet (to maintain ContinuID)
437
459
  if (!sourceWallet &&
438
460
  this.lastMoleculeQuery &&
@@ -463,7 +485,8 @@ export default class KnishIOClient {
463
485
  sourceWallet,
464
486
  remainderWallet: this.getRemainderWallet()!,
465
487
  cellSlug: this.getCellSlug(),
466
- version: this.getServerSdkVersion()
488
+ version: this.getServerSdkVersion(),
489
+ continuIdPosition
467
490
  })
468
491
  }
469
492
 
@@ -1496,9 +1519,13 @@ export default class KnishIOClient {
1496
1519
  })
1497
1520
  }
1498
1521
 
1499
- // Create molecule with the source wallet (same pattern as transferToken)
1522
+ // Create remainder wallet from source (must be same token for V-isotope conservation)
1523
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret())
1524
+
1525
+ // Create molecule with the token-specific source and remainder wallets
1500
1526
  const molecule = await this.createMolecule({
1501
- sourceWallet
1527
+ sourceWallet,
1528
+ remainderWallet
1502
1529
  })
1503
1530
 
1504
1531
  // Create a transfer to null address (burn)
@@ -1955,8 +1982,20 @@ export default class KnishIOClient {
1955
1982
  })
1956
1983
  }
1957
1984
 
1985
+ // Create remainder wallet from source (must be same token)
1986
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret())
1987
+
1988
+ // Build the molecule with the token-specific source and remainder wallets
1989
+ const molecule = await this.createMolecule({
1990
+ sourceWallet,
1991
+ remainderWallet
1992
+ })
1993
+
1958
1994
  // Create the molecule mutation
1959
- const mutation = await this.createMoleculeMutation({ mutationClass: MutationDepositBufferToken })
1995
+ const mutation = await this.createMoleculeMutation({
1996
+ mutationClass: MutationDepositBufferToken,
1997
+ molecule
1998
+ })
1960
1999
 
1961
2000
  // Initialize the deposit buffer token mutation
1962
2001
  await mutation.fillMolecule({
@@ -78,6 +78,7 @@ export default class Molecule {
78
78
  public remainderWallet: Wallet | null
79
79
  public atoms: Atom[]
80
80
  public version: string | null | undefined
81
+ public continuIdPosition: string | null
81
82
  public parentHashes: string[]
82
83
  public local?: number
83
84
 
@@ -91,7 +92,8 @@ export default class Molecule {
91
92
  sourceWallet = null,
92
93
  remainderWallet = null,
93
94
  cellSlug = null,
94
- version = null
95
+ version = null,
96
+ continuIdPosition = null
95
97
  }: {
96
98
  secret?: string | null
97
99
  bundle?: string | null
@@ -99,6 +101,7 @@ export default class Molecule {
99
101
  remainderWallet?: Wallet | null
100
102
  cellSlug?: string | null
101
103
  version?: string | number | null
104
+ continuIdPosition?: string | null
102
105
  } = {}) {
103
106
  this.status = null
104
107
  this.molecularHash = null
@@ -107,6 +110,7 @@ export default class Molecule {
107
110
  this.secret = secret
108
111
  this.bundle = bundle
109
112
  this.sourceWallet = sourceWallet
113
+ this.continuIdPosition = continuIdPosition
110
114
  this.atoms = []
111
115
  this.parentHashes = []
112
116
 
@@ -209,8 +213,12 @@ export default class Molecule {
209
213
  // ContinuID metadata for chain integrity validation
210
214
  const continuIdMeta: Record<string, any> = {}
211
215
 
212
- // previousPosition: the source wallet's position being consumed
213
- if (this.sourceWallet && this.sourceWallet.position) {
216
+ // previousPosition: the current USER ContinuID position being consumed.
217
+ // For non-USER source wallets (V/B isotopes), use the explicitly passed
218
+ // continuIdPosition from createMolecule() instead of the TOKEN wallet position.
219
+ if (this.continuIdPosition) {
220
+ continuIdMeta.previousPosition = this.continuIdPosition
221
+ } else if (this.sourceWallet && this.sourceWallet.position) {
214
222
  continuIdMeta.previousPosition = this.sourceWallet.position
215
223
  }
216
224
 
@@ -661,13 +669,29 @@ export default class Molecule {
661
669
  throw new BalanceInsufficientException()
662
670
  }
663
671
 
664
- // Burn tokens by removing from source (matching JS SDK)
672
+ // Create burn address wallet (null bundle = token destruction)
673
+ const burnWallet = new Wallet({
674
+ bundle: '0000000000000000000000000000000000000000000000000000000000000000',
675
+ token: this.sourceWallet.token
676
+ })
677
+
678
+ // V-atom 1: Debit full balance from source
665
679
  this.addAtom(Atom.create({
666
680
  isotope: 'V',
667
681
  wallet: this.sourceWallet,
668
- value: -amount
682
+ value: -Number(this.sourceWallet.balance)
683
+ }))
684
+
685
+ // V-atom 2: Credit burn amount to burn address
686
+ this.addAtom(Atom.create({
687
+ isotope: 'V',
688
+ wallet: burnWallet,
689
+ value: amount,
690
+ metaType: 'walletBundle',
691
+ metaId: burnWallet.bundle!
669
692
  }))
670
- // Remainder atom (matching JS SDK)
693
+
694
+ // V-atom 3: Remainder back to source identity
671
695
  this.addAtom(Atom.create({
672
696
  isotope: 'V',
673
697
  wallet: this.remainderWallet!,