@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.browser.js
CHANGED
|
@@ -33803,6 +33803,13 @@ var PermissionsController = class {
|
|
|
33803
33803
|
}
|
|
33804
33804
|
}
|
|
33805
33805
|
const nonce = await this.getUserNonce();
|
|
33806
|
+
if (params.granteeId === void 0 || params.granteeId === null) {
|
|
33807
|
+
throw new Error(
|
|
33808
|
+
"granteeId is required. Please select a grantee from the available list."
|
|
33809
|
+
);
|
|
33810
|
+
}
|
|
33811
|
+
const granteeId = params.granteeId;
|
|
33812
|
+
console.debug("\u{1F50D} Debug - Using provided granteeId:", granteeId);
|
|
33806
33813
|
console.debug(
|
|
33807
33814
|
"\u{1F50D} Debug - Final grant URL being passed to compose:",
|
|
33808
33815
|
grantUrl
|
|
@@ -33816,7 +33823,8 @@ var PermissionsController = class {
|
|
|
33816
33823
|
grantUrl,
|
|
33817
33824
|
serializedParameters: getGrantFileHash(grantFile),
|
|
33818
33825
|
// Hash as placeholder
|
|
33819
|
-
nonce
|
|
33826
|
+
nonce,
|
|
33827
|
+
granteeId
|
|
33820
33828
|
});
|
|
33821
33829
|
const signature = await this.signTypedData(typedData);
|
|
33822
33830
|
return await this.submitSignedGrant(typedData, signature);
|
|
@@ -33896,6 +33904,13 @@ var PermissionsController = class {
|
|
|
33896
33904
|
}
|
|
33897
33905
|
}
|
|
33898
33906
|
const nonce = await this.getUserNonce();
|
|
33907
|
+
if (params.granteeId === void 0 || params.granteeId === null) {
|
|
33908
|
+
throw new Error(
|
|
33909
|
+
"granteeId is required. Please select a grantee from the available list."
|
|
33910
|
+
);
|
|
33911
|
+
}
|
|
33912
|
+
const granteeId = params.granteeId;
|
|
33913
|
+
console.debug("\u{1F50D} Debug - Using provided granteeId:", granteeId);
|
|
33899
33914
|
console.debug(
|
|
33900
33915
|
"\u{1F50D} Debug - Final grant URL being passed to compose:",
|
|
33901
33916
|
grantUrl
|
|
@@ -33909,7 +33924,8 @@ var PermissionsController = class {
|
|
|
33909
33924
|
grantUrl,
|
|
33910
33925
|
serializedParameters: getGrantFileHash(grantFile),
|
|
33911
33926
|
// Hash as placeholder
|
|
33912
|
-
nonce
|
|
33927
|
+
nonce,
|
|
33928
|
+
granteeId
|
|
33913
33929
|
});
|
|
33914
33930
|
const signature = await this.signTypedData(typedData);
|
|
33915
33931
|
return { typedData, signature };
|
|
@@ -34105,12 +34121,14 @@ var PermissionsController = class {
|
|
|
34105
34121
|
const permissionInput = {
|
|
34106
34122
|
nonce: typedData.message.nonce,
|
|
34107
34123
|
grant: typedData.message.grant,
|
|
34108
|
-
fileIds: typedData.message.fileIds
|
|
34124
|
+
fileIds: typedData.message.fileIds,
|
|
34125
|
+
granteeId: typedData.message.granteeId
|
|
34109
34126
|
};
|
|
34110
34127
|
console.debug("\u{1F50D} Debug - Permission input being sent to contract:", {
|
|
34111
34128
|
nonce: permissionInput.nonce.toString(),
|
|
34112
34129
|
grant: permissionInput.grant,
|
|
34113
|
-
fileIds: permissionInput.fileIds.map((id) => id.toString())
|
|
34130
|
+
fileIds: permissionInput.fileIds.map((id) => id.toString()),
|
|
34131
|
+
granteeId: permissionInput.granteeId.toString()
|
|
34114
34132
|
});
|
|
34115
34133
|
console.debug("\u{1F50D} Debug - Grant field value:", typedData.message.grant);
|
|
34116
34134
|
console.debug(
|
|
@@ -34131,6 +34149,8 @@ var PermissionsController = class {
|
|
|
34131
34149
|
* Revokes a previously granted permission.
|
|
34132
34150
|
*
|
|
34133
34151
|
* @param params - Parameters for revoking the permission
|
|
34152
|
+
* @param params.permissionId - Permission identifier as bigint for contract compatibility.
|
|
34153
|
+
* Obtain from permission grants via `getUserPermissionGrantsOnChain()`.
|
|
34134
34154
|
* @returns Promise resolving to transaction hash
|
|
34135
34155
|
* @example
|
|
34136
34156
|
* ```typescript
|
|
@@ -34258,6 +34278,7 @@ var PermissionsController = class {
|
|
|
34258
34278
|
* @param params.grantUrl - URL where the grant details are stored
|
|
34259
34279
|
* @param params.serializedParameters - Serialized parameters for the operation
|
|
34260
34280
|
* @param params.nonce - Unique number to prevent replay attacks
|
|
34281
|
+
* @param params.granteeId - The ID of the grantee from the registry
|
|
34261
34282
|
* @returns Promise resolving to the typed data structure
|
|
34262
34283
|
*/
|
|
34263
34284
|
async composePermissionGrantMessage(params) {
|
|
@@ -34281,14 +34302,16 @@ var PermissionsController = class {
|
|
|
34281
34302
|
Permission: [
|
|
34282
34303
|
{ name: "nonce", type: "uint256" },
|
|
34283
34304
|
{ name: "grant", type: "string" },
|
|
34284
|
-
{ name: "fileIds", type: "uint256[]" }
|
|
34305
|
+
{ name: "fileIds", type: "uint256[]" },
|
|
34306
|
+
{ name: "granteeId", type: "uint256" }
|
|
34285
34307
|
]
|
|
34286
34308
|
},
|
|
34287
34309
|
primaryType: "Permission",
|
|
34288
34310
|
message: {
|
|
34289
34311
|
nonce: params.nonce,
|
|
34290
34312
|
grant: params.grantUrl,
|
|
34291
|
-
fileIds: params.files.map((fileId) => BigInt(fileId))
|
|
34313
|
+
fileIds: params.files.map((fileId) => BigInt(fileId)),
|
|
34314
|
+
granteeId: BigInt(params.granteeId)
|
|
34292
34315
|
}
|
|
34293
34316
|
};
|
|
34294
34317
|
}
|
|
@@ -35272,7 +35295,8 @@ var DataController = class {
|
|
|
35272
35295
|
schemaId,
|
|
35273
35296
|
permissions = [],
|
|
35274
35297
|
encrypt: encrypt2 = true,
|
|
35275
|
-
providerName
|
|
35298
|
+
providerName,
|
|
35299
|
+
owner
|
|
35276
35300
|
} = params;
|
|
35277
35301
|
try {
|
|
35278
35302
|
let blob;
|
|
@@ -35350,7 +35374,7 @@ var DataController = class {
|
|
|
35350
35374
|
filename,
|
|
35351
35375
|
providerName
|
|
35352
35376
|
);
|
|
35353
|
-
const userAddress = await this.getUserAddress();
|
|
35377
|
+
const userAddress = owner || await this.getUserAddress();
|
|
35354
35378
|
let encryptedPermissions = [];
|
|
35355
35379
|
if (permissions.length > 0 && encrypt2) {
|
|
35356
35380
|
const userEncryptionKey = await generateEncryptionKey(
|
|
@@ -35384,7 +35408,8 @@ var DataController = class {
|
|
|
35384
35408
|
url: uploadResult.url,
|
|
35385
35409
|
userAddress,
|
|
35386
35410
|
permissions: encryptedPermissions,
|
|
35387
|
-
schemaId: schemaId || 0
|
|
35411
|
+
schemaId: schemaId || 0,
|
|
35412
|
+
ownerAddress: owner
|
|
35388
35413
|
}
|
|
35389
35414
|
);
|
|
35390
35415
|
} else if (this.context.relayerCallbacks?.submitFileAddition) {
|
|
@@ -37645,6 +37670,39 @@ var ServerController = class {
|
|
|
37645
37670
|
this.context = context;
|
|
37646
37671
|
__publicField(this, "PERSONAL_SERVER_BASE_URL", process.env.NEXT_PUBLIC_PERSONAL_SERVER_BASE_URL);
|
|
37647
37672
|
}
|
|
37673
|
+
/**
|
|
37674
|
+
* Retrieves the cryptographic identity of a personal server.
|
|
37675
|
+
*
|
|
37676
|
+
* @remarks
|
|
37677
|
+
* This method fetches the public key and metadata for a personal server,
|
|
37678
|
+
* which is required for encrypting data before sharing with the server.
|
|
37679
|
+
* The identity includes the server's public key, address, and operational
|
|
37680
|
+
* details needed for secure communication. This information is cached
|
|
37681
|
+
* by identity servers to enable offline key retrieval.
|
|
37682
|
+
*
|
|
37683
|
+
* @param request - Parameters containing the user address
|
|
37684
|
+
* @param request.userAddress - The wallet address associated with the personal server
|
|
37685
|
+
* @returns Promise resolving to the server's identity information
|
|
37686
|
+
* @throws {NetworkError} When the identity service is unavailable or returns invalid data
|
|
37687
|
+
* @throws {PersonalServerError} When server identity cannot be retrieved
|
|
37688
|
+
* @example
|
|
37689
|
+
* ```typescript
|
|
37690
|
+
* // Get server identity for data encryption
|
|
37691
|
+
* const identity = await vana.server.getIdentity({
|
|
37692
|
+
* userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
37693
|
+
* });
|
|
37694
|
+
*
|
|
37695
|
+
* console.log(`Server: ${identity.name}`);
|
|
37696
|
+
* console.log(`Address: ${identity.address}`);
|
|
37697
|
+
* console.log(`Public Key: ${identity.public_key}`);
|
|
37698
|
+
*
|
|
37699
|
+
* // Use the public key for encrypting data to share with this server
|
|
37700
|
+
* const encryptedData = await encryptWithWalletPublicKey(
|
|
37701
|
+
* userData,
|
|
37702
|
+
* identity.public_key
|
|
37703
|
+
* );
|
|
37704
|
+
* ```
|
|
37705
|
+
*/
|
|
37648
37706
|
async getIdentity(request) {
|
|
37649
37707
|
try {
|
|
37650
37708
|
const response = await fetch(
|
|
@@ -37687,10 +37745,13 @@ var ServerController = class {
|
|
|
37687
37745
|
* This method submits a computation request to the personal server API.
|
|
37688
37746
|
* The response includes the operation ID.
|
|
37689
37747
|
* @param params - The request parameters object
|
|
37690
|
-
* @param params.permissionId - The permission ID authorizing this operation
|
|
37748
|
+
* @param params.permissionId - The permission ID authorizing this operation.
|
|
37749
|
+
* Obtain from granted permissions via `vana.permissions.getUserPermissionGrantsOnChain()`.
|
|
37691
37750
|
* @returns A Promise that resolves to an operation response with status and control URLs
|
|
37692
|
-
* @throws {PersonalServerError} When server request fails or parameters are invalid
|
|
37693
|
-
*
|
|
37751
|
+
* @throws {PersonalServerError} When server request fails or parameters are invalid.
|
|
37752
|
+
* Verify permissionId exists and is active for the target server.
|
|
37753
|
+
* @throws {NetworkError} When personal server API communication fails.
|
|
37754
|
+
* Check server URL configuration and network connectivity.
|
|
37694
37755
|
* @example
|
|
37695
37756
|
* ```typescript
|
|
37696
37757
|
* const response = await vana.server.createOperation({
|
|
@@ -37792,6 +37853,50 @@ var ServerController = class {
|
|
|
37792
37853
|
);
|
|
37793
37854
|
}
|
|
37794
37855
|
}
|
|
37856
|
+
/**
|
|
37857
|
+
* Cancels a running operation on the personal server.
|
|
37858
|
+
*
|
|
37859
|
+
* @remarks
|
|
37860
|
+
* This method attempts to cancel an operation that is currently processing
|
|
37861
|
+
* on the personal server. The operation must be in a cancellable state
|
|
37862
|
+
* (typically `starting` or `processing`). Not all operations support
|
|
37863
|
+
* cancellation, and cancellation may not be immediate. The server will
|
|
37864
|
+
* attempt to stop the operation and update its status to `canceled`.
|
|
37865
|
+
*
|
|
37866
|
+
* **Cancellation Behavior:**
|
|
37867
|
+
* - Operations in `succeeded` or `failed` states cannot be canceled
|
|
37868
|
+
* - Some long-running operations may take time to respond to cancellation
|
|
37869
|
+
* - Always verify cancellation by polling the operation status afterward
|
|
37870
|
+
*
|
|
37871
|
+
* @param operationId - The unique identifier of the operation to cancel,
|
|
37872
|
+
* obtained from `createOperation()` response
|
|
37873
|
+
* @returns Promise that resolves when the cancellation request is accepted
|
|
37874
|
+
* @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.
|
|
37875
|
+
* Check operation status - it may already be completed or failed.
|
|
37876
|
+
* @throws {NetworkError} When unable to reach the personal server API.
|
|
37877
|
+
* Verify server URL and network connectivity.
|
|
37878
|
+
* @example
|
|
37879
|
+
* ```typescript
|
|
37880
|
+
* // Start a long-running operation
|
|
37881
|
+
* const operation = await vana.server.createOperation({
|
|
37882
|
+
* permissionId: 123
|
|
37883
|
+
* });
|
|
37884
|
+
*
|
|
37885
|
+
* // Cancel if needed
|
|
37886
|
+
* try {
|
|
37887
|
+
* await vana.server.cancelOperation(operation.id);
|
|
37888
|
+
* console.log("Cancellation requested");
|
|
37889
|
+
*
|
|
37890
|
+
* // Verify cancellation
|
|
37891
|
+
* const status = await vana.server.getOperation(operation.id);
|
|
37892
|
+
* if (status.status === "canceled") {
|
|
37893
|
+
* console.log("Operation successfully canceled");
|
|
37894
|
+
* }
|
|
37895
|
+
* } catch (error) {
|
|
37896
|
+
* console.error("Failed to cancel:", error);
|
|
37897
|
+
* }
|
|
37898
|
+
* ```
|
|
37899
|
+
*/
|
|
37795
37900
|
async cancelOperation(operationId) {
|
|
37796
37901
|
try {
|
|
37797
37902
|
const response = await fetch(
|
|
@@ -38095,7 +38200,8 @@ var ProtocolController = class {
|
|
|
38095
38200
|
* are actually deployed on the current network.
|
|
38096
38201
|
* @param contractName - The name of the Vana contract to retrieve (use const assertion for full typing)
|
|
38097
38202
|
* @returns An object containing the contract's address and fully typed ABI
|
|
38098
|
-
* @throws {ContractNotFoundError} When the contract is not deployed on the current chain
|
|
38203
|
+
* @throws {ContractNotFoundError} When the contract is not deployed on the current chain.
|
|
38204
|
+
* Verify contract name spelling and check current network with `getChainId()`.
|
|
38099
38205
|
* @example
|
|
38100
38206
|
* ```typescript
|
|
38101
38207
|
* // Get contract info with full type inference
|
|
@@ -40047,15 +40153,35 @@ var VanaCore = class {
|
|
|
40047
40153
|
}
|
|
40048
40154
|
/**
|
|
40049
40155
|
* Encrypts data using the Vana protocol standard encryption.
|
|
40050
|
-
*
|
|
40156
|
+
*
|
|
40157
|
+
* @remarks
|
|
40158
|
+
* This method implements the Vana network's standard encryption protocol using
|
|
40159
|
+
* platform-appropriate cryptographic libraries. It automatically handles different
|
|
40160
|
+
* input types (string or Blob) and produces encrypted output suitable for secure
|
|
40161
|
+
* storage or transmission. The encryption is compatible with the network's
|
|
40162
|
+
* decryption protocols and can be decrypted by authorized parties.
|
|
40051
40163
|
*
|
|
40052
|
-
* @param data The data to encrypt (string or Blob)
|
|
40053
|
-
* @param key The key
|
|
40054
|
-
* @returns The encrypted data as Blob
|
|
40164
|
+
* @param data - The data to encrypt (string or Blob)
|
|
40165
|
+
* @param key - The encryption key (typically generated via `generateEncryptionKey`)
|
|
40166
|
+
* @returns The encrypted data as a Blob
|
|
40167
|
+
* @throws {Error} When encryption fails due to invalid key or data format
|
|
40055
40168
|
* @example
|
|
40056
40169
|
* ```typescript
|
|
40057
|
-
*
|
|
40058
|
-
*
|
|
40170
|
+
* import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
|
|
40171
|
+
*
|
|
40172
|
+
* // Generate encryption key from wallet signature
|
|
40173
|
+
* const encryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40174
|
+
*
|
|
40175
|
+
* // Encrypt string data
|
|
40176
|
+
* const sensitiveData = "User's private information";
|
|
40177
|
+
* const encrypted = await vana.encryptBlob(sensitiveData, encryptionKey);
|
|
40178
|
+
*
|
|
40179
|
+
* // Encrypt file data
|
|
40180
|
+
* const fileBlob = new Blob([fileContent], { type: 'application/json' });
|
|
40181
|
+
* const encryptedFile = await vana.encryptBlob(fileBlob, encryptionKey);
|
|
40182
|
+
*
|
|
40183
|
+
* // Store encrypted data safely
|
|
40184
|
+
* await storageProvider.upload(encrypted, 'encrypted-data.bin');
|
|
40059
40185
|
* ```
|
|
40060
40186
|
*/
|
|
40061
40187
|
async encryptBlob(data, key) {
|
|
@@ -40063,16 +40189,52 @@ var VanaCore = class {
|
|
|
40063
40189
|
}
|
|
40064
40190
|
/**
|
|
40065
40191
|
* Decrypts data that was encrypted using the Vana protocol.
|
|
40066
|
-
*
|
|
40192
|
+
*
|
|
40193
|
+
* @remarks
|
|
40194
|
+
* This method decrypts data that was previously encrypted using the Vana network's
|
|
40195
|
+
* standard encryption protocol. It requires the same wallet signature that was used
|
|
40196
|
+
* for encryption and automatically uses the appropriate platform adapter for
|
|
40197
|
+
* cryptographic operations. The decrypted output maintains the original data format.
|
|
40067
40198
|
*
|
|
40068
|
-
* @param encryptedData The encrypted data (string or Blob)
|
|
40069
|
-
* @param walletSignature The wallet signature
|
|
40070
|
-
* @returns The decrypted data as Blob
|
|
40199
|
+
* @param encryptedData - The encrypted data (string or Blob)
|
|
40200
|
+
* @param walletSignature - The wallet signature used as decryption key
|
|
40201
|
+
* @returns The decrypted data as a Blob
|
|
40202
|
+
* @throws {Error} When decryption fails due to invalid signature or corrupted data
|
|
40071
40203
|
* @example
|
|
40072
40204
|
* ```typescript
|
|
40073
|
-
*
|
|
40074
|
-
*
|
|
40075
|
-
*
|
|
40205
|
+
* import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
|
|
40206
|
+
*
|
|
40207
|
+
* // Retrieve encrypted data from storage
|
|
40208
|
+
* const encryptedBlob = await storageProvider.download('encrypted-data.bin');
|
|
40209
|
+
*
|
|
40210
|
+
* // Generate the same key used for encryption
|
|
40211
|
+
* const decryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40212
|
+
*
|
|
40213
|
+
* // Decrypt the data
|
|
40214
|
+
* const decrypted = await vana.decryptBlob(encryptedBlob, decryptionKey);
|
|
40215
|
+
*
|
|
40216
|
+
* // Convert back to original format
|
|
40217
|
+
* const originalText = await decrypted.text();
|
|
40218
|
+
* const originalJson = JSON.parse(originalText);
|
|
40219
|
+
*
|
|
40220
|
+
* console.log('Decrypted data:', originalJson);
|
|
40221
|
+
* ```
|
|
40222
|
+
*
|
|
40223
|
+
* @example
|
|
40224
|
+
* ```typescript
|
|
40225
|
+
* // Decrypt file downloaded from Vana network
|
|
40226
|
+
* const userFiles = await vana.data.getUserFiles();
|
|
40227
|
+
* const file = userFiles[0];
|
|
40228
|
+
*
|
|
40229
|
+
* // Download encrypted content
|
|
40230
|
+
* const encrypted = await fetch(file.url).then(r => r.blob());
|
|
40231
|
+
*
|
|
40232
|
+
* // Decrypt with user's key
|
|
40233
|
+
* const decryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40234
|
+
* const decrypted = await vana.decryptBlob(encrypted, decryptionKey);
|
|
40235
|
+
*
|
|
40236
|
+
* // Process original data
|
|
40237
|
+
* const fileContent = await decrypted.arrayBuffer();
|
|
40076
40238
|
* ```
|
|
40077
40239
|
*/
|
|
40078
40240
|
async decryptBlob(encryptedData, walletSignature) {
|