@wishknish/knishio-client-ts 0.7.0 → 0.7.2
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/index.cjs +235 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1833 -0
- package/dist/index.d.ts +1833 -0
- package/dist/index.iife.js +238 -181
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +235 -194
- package/dist/index.js.map +1 -1
- package/package.json +13 -10
- package/src/KnishIOClient.ts +183 -231
- package/src/core/Atom.ts +1 -1
- package/src/core/Molecule.ts +0 -1
- package/src/core/Wallet.ts +71 -8
- package/src/libraries/CheckMolecule.ts +3 -3
- package/src/libraries/GraphQLClient.ts +61 -23
- package/src/libraries/array.ts +2 -2
- package/src/libraries/crypto.ts +28 -25
- package/src/libraries/strings.ts +3 -3
- package/src/mutation/MutationProposeMolecule.ts +2 -1
- package/src/query/Query.ts +2 -1
- package/src/query/QueryAtom.ts +4 -3
- package/src/query/QueryBalance.ts +2 -1
- package/src/query/QueryBatch.ts +4 -3
- package/src/query/QueryContinuId.ts +4 -3
- package/src/query/QueryMetaType.ts +4 -3
- package/src/query/QueryMetaTypeViaAtom.ts +4 -3
- package/src/query/QueryWalletBundle.ts +2 -1
- package/src/query/QueryWalletList.ts +4 -3
- package/src/response/EnhancedResponse.ts +19 -24
- package/src/response/Response.ts +3 -3
- package/src/response/ResponseAtom.ts +1 -1
- package/src/response/ResponseAuthorizationGuest.ts +1 -1
- package/src/response/ResponseBalance.ts +1 -1
- package/src/response/ResponseContinuId.ts +1 -1
- package/src/response/ResponseMetaType.ts +1 -1
- package/src/response/ResponseMetaTypeViaAtom.ts +1 -1
- package/src/response/ResponsePolicy.ts +1 -1
- package/src/response/ResponseProposeMolecule.ts +4 -5
- package/src/response/ResponseQueryActiveSession.ts +1 -1
- package/src/response/ResponseQueryUserActivity.ts +1 -1
- package/src/response/ResponseRequestAuthorizationGuest.ts +1 -1
- package/src/response/ResponseTransferTokens.ts +1 -1
- package/src/response/ResponseWalletBundle.ts +1 -1
- package/src/response/ResponseWalletList.ts +1 -1
- package/src/types/graphql.ts +8 -0
- package/src/types/index.ts +2 -7
- package/src/types/response.ts +12 -7
package/src/KnishIOClient.ts
CHANGED
|
@@ -59,10 +59,8 @@ import Mutation from '@/mutation/Mutation'
|
|
|
59
59
|
import Response from '@/response/Response'
|
|
60
60
|
|
|
61
61
|
// 2025 TypeScript: Zod validation integration
|
|
62
|
-
import {
|
|
63
|
-
validateClientConfig
|
|
64
|
-
validateTransferParams,
|
|
65
|
-
type ValidationResult
|
|
62
|
+
import {
|
|
63
|
+
validateClientConfig
|
|
66
64
|
} from '@/validation/ValidationService'
|
|
67
65
|
|
|
68
66
|
// Enhanced configuration validation (Phase 2)
|
|
@@ -111,7 +109,8 @@ import {
|
|
|
111
109
|
CodeException,
|
|
112
110
|
UnauthenticatedException,
|
|
113
111
|
TransferBalanceException,
|
|
114
|
-
WalletShadowException
|
|
112
|
+
WalletShadowException,
|
|
113
|
+
StackableUnitAmountException
|
|
115
114
|
} from '@/exception'
|
|
116
115
|
|
|
117
116
|
// Type imports
|
|
@@ -135,7 +134,7 @@ export default class KnishIOClient {
|
|
|
135
134
|
private $__cellSlug: string | null = null
|
|
136
135
|
private $__encrypt: boolean = false
|
|
137
136
|
private $__uris: string[] = []
|
|
138
|
-
private $__client
|
|
137
|
+
private $__client!: GraphQLClient
|
|
139
138
|
private $__serverSdkVersion: number = 3
|
|
140
139
|
private $__logging: boolean = false
|
|
141
140
|
private $__authTokenObjects: Record<string, AuthToken | null> = {}
|
|
@@ -193,10 +192,10 @@ export default class KnishIOClient {
|
|
|
193
192
|
} = validatedConfig
|
|
194
193
|
|
|
195
194
|
this.initialize({
|
|
196
|
-
uri,
|
|
197
|
-
cellSlug,
|
|
198
|
-
socket,
|
|
199
|
-
client,
|
|
195
|
+
uri: uri as string | string[],
|
|
196
|
+
cellSlug: cellSlug as string | null,
|
|
197
|
+
socket: socket as { socketUri: string | null; appKey?: string } | null,
|
|
198
|
+
client: client as GraphQLClient | null,
|
|
200
199
|
serverSdkVersion,
|
|
201
200
|
logging
|
|
202
201
|
})
|
|
@@ -253,8 +252,11 @@ export default class KnishIOClient {
|
|
|
253
252
|
* Get random uri from specified this.$__uris
|
|
254
253
|
*/
|
|
255
254
|
getRandomUri(): string {
|
|
255
|
+
if (this.$__uris.length === 0) {
|
|
256
|
+
throw new Error('No URIs configured')
|
|
257
|
+
}
|
|
256
258
|
const rand = Math.floor(Math.random() * this.$__uris.length)
|
|
257
|
-
return this.$__uris[rand]
|
|
259
|
+
return this.$__uris[rand]!
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
/**
|
|
@@ -445,19 +447,20 @@ export default class KnishIOClient {
|
|
|
445
447
|
/**
|
|
446
448
|
* Creates a new molecule mutation
|
|
447
449
|
*/
|
|
448
|
-
async createMoleculeMutation({
|
|
450
|
+
async createMoleculeMutation<T extends Mutation>({
|
|
449
451
|
mutationClass,
|
|
450
452
|
molecule = null
|
|
451
453
|
}: {
|
|
452
|
-
mutationClass:
|
|
454
|
+
mutationClass: new (client: GraphQLClient, knishIOClient: KnishIOClient, molecule: Molecule) => T
|
|
453
455
|
molecule?: Molecule | null
|
|
454
|
-
}): Promise<
|
|
456
|
+
}): Promise<T> {
|
|
455
457
|
this.log('info', `KnishIOClient::createMoleculeMutation() - Creating a new ${mutationClass.name} query...`)
|
|
456
458
|
|
|
457
459
|
// If you don't supply the molecule, we'll generate one for you
|
|
458
460
|
const _molecule = molecule || await this.createMolecule({})
|
|
459
461
|
|
|
460
|
-
|
|
462
|
+
// Pass molecule to constructor for MutationProposeMolecule subclasses
|
|
463
|
+
const mutation = new mutationClass(this.client(), this, _molecule)
|
|
461
464
|
|
|
462
465
|
if (!(mutation instanceof Mutation)) {
|
|
463
466
|
throw new CodeException(`${this.constructor.name}::createMoleculeMutation() - This method only accepts Mutation subclasses!`)
|
|
@@ -521,101 +524,109 @@ export default class KnishIOClient {
|
|
|
521
524
|
|
|
522
525
|
/**
|
|
523
526
|
* Transfer tokens between wallets
|
|
524
|
-
*
|
|
527
|
+
* Matches JavaScript SDK transferToken implementation exactly
|
|
525
528
|
*/
|
|
526
|
-
async transferToken(
|
|
529
|
+
async transferToken({
|
|
530
|
+
bundleHash,
|
|
531
|
+
token,
|
|
532
|
+
amount = null,
|
|
533
|
+
units = [],
|
|
534
|
+
batchId = null,
|
|
535
|
+
sourceWallet = null
|
|
536
|
+
}: {
|
|
527
537
|
bundleHash: string
|
|
528
538
|
token: string
|
|
529
539
|
amount?: number | null
|
|
530
540
|
units?: string[]
|
|
531
541
|
batchId?: string | null
|
|
532
542
|
sourceWallet?: Wallet | null
|
|
533
|
-
}): Promise<
|
|
534
|
-
// 2025 Pattern: Validate parameters with Zod
|
|
535
|
-
const transferParams = {
|
|
536
|
-
recipient: params.bundleHash,
|
|
537
|
-
amount: params.amount || 0,
|
|
538
|
-
token: params.token
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
const validationResult = validateTransferParams(transferParams)
|
|
542
|
-
|
|
543
|
-
if (!validationResult.success) {
|
|
544
|
-
return {
|
|
545
|
-
success: false,
|
|
546
|
-
error: {
|
|
547
|
-
code: 'VALIDATION_ERROR',
|
|
548
|
-
message: 'Invalid transfer parameters',
|
|
549
|
-
details: validationResult.error.details,
|
|
550
|
-
context: 'transferToken'
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// Use validated parameters
|
|
556
|
-
const validatedParams = validationResult.data
|
|
557
|
-
let {
|
|
558
|
-
bundleHash,
|
|
559
|
-
token,
|
|
560
|
-
amount = null,
|
|
561
|
-
units = [],
|
|
562
|
-
batchId = null,
|
|
563
|
-
sourceWallet = null
|
|
564
|
-
} = params
|
|
543
|
+
}): Promise<Response | null> {
|
|
565
544
|
// Calculate amount & set meta key
|
|
566
545
|
if (units.length > 0) {
|
|
567
546
|
// Can't move stackable units AND provide amount
|
|
568
|
-
if (amount && amount > 0) {
|
|
569
|
-
throw new
|
|
547
|
+
if (amount !== null && amount > 0) {
|
|
548
|
+
throw new StackableUnitAmountException()
|
|
570
549
|
}
|
|
550
|
+
|
|
571
551
|
amount = units.length
|
|
572
552
|
}
|
|
573
553
|
|
|
574
|
-
//
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
batchId
|
|
579
|
-
})
|
|
554
|
+
// Ensure amount is set
|
|
555
|
+
if (amount === null) {
|
|
556
|
+
amount = 0
|
|
557
|
+
}
|
|
580
558
|
|
|
581
|
-
// Get source wallet
|
|
582
|
-
if (
|
|
583
|
-
sourceWallet = await this.
|
|
559
|
+
// Get a source wallet
|
|
560
|
+
if (sourceWallet === null) {
|
|
561
|
+
sourceWallet = await this.querySourceWallet({
|
|
562
|
+
token,
|
|
563
|
+
amount
|
|
564
|
+
})
|
|
584
565
|
}
|
|
585
566
|
|
|
586
|
-
//
|
|
587
|
-
if (
|
|
567
|
+
// Do you have enough tokens?
|
|
568
|
+
if (sourceWallet === null || Decimal.cmp(sourceWallet.balance, amount) < 0) {
|
|
588
569
|
throw new TransferBalanceException()
|
|
589
570
|
}
|
|
590
571
|
|
|
591
|
-
//
|
|
572
|
+
// Attempt to get the recipient's wallet
|
|
573
|
+
const recipientWallet = Wallet.create({
|
|
574
|
+
bundle: bundleHash,
|
|
575
|
+
token
|
|
576
|
+
})
|
|
577
|
+
|
|
578
|
+
// Compute the batch ID for the recipient (typically used by stackable tokens)
|
|
579
|
+
if (batchId !== null) {
|
|
580
|
+
recipientWallet.batchId = batchId
|
|
581
|
+
} else {
|
|
582
|
+
recipientWallet.initBatchId({
|
|
583
|
+
sourceWallet
|
|
584
|
+
})
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Create a remainder from the source wallet
|
|
592
588
|
const remainderWallet = sourceWallet.createRemainder(this.getSecret())
|
|
593
589
|
|
|
590
|
+
// Token units splitting
|
|
591
|
+
sourceWallet.splitUnits(
|
|
592
|
+
units,
|
|
593
|
+
remainderWallet,
|
|
594
|
+
recipientWallet
|
|
595
|
+
)
|
|
596
|
+
|
|
594
597
|
// Build the molecule itself
|
|
595
598
|
const molecule = await this.createMolecule({
|
|
596
599
|
sourceWallet,
|
|
597
600
|
remainderWallet
|
|
598
601
|
})
|
|
599
602
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
+
const query = await this.createMoleculeMutation({
|
|
604
|
+
mutationClass: MutationTransferTokens,
|
|
605
|
+
molecule
|
|
606
|
+
})
|
|
607
|
+
|
|
608
|
+
query.fillMolecule({
|
|
609
|
+
recipientWallet,
|
|
610
|
+
amount
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
return await this.executeQuery(query)
|
|
603
614
|
}
|
|
604
615
|
|
|
605
616
|
/**
|
|
606
617
|
* Request authorization token
|
|
607
618
|
*/
|
|
608
619
|
async requestAuthToken({
|
|
609
|
-
secret = null,
|
|
610
|
-
seed = null,
|
|
611
|
-
cellSlug = null,
|
|
612
|
-
encrypt = false
|
|
620
|
+
secret: _secret = null,
|
|
621
|
+
seed: _seed = null,
|
|
622
|
+
cellSlug: _cellSlug = null,
|
|
623
|
+
encrypt: _encrypt = false
|
|
613
624
|
}: {
|
|
614
625
|
secret?: string | null
|
|
615
626
|
seed?: string | null
|
|
616
627
|
cellSlug?: string | null
|
|
617
628
|
encrypt?: boolean
|
|
618
|
-
}): Promise<Response | null> {
|
|
629
|
+
} = {}): Promise<Response | null> {
|
|
619
630
|
// SDK versions 2 and below do not utilize an authorization token
|
|
620
631
|
if (this.$__serverSdkVersion < 3) {
|
|
621
632
|
this.log('warn', 'KnishIOClient::authorize() - Server SDK version does not require an authorization...')
|
|
@@ -743,7 +754,8 @@ export default class KnishIOClient {
|
|
|
743
754
|
const sourceWallet = response.payload() as Wallet | null
|
|
744
755
|
|
|
745
756
|
// Do you have enough tokens?
|
|
746
|
-
|
|
757
|
+
const amountNum = typeof amount === 'string' ? Number(amount) : amount
|
|
758
|
+
if (sourceWallet === null || Decimal.cmp(sourceWallet.balance || 0, amountNum) < 0) {
|
|
747
759
|
throw new TransferBalanceException()
|
|
748
760
|
}
|
|
749
761
|
|
|
@@ -785,7 +797,7 @@ export default class KnishIOClient {
|
|
|
785
797
|
*/
|
|
786
798
|
async queryBundle({
|
|
787
799
|
bundle = null,
|
|
788
|
-
fields = null,
|
|
800
|
+
fields: _fields = null,
|
|
789
801
|
raw = false
|
|
790
802
|
}: {
|
|
791
803
|
bundle?: BundleHash | string | string[] | null
|
|
@@ -832,7 +844,7 @@ export default class KnishIOClient {
|
|
|
832
844
|
key = null,
|
|
833
845
|
value = null,
|
|
834
846
|
latest = null,
|
|
835
|
-
fields = null,
|
|
847
|
+
fields: _fields = null,
|
|
836
848
|
filter = null,
|
|
837
849
|
queryArgs = null,
|
|
838
850
|
count = null,
|
|
@@ -1259,7 +1271,7 @@ export default class KnishIOClient {
|
|
|
1259
1271
|
amount = null,
|
|
1260
1272
|
meta = null,
|
|
1261
1273
|
batchId = null,
|
|
1262
|
-
units = null
|
|
1274
|
+
units: _units = null
|
|
1263
1275
|
}: {
|
|
1264
1276
|
token: TokenSlug | string
|
|
1265
1277
|
amount?: number | string | null
|
|
@@ -1269,26 +1281,26 @@ export default class KnishIOClient {
|
|
|
1269
1281
|
}): Promise<Response> {
|
|
1270
1282
|
this.log('info', `KnishIOClient::createToken() - Creating token ${token}...`)
|
|
1271
1283
|
|
|
1272
|
-
|
|
1284
|
+
// Create the molecule mutation
|
|
1285
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationCreateToken })
|
|
1273
1286
|
|
|
1274
|
-
//
|
|
1275
|
-
const
|
|
1287
|
+
// Create recipient wallet for new tokens
|
|
1288
|
+
const recipientWallet = new Wallet({
|
|
1289
|
+
secret: this.getSecret(),
|
|
1290
|
+
bundle: this.getBundle(),
|
|
1291
|
+
token: token.toUpperCase(),
|
|
1292
|
+
batchId: batchId as any
|
|
1293
|
+
})
|
|
1276
1294
|
|
|
1277
1295
|
// Initialize the create token mutation
|
|
1278
1296
|
await mutation.fillMolecule({
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
meta,
|
|
1283
|
-
batchId,
|
|
1284
|
-
units
|
|
1297
|
+
recipientWallet,
|
|
1298
|
+
amount: amount ?? 0,
|
|
1299
|
+
meta
|
|
1285
1300
|
})
|
|
1286
1301
|
|
|
1287
|
-
// Create the molecule mutation
|
|
1288
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1289
|
-
|
|
1290
1302
|
// Execute the mutation
|
|
1291
|
-
const response = await this.executeQuery(
|
|
1303
|
+
const response = await this.executeQuery(mutation)
|
|
1292
1304
|
|
|
1293
1305
|
if (!response) {
|
|
1294
1306
|
throw new CodeException('Token creation failed')
|
|
@@ -1304,7 +1316,7 @@ export default class KnishIOClient {
|
|
|
1304
1316
|
token,
|
|
1305
1317
|
to = null,
|
|
1306
1318
|
amount = null,
|
|
1307
|
-
units = null,
|
|
1319
|
+
units: _units = null,
|
|
1308
1320
|
meta = null,
|
|
1309
1321
|
batchId = null
|
|
1310
1322
|
}: {
|
|
@@ -1317,27 +1329,21 @@ export default class KnishIOClient {
|
|
|
1317
1329
|
}): Promise<Response> {
|
|
1318
1330
|
this.log('info', `KnishIOClient::requestTokens() - Requesting ${amount || 'units'} of ${token}...`)
|
|
1319
1331
|
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
// Get source wallet if needed
|
|
1323
|
-
const sourceWallet = await this.getSourceWallet()
|
|
1332
|
+
// Create the molecule mutation
|
|
1333
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationRequestTokens })
|
|
1324
1334
|
|
|
1325
1335
|
// Initialize the request tokens mutation
|
|
1326
1336
|
await mutation.fillMolecule({
|
|
1327
|
-
sourceWallet,
|
|
1328
1337
|
token: token.toUpperCase(),
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1338
|
+
amount: amount ?? 0,
|
|
1339
|
+
metaType: to || '',
|
|
1340
|
+
metaId: to || '',
|
|
1332
1341
|
meta,
|
|
1333
1342
|
batchId
|
|
1334
1343
|
})
|
|
1335
1344
|
|
|
1336
|
-
// Create the molecule mutation
|
|
1337
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1338
|
-
|
|
1339
1345
|
// Execute the mutation
|
|
1340
|
-
const response = await this.executeQuery(
|
|
1346
|
+
const response = await this.executeQuery(mutation)
|
|
1341
1347
|
|
|
1342
1348
|
if (!response) {
|
|
1343
1349
|
throw new CodeException('Token request failed')
|
|
@@ -1352,7 +1358,7 @@ export default class KnishIOClient {
|
|
|
1352
1358
|
async burnTokens({
|
|
1353
1359
|
token,
|
|
1354
1360
|
amount = null,
|
|
1355
|
-
units = null,
|
|
1361
|
+
units: _units = null,
|
|
1356
1362
|
sourceWallet = null
|
|
1357
1363
|
}: {
|
|
1358
1364
|
token: TokenSlug | string
|
|
@@ -1371,18 +1377,21 @@ export default class KnishIOClient {
|
|
|
1371
1377
|
}
|
|
1372
1378
|
|
|
1373
1379
|
// Create a transfer to null address (burn)
|
|
1374
|
-
const mutation = this.
|
|
1380
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationTransferTokens })
|
|
1381
|
+
|
|
1382
|
+
// Create recipient wallet for burn address
|
|
1383
|
+
const recipientWallet = new Wallet({
|
|
1384
|
+
secret: this.getSecret(),
|
|
1385
|
+
bundle: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
1386
|
+
token: token.toUpperCase()
|
|
1387
|
+
})
|
|
1375
1388
|
|
|
1376
1389
|
await mutation.fillMolecule({
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
token: token.toUpperCase(),
|
|
1380
|
-
amount,
|
|
1381
|
-
units
|
|
1390
|
+
recipientWallet,
|
|
1391
|
+
amount: amount ?? 0
|
|
1382
1392
|
})
|
|
1383
1393
|
|
|
1384
|
-
const
|
|
1385
|
-
const response = await this.executeQuery(moleculeMutation)
|
|
1394
|
+
const response = await this.executeQuery(mutation)
|
|
1386
1395
|
|
|
1387
1396
|
if (!response) {
|
|
1388
1397
|
throw new CodeException('Token burn failed')
|
|
@@ -1398,7 +1407,7 @@ export default class KnishIOClient {
|
|
|
1398
1407
|
token,
|
|
1399
1408
|
amount = null,
|
|
1400
1409
|
units = null,
|
|
1401
|
-
sourceWallet = null
|
|
1410
|
+
sourceWallet: _sourceWallet = null
|
|
1402
1411
|
}: {
|
|
1403
1412
|
token: TokenSlug | string
|
|
1404
1413
|
amount?: number | string | null
|
|
@@ -1419,11 +1428,11 @@ export default class KnishIOClient {
|
|
|
1419
1428
|
* Fuse token units
|
|
1420
1429
|
*/
|
|
1421
1430
|
async fuseToken({
|
|
1422
|
-
bundleHash,
|
|
1431
|
+
bundleHash: _bundleHash,
|
|
1423
1432
|
tokenSlug,
|
|
1424
|
-
newTokenUnit,
|
|
1425
|
-
fusedTokenUnitIds,
|
|
1426
|
-
sourceWallet = null
|
|
1433
|
+
newTokenUnit: _newTokenUnit,
|
|
1434
|
+
fusedTokenUnitIds: _fusedTokenUnitIds,
|
|
1435
|
+
sourceWallet: _sourceWallet = null
|
|
1427
1436
|
}: {
|
|
1428
1437
|
bundleHash: BundleHash | string
|
|
1429
1438
|
tokenSlug: TokenSlug | string
|
|
@@ -1452,22 +1461,21 @@ export default class KnishIOClient {
|
|
|
1452
1461
|
}): Promise<Response> {
|
|
1453
1462
|
this.log('info', `KnishIOClient::createWallet() - Creating wallet for token ${token}...`)
|
|
1454
1463
|
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
// Get source wallet
|
|
1458
|
-
const sourceWallet = await this.getSourceWallet()
|
|
1464
|
+
// Create the molecule mutation
|
|
1465
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationCreateWallet })
|
|
1459
1466
|
|
|
1460
|
-
//
|
|
1461
|
-
|
|
1462
|
-
|
|
1467
|
+
// Create new wallet for this token
|
|
1468
|
+
const newWallet = new Wallet({
|
|
1469
|
+
secret: this.getSecret(),
|
|
1470
|
+
bundle: this.getBundle(),
|
|
1463
1471
|
token: token.toUpperCase()
|
|
1464
1472
|
})
|
|
1465
1473
|
|
|
1466
|
-
//
|
|
1467
|
-
|
|
1474
|
+
// Initialize the create wallet mutation
|
|
1475
|
+
await mutation.fillMolecule(newWallet)
|
|
1468
1476
|
|
|
1469
1477
|
// Execute the mutation
|
|
1470
|
-
const response = await this.executeQuery(
|
|
1478
|
+
const response = await this.executeQuery(mutation)
|
|
1471
1479
|
|
|
1472
1480
|
if (!response) {
|
|
1473
1481
|
throw new CodeException('Wallet creation failed')
|
|
@@ -1482,7 +1490,7 @@ export default class KnishIOClient {
|
|
|
1482
1490
|
async claimShadowWallet({
|
|
1483
1491
|
token,
|
|
1484
1492
|
batchId = null,
|
|
1485
|
-
molecule = null
|
|
1493
|
+
molecule: _molecule = null
|
|
1486
1494
|
}: {
|
|
1487
1495
|
token: TokenSlug | string
|
|
1488
1496
|
batchId?: BatchId | string | null
|
|
@@ -1510,23 +1518,17 @@ export default class KnishIOClient {
|
|
|
1510
1518
|
throw new WalletShadowException('Wallet is not a shadow wallet')
|
|
1511
1519
|
}
|
|
1512
1520
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
// Get source wallet
|
|
1516
|
-
const sourceWallet = await this.getSourceWallet()
|
|
1521
|
+
// Create the molecule mutation
|
|
1522
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationClaimShadowWallet })
|
|
1517
1523
|
|
|
1518
1524
|
// Initialize the claim shadow wallet mutation
|
|
1519
1525
|
await mutation.fillMolecule({
|
|
1520
|
-
|
|
1521
|
-
token: token.toUpperCase(),
|
|
1526
|
+
token: token.toUpperCase() as TokenSlug,
|
|
1522
1527
|
batchId: shadowWallet.batchId
|
|
1523
1528
|
})
|
|
1524
1529
|
|
|
1525
|
-
// Create the molecule mutation
|
|
1526
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1527
|
-
|
|
1528
1530
|
// Execute the mutation
|
|
1529
|
-
const response = await this.executeQuery(
|
|
1531
|
+
const response = await this.executeQuery(mutation)
|
|
1530
1532
|
|
|
1531
1533
|
if (!response) {
|
|
1532
1534
|
throw new CodeException('Shadow wallet claim failed')
|
|
@@ -1592,25 +1594,19 @@ export default class KnishIOClient {
|
|
|
1592
1594
|
}): Promise<Response> {
|
|
1593
1595
|
this.log('info', `KnishIOClient::createMeta() - Creating metadata for ${metaType}:${metaId}...`)
|
|
1594
1596
|
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
// Get source wallet
|
|
1598
|
-
const sourceWallet = await this.getSourceWallet()
|
|
1597
|
+
// Create the molecule mutation
|
|
1598
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationCreateMeta })
|
|
1599
1599
|
|
|
1600
1600
|
// Initialize the create meta mutation
|
|
1601
1601
|
await mutation.fillMolecule({
|
|
1602
|
-
sourceWallet,
|
|
1603
1602
|
metaType: metaType.toUpperCase(),
|
|
1604
1603
|
metaId,
|
|
1605
1604
|
meta,
|
|
1606
1605
|
policy
|
|
1607
1606
|
})
|
|
1608
1607
|
|
|
1609
|
-
// Create the molecule mutation
|
|
1610
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1611
|
-
|
|
1612
1608
|
// Execute the mutation
|
|
1613
|
-
const response = await this.executeQuery(
|
|
1609
|
+
const response = await this.executeQuery(mutation)
|
|
1614
1610
|
|
|
1615
1611
|
if (!response) {
|
|
1616
1612
|
throw new CodeException('Metadata creation failed')
|
|
@@ -1635,25 +1631,19 @@ export default class KnishIOClient {
|
|
|
1635
1631
|
}): Promise<Response> {
|
|
1636
1632
|
this.log('info', `KnishIOClient::createRule() - Creating rule for ${metaType}:${metaId}...`)
|
|
1637
1633
|
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
// Get source wallet
|
|
1641
|
-
const sourceWallet = await this.getSourceWallet()
|
|
1634
|
+
// Create the molecule mutation
|
|
1635
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationCreateRule })
|
|
1642
1636
|
|
|
1643
1637
|
// Initialize the create rule mutation
|
|
1644
1638
|
await mutation.fillMolecule({
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
metaId,
|
|
1639
|
+
metaType: metaType.toUpperCase() as MetaType,
|
|
1640
|
+
metaId: metaId as MetaId,
|
|
1648
1641
|
rule,
|
|
1649
1642
|
policy
|
|
1650
1643
|
})
|
|
1651
1644
|
|
|
1652
|
-
// Create the molecule mutation
|
|
1653
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1654
|
-
|
|
1655
1645
|
// Execute the mutation
|
|
1656
|
-
const response = await this.executeQuery(
|
|
1646
|
+
const response = await this.executeQuery(mutation)
|
|
1657
1647
|
|
|
1658
1648
|
if (!response) {
|
|
1659
1649
|
throw new CodeException('Rule creation failed')
|
|
@@ -1699,24 +1689,18 @@ export default class KnishIOClient {
|
|
|
1699
1689
|
}): Promise<Response> {
|
|
1700
1690
|
this.log('info', `KnishIOClient::createIdentifier() - Creating identifier of type ${type}...`)
|
|
1701
1691
|
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
// Get source wallet
|
|
1705
|
-
const sourceWallet = await this.getSourceWallet()
|
|
1692
|
+
// Create the molecule mutation
|
|
1693
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationCreateIdentifier })
|
|
1706
1694
|
|
|
1707
1695
|
// Initialize the create identifier mutation
|
|
1708
1696
|
await mutation.fillMolecule({
|
|
1709
|
-
sourceWallet,
|
|
1710
1697
|
type,
|
|
1711
1698
|
contact,
|
|
1712
1699
|
code
|
|
1713
1700
|
})
|
|
1714
1701
|
|
|
1715
|
-
// Create the molecule mutation
|
|
1716
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1717
|
-
|
|
1718
1702
|
// Execute the mutation
|
|
1719
|
-
const response = await this.executeQuery(
|
|
1703
|
+
const response = await this.executeQuery(mutation)
|
|
1720
1704
|
|
|
1721
1705
|
if (!response) {
|
|
1722
1706
|
throw new CodeException('Identifier creation failed')
|
|
@@ -1737,24 +1721,16 @@ export default class KnishIOClient {
|
|
|
1737
1721
|
}): Promise<Response> {
|
|
1738
1722
|
this.log('info', `KnishIOClient::linkIdentifier() - Linking identifier of type ${type}...`)
|
|
1739
1723
|
|
|
1740
|
-
|
|
1724
|
+
// Create the mutation (extends Mutation directly, not MutationProposeMolecule)
|
|
1725
|
+
const mutation = this.createQuery(MutationLinkIdentifier)
|
|
1741
1726
|
|
|
1742
|
-
//
|
|
1743
|
-
const
|
|
1744
|
-
|
|
1745
|
-
// Initialize the link identifier mutation
|
|
1746
|
-
await mutation.fillMolecule({
|
|
1747
|
-
sourceWallet,
|
|
1727
|
+
// Execute with variables
|
|
1728
|
+
const response = await this.executeQuery(mutation, {
|
|
1729
|
+
bundle: this.getBundle(),
|
|
1748
1730
|
type,
|
|
1749
|
-
contact
|
|
1731
|
+
content: contact
|
|
1750
1732
|
})
|
|
1751
1733
|
|
|
1752
|
-
// Create the molecule mutation
|
|
1753
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1754
|
-
|
|
1755
|
-
// Execute the mutation
|
|
1756
|
-
const response = await this.executeQuery(moleculeMutation)
|
|
1757
|
-
|
|
1758
1734
|
if (!response) {
|
|
1759
1735
|
throw new CodeException('Identifier linking failed')
|
|
1760
1736
|
}
|
|
@@ -1792,15 +1768,12 @@ export default class KnishIOClient {
|
|
|
1792
1768
|
}): Promise<Response> {
|
|
1793
1769
|
this.log('info', `KnishIOClient::activeSession() - Declaring active session for ${metaType}:${metaId}...`)
|
|
1794
1770
|
|
|
1795
|
-
|
|
1771
|
+
// Create the mutation (extends Mutation directly, not MutationProposeMolecule)
|
|
1772
|
+
const mutation = this.createQuery(MutationActiveSession)
|
|
1796
1773
|
|
|
1797
|
-
//
|
|
1798
|
-
const
|
|
1799
|
-
|
|
1800
|
-
// Initialize the active session mutation
|
|
1801
|
-
await mutation.fillMolecule({
|
|
1802
|
-
sourceWallet,
|
|
1803
|
-
bundle,
|
|
1774
|
+
// Execute with variables
|
|
1775
|
+
const response = await this.executeQuery(mutation, {
|
|
1776
|
+
bundle: bundle || this.getBundle(),
|
|
1804
1777
|
metaType: metaType.toUpperCase(),
|
|
1805
1778
|
metaId,
|
|
1806
1779
|
ipAddress,
|
|
@@ -1811,12 +1784,6 @@ export default class KnishIOClient {
|
|
|
1811
1784
|
json
|
|
1812
1785
|
})
|
|
1813
1786
|
|
|
1814
|
-
// Create the molecule mutation
|
|
1815
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1816
|
-
|
|
1817
|
-
// Execute the mutation
|
|
1818
|
-
const response = await this.executeQuery(moleculeMutation)
|
|
1819
|
-
|
|
1820
1787
|
if (!response) {
|
|
1821
1788
|
throw new CodeException('Active session declaration failed')
|
|
1822
1789
|
}
|
|
@@ -1848,21 +1815,17 @@ export default class KnishIOClient {
|
|
|
1848
1815
|
})
|
|
1849
1816
|
}
|
|
1850
1817
|
|
|
1851
|
-
|
|
1818
|
+
// Create the molecule mutation
|
|
1819
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationDepositBufferToken })
|
|
1852
1820
|
|
|
1853
1821
|
// Initialize the deposit buffer token mutation
|
|
1854
1822
|
await mutation.fillMolecule({
|
|
1855
|
-
|
|
1856
|
-
tokenSlug: tokenSlug.toUpperCase(),
|
|
1857
|
-
amount,
|
|
1823
|
+
amount: typeof amount === 'string' ? Number(amount) : amount,
|
|
1858
1824
|
tradeRates
|
|
1859
1825
|
})
|
|
1860
1826
|
|
|
1861
|
-
// Create the molecule mutation
|
|
1862
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1863
|
-
|
|
1864
1827
|
// Execute the mutation
|
|
1865
|
-
const response = await this.executeQuery(
|
|
1828
|
+
const response = await this.executeQuery(mutation)
|
|
1866
1829
|
|
|
1867
1830
|
if (!response) {
|
|
1868
1831
|
throw new CodeException('Buffer token deposit failed')
|
|
@@ -1892,21 +1855,21 @@ export default class KnishIOClient {
|
|
|
1892
1855
|
sourceWallet = await this.getSourceWallet()
|
|
1893
1856
|
}
|
|
1894
1857
|
|
|
1895
|
-
|
|
1858
|
+
// Create the molecule mutation
|
|
1859
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationWithdrawBufferToken })
|
|
1896
1860
|
|
|
1897
1861
|
// Initialize the withdraw buffer token mutation
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1862
|
+
const recipients: Record<string, any> = {}
|
|
1863
|
+
recipients[this.getBundle()] = amount
|
|
1864
|
+
// Only include signingWallet if it exists (exactOptionalPropertyTypes compliance)
|
|
1865
|
+
const fillMoleculeParams: any = { recipients }
|
|
1866
|
+
if (signingWallet) {
|
|
1867
|
+
fillMoleculeParams.signingWallet = signingWallet
|
|
1868
|
+
}
|
|
1869
|
+
await mutation.fillMolecule(fillMoleculeParams)
|
|
1907
1870
|
|
|
1908
1871
|
// Execute the mutation
|
|
1909
|
-
const response = await this.executeQuery(
|
|
1872
|
+
const response = await this.executeQuery(mutation)
|
|
1910
1873
|
|
|
1911
1874
|
if (!response) {
|
|
1912
1875
|
throw new CodeException('Buffer token withdrawal failed')
|
|
@@ -1931,19 +1894,14 @@ export default class KnishIOClient {
|
|
|
1931
1894
|
} = {}): Promise<Response> {
|
|
1932
1895
|
this.log('info', 'KnishIOClient::requestGuestAuthToken() - Requesting guest auth token...')
|
|
1933
1896
|
|
|
1934
|
-
|
|
1897
|
+
// Create the mutation (extends Mutation directly, not MutationProposeMolecule)
|
|
1898
|
+
const mutation = this.createQuery(MutationRequestAuthorizationGuest)
|
|
1935
1899
|
|
|
1936
|
-
//
|
|
1937
|
-
await
|
|
1900
|
+
// Execute with variables
|
|
1901
|
+
const response = await this.executeQuery(mutation, {
|
|
1938
1902
|
cellSlug: cellSlug || this.getCellSlug()
|
|
1939
1903
|
})
|
|
1940
1904
|
|
|
1941
|
-
// Create the molecule mutation
|
|
1942
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1943
|
-
|
|
1944
|
-
// Execute the mutation
|
|
1945
|
-
const response = await this.executeQuery(moleculeMutation)
|
|
1946
|
-
|
|
1947
1905
|
if (!response) {
|
|
1948
1906
|
throw new CodeException('Guest auth token request failed')
|
|
1949
1907
|
}
|
|
@@ -1971,22 +1929,16 @@ export default class KnishIOClient {
|
|
|
1971
1929
|
// Set the secret
|
|
1972
1930
|
this.setSecret(secret)
|
|
1973
1931
|
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
// Get source wallet
|
|
1977
|
-
const sourceWallet = await this.getSourceWallet()
|
|
1932
|
+
// Create the molecule mutation
|
|
1933
|
+
const mutation = await this.createMoleculeMutation({ mutationClass: MutationRequestAuthorization })
|
|
1978
1934
|
|
|
1979
1935
|
// Initialize the profile auth mutation
|
|
1980
1936
|
await mutation.fillMolecule({
|
|
1981
|
-
|
|
1982
|
-
cellSlug: this.getCellSlug()
|
|
1937
|
+
meta: { encrypt: encrypt ? 'true' : 'false' }
|
|
1983
1938
|
})
|
|
1984
1939
|
|
|
1985
|
-
// Create the molecule mutation
|
|
1986
|
-
const moleculeMutation = await this.createMoleculeMutation({ mutationClass: mutation })
|
|
1987
|
-
|
|
1988
1940
|
// Execute the mutation
|
|
1989
|
-
const response = await this.executeQuery(
|
|
1941
|
+
const response = await this.executeQuery(mutation)
|
|
1990
1942
|
|
|
1991
1943
|
if (!response) {
|
|
1992
1944
|
throw new CodeException('Profile auth token request failed')
|