@opendatalabs/vana-sdk 0.1.0-alpha.b390e7f → 0.1.0-alpha.d6bebb0
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.browser.d.ts +683 -104
- package/dist/index.browser.js +188 -26
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +188 -26
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +710 -104
- package/dist/index.node.d.ts +710 -104
- package/dist/index.node.js +188 -26
- package/dist/index.node.js.map +1 -1
- package/dist/platform.browser.d.ts +35 -0
- package/dist/platform.node.d.cts +35 -0
- package/dist/platform.node.d.ts +35 -0
- package/package.json +1 -1
package/dist/index.node.cjs
CHANGED
|
@@ -34179,6 +34179,13 @@ var PermissionsController = class {
|
|
|
34179
34179
|
}
|
|
34180
34180
|
}
|
|
34181
34181
|
const nonce = await this.getUserNonce();
|
|
34182
|
+
if (params.granteeId === void 0 || params.granteeId === null) {
|
|
34183
|
+
throw new Error(
|
|
34184
|
+
"granteeId is required. Please select a grantee from the available list."
|
|
34185
|
+
);
|
|
34186
|
+
}
|
|
34187
|
+
const granteeId = params.granteeId;
|
|
34188
|
+
console.debug("\u{1F50D} Debug - Using provided granteeId:", granteeId);
|
|
34182
34189
|
console.debug(
|
|
34183
34190
|
"\u{1F50D} Debug - Final grant URL being passed to compose:",
|
|
34184
34191
|
grantUrl
|
|
@@ -34192,7 +34199,8 @@ var PermissionsController = class {
|
|
|
34192
34199
|
grantUrl,
|
|
34193
34200
|
serializedParameters: getGrantFileHash(grantFile),
|
|
34194
34201
|
// Hash as placeholder
|
|
34195
|
-
nonce
|
|
34202
|
+
nonce,
|
|
34203
|
+
granteeId
|
|
34196
34204
|
});
|
|
34197
34205
|
const signature = await this.signTypedData(typedData);
|
|
34198
34206
|
return await this.submitSignedGrant(typedData, signature);
|
|
@@ -34272,6 +34280,13 @@ var PermissionsController = class {
|
|
|
34272
34280
|
}
|
|
34273
34281
|
}
|
|
34274
34282
|
const nonce = await this.getUserNonce();
|
|
34283
|
+
if (params.granteeId === void 0 || params.granteeId === null) {
|
|
34284
|
+
throw new Error(
|
|
34285
|
+
"granteeId is required. Please select a grantee from the available list."
|
|
34286
|
+
);
|
|
34287
|
+
}
|
|
34288
|
+
const granteeId = params.granteeId;
|
|
34289
|
+
console.debug("\u{1F50D} Debug - Using provided granteeId:", granteeId);
|
|
34275
34290
|
console.debug(
|
|
34276
34291
|
"\u{1F50D} Debug - Final grant URL being passed to compose:",
|
|
34277
34292
|
grantUrl
|
|
@@ -34285,7 +34300,8 @@ var PermissionsController = class {
|
|
|
34285
34300
|
grantUrl,
|
|
34286
34301
|
serializedParameters: getGrantFileHash(grantFile),
|
|
34287
34302
|
// Hash as placeholder
|
|
34288
|
-
nonce
|
|
34303
|
+
nonce,
|
|
34304
|
+
granteeId
|
|
34289
34305
|
});
|
|
34290
34306
|
const signature = await this.signTypedData(typedData);
|
|
34291
34307
|
return { typedData, signature };
|
|
@@ -34481,12 +34497,14 @@ var PermissionsController = class {
|
|
|
34481
34497
|
const permissionInput = {
|
|
34482
34498
|
nonce: typedData.message.nonce,
|
|
34483
34499
|
grant: typedData.message.grant,
|
|
34484
|
-
fileIds: typedData.message.fileIds
|
|
34500
|
+
fileIds: typedData.message.fileIds,
|
|
34501
|
+
granteeId: typedData.message.granteeId
|
|
34485
34502
|
};
|
|
34486
34503
|
console.debug("\u{1F50D} Debug - Permission input being sent to contract:", {
|
|
34487
34504
|
nonce: permissionInput.nonce.toString(),
|
|
34488
34505
|
grant: permissionInput.grant,
|
|
34489
|
-
fileIds: permissionInput.fileIds.map((id) => id.toString())
|
|
34506
|
+
fileIds: permissionInput.fileIds.map((id) => id.toString()),
|
|
34507
|
+
granteeId: permissionInput.granteeId.toString()
|
|
34490
34508
|
});
|
|
34491
34509
|
console.debug("\u{1F50D} Debug - Grant field value:", typedData.message.grant);
|
|
34492
34510
|
console.debug(
|
|
@@ -34507,6 +34525,8 @@ var PermissionsController = class {
|
|
|
34507
34525
|
* Revokes a previously granted permission.
|
|
34508
34526
|
*
|
|
34509
34527
|
* @param params - Parameters for revoking the permission
|
|
34528
|
+
* @param params.permissionId - Permission identifier as bigint for contract compatibility.
|
|
34529
|
+
* Obtain from permission grants via `getUserPermissionGrantsOnChain()`.
|
|
34510
34530
|
* @returns Promise resolving to transaction hash
|
|
34511
34531
|
* @example
|
|
34512
34532
|
* ```typescript
|
|
@@ -34634,6 +34654,7 @@ var PermissionsController = class {
|
|
|
34634
34654
|
* @param params.grantUrl - URL where the grant details are stored
|
|
34635
34655
|
* @param params.serializedParameters - Serialized parameters for the operation
|
|
34636
34656
|
* @param params.nonce - Unique number to prevent replay attacks
|
|
34657
|
+
* @param params.granteeId - The ID of the grantee from the registry
|
|
34637
34658
|
* @returns Promise resolving to the typed data structure
|
|
34638
34659
|
*/
|
|
34639
34660
|
async composePermissionGrantMessage(params) {
|
|
@@ -34657,14 +34678,16 @@ var PermissionsController = class {
|
|
|
34657
34678
|
Permission: [
|
|
34658
34679
|
{ name: "nonce", type: "uint256" },
|
|
34659
34680
|
{ name: "grant", type: "string" },
|
|
34660
|
-
{ name: "fileIds", type: "uint256[]" }
|
|
34681
|
+
{ name: "fileIds", type: "uint256[]" },
|
|
34682
|
+
{ name: "granteeId", type: "uint256" }
|
|
34661
34683
|
]
|
|
34662
34684
|
},
|
|
34663
34685
|
primaryType: "Permission",
|
|
34664
34686
|
message: {
|
|
34665
34687
|
nonce: params.nonce,
|
|
34666
34688
|
grant: params.grantUrl,
|
|
34667
|
-
fileIds: params.files.map((fileId) => BigInt(fileId))
|
|
34689
|
+
fileIds: params.files.map((fileId) => BigInt(fileId)),
|
|
34690
|
+
granteeId: BigInt(params.granteeId)
|
|
34668
34691
|
}
|
|
34669
34692
|
};
|
|
34670
34693
|
}
|
|
@@ -35648,7 +35671,8 @@ var DataController = class {
|
|
|
35648
35671
|
schemaId,
|
|
35649
35672
|
permissions = [],
|
|
35650
35673
|
encrypt: encrypt3 = true,
|
|
35651
|
-
providerName
|
|
35674
|
+
providerName,
|
|
35675
|
+
owner
|
|
35652
35676
|
} = params;
|
|
35653
35677
|
try {
|
|
35654
35678
|
let blob;
|
|
@@ -35726,7 +35750,7 @@ var DataController = class {
|
|
|
35726
35750
|
filename,
|
|
35727
35751
|
providerName
|
|
35728
35752
|
);
|
|
35729
|
-
const userAddress = await this.getUserAddress();
|
|
35753
|
+
const userAddress = owner || await this.getUserAddress();
|
|
35730
35754
|
let encryptedPermissions = [];
|
|
35731
35755
|
if (permissions.length > 0 && encrypt3) {
|
|
35732
35756
|
const userEncryptionKey = await generateEncryptionKey(
|
|
@@ -35760,7 +35784,8 @@ var DataController = class {
|
|
|
35760
35784
|
url: uploadResult.url,
|
|
35761
35785
|
userAddress,
|
|
35762
35786
|
permissions: encryptedPermissions,
|
|
35763
|
-
schemaId: schemaId || 0
|
|
35787
|
+
schemaId: schemaId || 0,
|
|
35788
|
+
ownerAddress: owner
|
|
35764
35789
|
}
|
|
35765
35790
|
);
|
|
35766
35791
|
} else if (this.context.relayerCallbacks?.submitFileAddition) {
|
|
@@ -38021,6 +38046,39 @@ var ServerController = class {
|
|
|
38021
38046
|
this.context = context;
|
|
38022
38047
|
}
|
|
38023
38048
|
PERSONAL_SERVER_BASE_URL = process.env.NEXT_PUBLIC_PERSONAL_SERVER_BASE_URL;
|
|
38049
|
+
/**
|
|
38050
|
+
* Retrieves the cryptographic identity of a personal server.
|
|
38051
|
+
*
|
|
38052
|
+
* @remarks
|
|
38053
|
+
* This method fetches the public key and metadata for a personal server,
|
|
38054
|
+
* which is required for encrypting data before sharing with the server.
|
|
38055
|
+
* The identity includes the server's public key, address, and operational
|
|
38056
|
+
* details needed for secure communication. This information is cached
|
|
38057
|
+
* by identity servers to enable offline key retrieval.
|
|
38058
|
+
*
|
|
38059
|
+
* @param request - Parameters containing the user address
|
|
38060
|
+
* @param request.userAddress - The wallet address associated with the personal server
|
|
38061
|
+
* @returns Promise resolving to the server's identity information
|
|
38062
|
+
* @throws {NetworkError} When the identity service is unavailable or returns invalid data
|
|
38063
|
+
* @throws {PersonalServerError} When server identity cannot be retrieved
|
|
38064
|
+
* @example
|
|
38065
|
+
* ```typescript
|
|
38066
|
+
* // Get server identity for data encryption
|
|
38067
|
+
* const identity = await vana.server.getIdentity({
|
|
38068
|
+
* userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
38069
|
+
* });
|
|
38070
|
+
*
|
|
38071
|
+
* console.log(`Server: ${identity.name}`);
|
|
38072
|
+
* console.log(`Address: ${identity.address}`);
|
|
38073
|
+
* console.log(`Public Key: ${identity.public_key}`);
|
|
38074
|
+
*
|
|
38075
|
+
* // Use the public key for encrypting data to share with this server
|
|
38076
|
+
* const encryptedData = await encryptWithWalletPublicKey(
|
|
38077
|
+
* userData,
|
|
38078
|
+
* identity.public_key
|
|
38079
|
+
* );
|
|
38080
|
+
* ```
|
|
38081
|
+
*/
|
|
38024
38082
|
async getIdentity(request) {
|
|
38025
38083
|
try {
|
|
38026
38084
|
const response = await fetch(
|
|
@@ -38063,10 +38121,13 @@ var ServerController = class {
|
|
|
38063
38121
|
* This method submits a computation request to the personal server API.
|
|
38064
38122
|
* The response includes the operation ID.
|
|
38065
38123
|
* @param params - The request parameters object
|
|
38066
|
-
* @param params.permissionId - The permission ID authorizing this operation
|
|
38124
|
+
* @param params.permissionId - The permission ID authorizing this operation.
|
|
38125
|
+
* Obtain from granted permissions via `vana.permissions.getUserPermissionGrantsOnChain()`.
|
|
38067
38126
|
* @returns A Promise that resolves to an operation response with status and control URLs
|
|
38068
|
-
* @throws {PersonalServerError} When server request fails or parameters are invalid
|
|
38069
|
-
*
|
|
38127
|
+
* @throws {PersonalServerError} When server request fails or parameters are invalid.
|
|
38128
|
+
* Verify permissionId exists and is active for the target server.
|
|
38129
|
+
* @throws {NetworkError} When personal server API communication fails.
|
|
38130
|
+
* Check server URL configuration and network connectivity.
|
|
38070
38131
|
* @example
|
|
38071
38132
|
* ```typescript
|
|
38072
38133
|
* const response = await vana.server.createOperation({
|
|
@@ -38168,6 +38229,50 @@ var ServerController = class {
|
|
|
38168
38229
|
);
|
|
38169
38230
|
}
|
|
38170
38231
|
}
|
|
38232
|
+
/**
|
|
38233
|
+
* Cancels a running operation on the personal server.
|
|
38234
|
+
*
|
|
38235
|
+
* @remarks
|
|
38236
|
+
* This method attempts to cancel an operation that is currently processing
|
|
38237
|
+
* on the personal server. The operation must be in a cancellable state
|
|
38238
|
+
* (typically `starting` or `processing`). Not all operations support
|
|
38239
|
+
* cancellation, and cancellation may not be immediate. The server will
|
|
38240
|
+
* attempt to stop the operation and update its status to `canceled`.
|
|
38241
|
+
*
|
|
38242
|
+
* **Cancellation Behavior:**
|
|
38243
|
+
* - Operations in `succeeded` or `failed` states cannot be canceled
|
|
38244
|
+
* - Some long-running operations may take time to respond to cancellation
|
|
38245
|
+
* - Always verify cancellation by polling the operation status afterward
|
|
38246
|
+
*
|
|
38247
|
+
* @param operationId - The unique identifier of the operation to cancel,
|
|
38248
|
+
* obtained from `createOperation()` response
|
|
38249
|
+
* @returns Promise that resolves when the cancellation request is accepted
|
|
38250
|
+
* @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.
|
|
38251
|
+
* Check operation status - it may already be completed or failed.
|
|
38252
|
+
* @throws {NetworkError} When unable to reach the personal server API.
|
|
38253
|
+
* Verify server URL and network connectivity.
|
|
38254
|
+
* @example
|
|
38255
|
+
* ```typescript
|
|
38256
|
+
* // Start a long-running operation
|
|
38257
|
+
* const operation = await vana.server.createOperation({
|
|
38258
|
+
* permissionId: 123
|
|
38259
|
+
* });
|
|
38260
|
+
*
|
|
38261
|
+
* // Cancel if needed
|
|
38262
|
+
* try {
|
|
38263
|
+
* await vana.server.cancelOperation(operation.id);
|
|
38264
|
+
* console.log("Cancellation requested");
|
|
38265
|
+
*
|
|
38266
|
+
* // Verify cancellation
|
|
38267
|
+
* const status = await vana.server.getOperation(operation.id);
|
|
38268
|
+
* if (status.status === "canceled") {
|
|
38269
|
+
* console.log("Operation successfully canceled");
|
|
38270
|
+
* }
|
|
38271
|
+
* } catch (error) {
|
|
38272
|
+
* console.error("Failed to cancel:", error);
|
|
38273
|
+
* }
|
|
38274
|
+
* ```
|
|
38275
|
+
*/
|
|
38171
38276
|
async cancelOperation(operationId) {
|
|
38172
38277
|
try {
|
|
38173
38278
|
const response = await fetch(
|
|
@@ -38465,7 +38570,8 @@ var ProtocolController = class {
|
|
|
38465
38570
|
* are actually deployed on the current network.
|
|
38466
38571
|
* @param contractName - The name of the Vana contract to retrieve (use const assertion for full typing)
|
|
38467
38572
|
* @returns An object containing the contract's address and fully typed ABI
|
|
38468
|
-
* @throws {ContractNotFoundError} When the contract is not deployed on the current chain
|
|
38573
|
+
* @throws {ContractNotFoundError} When the contract is not deployed on the current chain.
|
|
38574
|
+
* Verify contract name spelling and check current network with `getChainId()`.
|
|
38469
38575
|
* @example
|
|
38470
38576
|
* ```typescript
|
|
38471
38577
|
* // Get contract info with full type inference
|
|
@@ -40415,15 +40521,35 @@ var VanaCore = class {
|
|
|
40415
40521
|
}
|
|
40416
40522
|
/**
|
|
40417
40523
|
* Encrypts data using the Vana protocol standard encryption.
|
|
40418
|
-
*
|
|
40524
|
+
*
|
|
40525
|
+
* @remarks
|
|
40526
|
+
* This method implements the Vana network's standard encryption protocol using
|
|
40527
|
+
* platform-appropriate cryptographic libraries. It automatically handles different
|
|
40528
|
+
* input types (string or Blob) and produces encrypted output suitable for secure
|
|
40529
|
+
* storage or transmission. The encryption is compatible with the network's
|
|
40530
|
+
* decryption protocols and can be decrypted by authorized parties.
|
|
40419
40531
|
*
|
|
40420
|
-
* @param data The data to encrypt (string or Blob)
|
|
40421
|
-
* @param key The key
|
|
40422
|
-
* @returns The encrypted data as Blob
|
|
40532
|
+
* @param data - The data to encrypt (string or Blob)
|
|
40533
|
+
* @param key - The encryption key (typically generated via `generateEncryptionKey`)
|
|
40534
|
+
* @returns The encrypted data as a Blob
|
|
40535
|
+
* @throws {Error} When encryption fails due to invalid key or data format
|
|
40423
40536
|
* @example
|
|
40424
40537
|
* ```typescript
|
|
40425
|
-
*
|
|
40426
|
-
*
|
|
40538
|
+
* import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
|
|
40539
|
+
*
|
|
40540
|
+
* // Generate encryption key from wallet signature
|
|
40541
|
+
* const encryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40542
|
+
*
|
|
40543
|
+
* // Encrypt string data
|
|
40544
|
+
* const sensitiveData = "User's private information";
|
|
40545
|
+
* const encrypted = await vana.encryptBlob(sensitiveData, encryptionKey);
|
|
40546
|
+
*
|
|
40547
|
+
* // Encrypt file data
|
|
40548
|
+
* const fileBlob = new Blob([fileContent], { type: 'application/json' });
|
|
40549
|
+
* const encryptedFile = await vana.encryptBlob(fileBlob, encryptionKey);
|
|
40550
|
+
*
|
|
40551
|
+
* // Store encrypted data safely
|
|
40552
|
+
* await storageProvider.upload(encrypted, 'encrypted-data.bin');
|
|
40427
40553
|
* ```
|
|
40428
40554
|
*/
|
|
40429
40555
|
async encryptBlob(data, key) {
|
|
@@ -40431,16 +40557,52 @@ var VanaCore = class {
|
|
|
40431
40557
|
}
|
|
40432
40558
|
/**
|
|
40433
40559
|
* Decrypts data that was encrypted using the Vana protocol.
|
|
40434
|
-
*
|
|
40560
|
+
*
|
|
40561
|
+
* @remarks
|
|
40562
|
+
* This method decrypts data that was previously encrypted using the Vana network's
|
|
40563
|
+
* standard encryption protocol. It requires the same wallet signature that was used
|
|
40564
|
+
* for encryption and automatically uses the appropriate platform adapter for
|
|
40565
|
+
* cryptographic operations. The decrypted output maintains the original data format.
|
|
40435
40566
|
*
|
|
40436
|
-
* @param encryptedData The encrypted data (string or Blob)
|
|
40437
|
-
* @param walletSignature The wallet signature
|
|
40438
|
-
* @returns The decrypted data as Blob
|
|
40567
|
+
* @param encryptedData - The encrypted data (string or Blob)
|
|
40568
|
+
* @param walletSignature - The wallet signature used as decryption key
|
|
40569
|
+
* @returns The decrypted data as a Blob
|
|
40570
|
+
* @throws {Error} When decryption fails due to invalid signature or corrupted data
|
|
40439
40571
|
* @example
|
|
40440
40572
|
* ```typescript
|
|
40441
|
-
*
|
|
40442
|
-
*
|
|
40443
|
-
*
|
|
40573
|
+
* import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
|
|
40574
|
+
*
|
|
40575
|
+
* // Retrieve encrypted data from storage
|
|
40576
|
+
* const encryptedBlob = await storageProvider.download('encrypted-data.bin');
|
|
40577
|
+
*
|
|
40578
|
+
* // Generate the same key used for encryption
|
|
40579
|
+
* const decryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40580
|
+
*
|
|
40581
|
+
* // Decrypt the data
|
|
40582
|
+
* const decrypted = await vana.decryptBlob(encryptedBlob, decryptionKey);
|
|
40583
|
+
*
|
|
40584
|
+
* // Convert back to original format
|
|
40585
|
+
* const originalText = await decrypted.text();
|
|
40586
|
+
* const originalJson = JSON.parse(originalText);
|
|
40587
|
+
*
|
|
40588
|
+
* console.log('Decrypted data:', originalJson);
|
|
40589
|
+
* ```
|
|
40590
|
+
*
|
|
40591
|
+
* @example
|
|
40592
|
+
* ```typescript
|
|
40593
|
+
* // Decrypt file downloaded from Vana network
|
|
40594
|
+
* const userFiles = await vana.data.getUserFiles();
|
|
40595
|
+
* const file = userFiles[0];
|
|
40596
|
+
*
|
|
40597
|
+
* // Download encrypted content
|
|
40598
|
+
* const encrypted = await fetch(file.url).then(r => r.blob());
|
|
40599
|
+
*
|
|
40600
|
+
* // Decrypt with user's key
|
|
40601
|
+
* const decryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40602
|
+
* const decrypted = await vana.decryptBlob(encrypted, decryptionKey);
|
|
40603
|
+
*
|
|
40604
|
+
* // Process original data
|
|
40605
|
+
* const fileContent = await decrypted.arrayBuffer();
|
|
40444
40606
|
* ```
|
|
40445
40607
|
*/
|
|
40446
40608
|
async decryptBlob(encryptedData, walletSignature) {
|