@opendatalabs/vana-sdk 0.1.0-alpha.793d5ba → 0.1.0-alpha.adc188d
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 +81 -4
- package/dist/index.browser.js +157 -59
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +157 -59
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +81 -4
- package/dist/index.node.d.ts +81 -4
- package/dist/index.node.js +157 -59
- package/dist/index.node.js.map +1 -1
- package/package.json +10 -2
package/dist/index.browser.d.ts
CHANGED
|
@@ -804,6 +804,7 @@ interface RelayerCallbacks {
|
|
|
804
804
|
/**
|
|
805
805
|
* Submit a file addition for relay
|
|
806
806
|
*
|
|
807
|
+
* @deprecated Use submitFileAdditionComplete for full support.
|
|
807
808
|
* @param url - The file URL to register
|
|
808
809
|
* @param userAddress - The user's address
|
|
809
810
|
* @returns Promise resolving to object with fileId and transactionHash
|
|
@@ -815,6 +816,7 @@ interface RelayerCallbacks {
|
|
|
815
816
|
/**
|
|
816
817
|
* Submit a file addition with permissions for relay
|
|
817
818
|
*
|
|
819
|
+
* @deprecated Use submitFileAdditionComplete for full support.
|
|
818
820
|
* @param url - The file URL to register
|
|
819
821
|
* @param userAddress - The user's address
|
|
820
822
|
* @param permissions - Array of encrypted permissions
|
|
@@ -827,6 +829,31 @@ interface RelayerCallbacks {
|
|
|
827
829
|
fileId: number;
|
|
828
830
|
transactionHash: Hash;
|
|
829
831
|
}>;
|
|
832
|
+
/**
|
|
833
|
+
* Submit a comprehensive file addition with optional schema and permissions for relay
|
|
834
|
+
*
|
|
835
|
+
* This is the preferred callback that supports all file addition scenarios.
|
|
836
|
+
* It can handle files with schemas, permissions, or both.
|
|
837
|
+
*
|
|
838
|
+
* @param params - Complete parameters for file addition
|
|
839
|
+
* @param params.url - The file URL to register
|
|
840
|
+
* @param params.userAddress - The user's address
|
|
841
|
+
* @param params.permissions - Array of encrypted permissions (empty array if none)
|
|
842
|
+
* @param params.schemaId - Schema ID for validation (0 if none)
|
|
843
|
+
* @returns Promise resolving to object with fileId and transactionHash
|
|
844
|
+
*/
|
|
845
|
+
submitFileAdditionComplete?: (params: {
|
|
846
|
+
url: string;
|
|
847
|
+
userAddress: Address;
|
|
848
|
+
permissions: Array<{
|
|
849
|
+
account: Address;
|
|
850
|
+
key: string;
|
|
851
|
+
}>;
|
|
852
|
+
schemaId: number;
|
|
853
|
+
}) => Promise<{
|
|
854
|
+
fileId: number;
|
|
855
|
+
transactionHash: Hash;
|
|
856
|
+
}>;
|
|
830
857
|
/**
|
|
831
858
|
* Store a grant file for relay (e.g., upload to IPFS)
|
|
832
859
|
*
|
|
@@ -1177,6 +1204,8 @@ interface PermissionParams {
|
|
|
1177
1204
|
nonce?: bigint;
|
|
1178
1205
|
/** Optional expiration timestamp. */
|
|
1179
1206
|
expiresAt?: number;
|
|
1207
|
+
/** Public key of the recipient to encrypt the data key for (required for upload with permissions). */
|
|
1208
|
+
publicKey?: string;
|
|
1180
1209
|
}
|
|
1181
1210
|
/**
|
|
1182
1211
|
* Result of the high-level upload operation.
|
|
@@ -5407,6 +5436,23 @@ declare class DataController {
|
|
|
5407
5436
|
fileId: number;
|
|
5408
5437
|
transactionHash: string;
|
|
5409
5438
|
}>;
|
|
5439
|
+
/**
|
|
5440
|
+
* Adds a file to the registry with permissions and schema.
|
|
5441
|
+
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
5442
|
+
*
|
|
5443
|
+
* @param url - The URL of the file to register
|
|
5444
|
+
* @param ownerAddress - The address of the file owner
|
|
5445
|
+
* @param permissions - Array of permissions to grant (account and encrypted key)
|
|
5446
|
+
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
5447
|
+
* @returns Promise resolving to object with fileId and transactionHash
|
|
5448
|
+
*/
|
|
5449
|
+
addFileWithPermissionsAndSchema(url: string, ownerAddress: Address, permissions?: Array<{
|
|
5450
|
+
account: Address;
|
|
5451
|
+
key: string;
|
|
5452
|
+
}>, schemaId?: number): Promise<{
|
|
5453
|
+
fileId: number;
|
|
5454
|
+
transactionHash: string;
|
|
5455
|
+
}>;
|
|
5410
5456
|
/**
|
|
5411
5457
|
* Adds a new schema to the DataRefinerRegistry.
|
|
5412
5458
|
*
|
|
@@ -9839,6 +9885,11 @@ declare const contractAbis: {
|
|
|
9839
9885
|
readonly internalType: "uint256";
|
|
9840
9886
|
readonly name: "schemaId";
|
|
9841
9887
|
readonly type: "uint256";
|
|
9888
|
+
}, {
|
|
9889
|
+
readonly indexed: false;
|
|
9890
|
+
readonly internalType: "string";
|
|
9891
|
+
readonly name: "schemaDefinitionUrl";
|
|
9892
|
+
readonly type: "string";
|
|
9842
9893
|
}, {
|
|
9843
9894
|
readonly indexed: false;
|
|
9844
9895
|
readonly internalType: "string";
|
|
@@ -9922,7 +9973,7 @@ declare const contractAbis: {
|
|
|
9922
9973
|
}, {
|
|
9923
9974
|
readonly indexed: false;
|
|
9924
9975
|
readonly internalType: "string";
|
|
9925
|
-
readonly name: "
|
|
9976
|
+
readonly name: "dialect";
|
|
9926
9977
|
readonly type: "string";
|
|
9927
9978
|
}, {
|
|
9928
9979
|
readonly indexed: false;
|
|
@@ -9996,6 +10047,32 @@ declare const contractAbis: {
|
|
|
9996
10047
|
readonly outputs: readonly [];
|
|
9997
10048
|
readonly stateMutability: "nonpayable";
|
|
9998
10049
|
readonly type: "function";
|
|
10050
|
+
}, {
|
|
10051
|
+
readonly inputs: readonly [{
|
|
10052
|
+
readonly internalType: "uint256";
|
|
10053
|
+
readonly name: "dlpId";
|
|
10054
|
+
readonly type: "uint256";
|
|
10055
|
+
}, {
|
|
10056
|
+
readonly internalType: "string";
|
|
10057
|
+
readonly name: "name";
|
|
10058
|
+
readonly type: "string";
|
|
10059
|
+
}, {
|
|
10060
|
+
readonly internalType: "string";
|
|
10061
|
+
readonly name: "schemaDefinitionUrl";
|
|
10062
|
+
readonly type: "string";
|
|
10063
|
+
}, {
|
|
10064
|
+
readonly internalType: "string";
|
|
10065
|
+
readonly name: "refinementInstructionUrl";
|
|
10066
|
+
readonly type: "string";
|
|
10067
|
+
}];
|
|
10068
|
+
readonly name: "addRefiner";
|
|
10069
|
+
readonly outputs: readonly [{
|
|
10070
|
+
readonly internalType: "uint256";
|
|
10071
|
+
readonly name: "";
|
|
10072
|
+
readonly type: "uint256";
|
|
10073
|
+
}];
|
|
10074
|
+
readonly stateMutability: "nonpayable";
|
|
10075
|
+
readonly type: "function";
|
|
9999
10076
|
}, {
|
|
10000
10077
|
readonly inputs: readonly [{
|
|
10001
10078
|
readonly internalType: "uint256";
|
|
@@ -10014,7 +10091,7 @@ declare const contractAbis: {
|
|
|
10014
10091
|
readonly name: "refinementInstructionUrl";
|
|
10015
10092
|
readonly type: "string";
|
|
10016
10093
|
}];
|
|
10017
|
-
readonly name: "
|
|
10094
|
+
readonly name: "addRefinerWithSchemaId";
|
|
10018
10095
|
readonly outputs: readonly [{
|
|
10019
10096
|
readonly internalType: "uint256";
|
|
10020
10097
|
readonly name: "";
|
|
@@ -10029,7 +10106,7 @@ declare const contractAbis: {
|
|
|
10029
10106
|
readonly type: "string";
|
|
10030
10107
|
}, {
|
|
10031
10108
|
readonly internalType: "string";
|
|
10032
|
-
readonly name: "
|
|
10109
|
+
readonly name: "dialect";
|
|
10033
10110
|
readonly type: "string";
|
|
10034
10111
|
}, {
|
|
10035
10112
|
readonly internalType: "string";
|
|
@@ -10305,7 +10382,7 @@ declare const contractAbis: {
|
|
|
10305
10382
|
readonly type: "string";
|
|
10306
10383
|
}, {
|
|
10307
10384
|
readonly internalType: "string";
|
|
10308
|
-
readonly name: "
|
|
10385
|
+
readonly name: "dialect";
|
|
10309
10386
|
readonly type: "string";
|
|
10310
10387
|
}, {
|
|
10311
10388
|
readonly internalType: "string";
|
package/dist/index.browser.js
CHANGED
|
@@ -7820,6 +7820,12 @@ var DataRefinerRegistryABI = [
|
|
|
7820
7820
|
name: "schemaId",
|
|
7821
7821
|
type: "uint256"
|
|
7822
7822
|
},
|
|
7823
|
+
{
|
|
7824
|
+
indexed: false,
|
|
7825
|
+
internalType: "string",
|
|
7826
|
+
name: "schemaDefinitionUrl",
|
|
7827
|
+
type: "string"
|
|
7828
|
+
},
|
|
7823
7829
|
{
|
|
7824
7830
|
indexed: false,
|
|
7825
7831
|
internalType: "string",
|
|
@@ -7923,7 +7929,7 @@ var DataRefinerRegistryABI = [
|
|
|
7923
7929
|
{
|
|
7924
7930
|
indexed: false,
|
|
7925
7931
|
internalType: "string",
|
|
7926
|
-
name: "
|
|
7932
|
+
name: "dialect",
|
|
7927
7933
|
type: "string"
|
|
7928
7934
|
},
|
|
7929
7935
|
{
|
|
@@ -8019,6 +8025,40 @@ var DataRefinerRegistryABI = [
|
|
|
8019
8025
|
stateMutability: "nonpayable",
|
|
8020
8026
|
type: "function"
|
|
8021
8027
|
},
|
|
8028
|
+
{
|
|
8029
|
+
inputs: [
|
|
8030
|
+
{
|
|
8031
|
+
internalType: "uint256",
|
|
8032
|
+
name: "dlpId",
|
|
8033
|
+
type: "uint256"
|
|
8034
|
+
},
|
|
8035
|
+
{
|
|
8036
|
+
internalType: "string",
|
|
8037
|
+
name: "name",
|
|
8038
|
+
type: "string"
|
|
8039
|
+
},
|
|
8040
|
+
{
|
|
8041
|
+
internalType: "string",
|
|
8042
|
+
name: "schemaDefinitionUrl",
|
|
8043
|
+
type: "string"
|
|
8044
|
+
},
|
|
8045
|
+
{
|
|
8046
|
+
internalType: "string",
|
|
8047
|
+
name: "refinementInstructionUrl",
|
|
8048
|
+
type: "string"
|
|
8049
|
+
}
|
|
8050
|
+
],
|
|
8051
|
+
name: "addRefiner",
|
|
8052
|
+
outputs: [
|
|
8053
|
+
{
|
|
8054
|
+
internalType: "uint256",
|
|
8055
|
+
name: "",
|
|
8056
|
+
type: "uint256"
|
|
8057
|
+
}
|
|
8058
|
+
],
|
|
8059
|
+
stateMutability: "nonpayable",
|
|
8060
|
+
type: "function"
|
|
8061
|
+
},
|
|
8022
8062
|
{
|
|
8023
8063
|
inputs: [
|
|
8024
8064
|
{
|
|
@@ -8042,7 +8082,7 @@ var DataRefinerRegistryABI = [
|
|
|
8042
8082
|
type: "string"
|
|
8043
8083
|
}
|
|
8044
8084
|
],
|
|
8045
|
-
name: "
|
|
8085
|
+
name: "addRefinerWithSchemaId",
|
|
8046
8086
|
outputs: [
|
|
8047
8087
|
{
|
|
8048
8088
|
internalType: "uint256",
|
|
@@ -8062,7 +8102,7 @@ var DataRefinerRegistryABI = [
|
|
|
8062
8102
|
},
|
|
8063
8103
|
{
|
|
8064
8104
|
internalType: "string",
|
|
8065
|
-
name: "
|
|
8105
|
+
name: "dialect",
|
|
8066
8106
|
type: "string"
|
|
8067
8107
|
},
|
|
8068
8108
|
{
|
|
@@ -8425,7 +8465,7 @@ var DataRefinerRegistryABI = [
|
|
|
8425
8465
|
},
|
|
8426
8466
|
{
|
|
8427
8467
|
internalType: "string",
|
|
8428
|
-
name: "
|
|
8468
|
+
name: "dialect",
|
|
8429
8469
|
type: "string"
|
|
8430
8470
|
},
|
|
8431
8471
|
{
|
|
@@ -35481,68 +35521,66 @@ var DataController = class {
|
|
|
35481
35521
|
filename,
|
|
35482
35522
|
providerName
|
|
35483
35523
|
);
|
|
35484
|
-
let blockchainResult;
|
|
35485
35524
|
const userAddress = await this.getUserAddress();
|
|
35486
|
-
|
|
35487
|
-
|
|
35488
|
-
|
|
35525
|
+
let encryptedPermissions = [];
|
|
35526
|
+
if (permissions.length > 0 && encrypt2) {
|
|
35527
|
+
const userEncryptionKey = await generateEncryptionKey(
|
|
35528
|
+
this.context.walletClient,
|
|
35529
|
+
DEFAULT_ENCRYPTION_SEED
|
|
35489
35530
|
);
|
|
35490
|
-
|
|
35491
|
-
|
|
35492
|
-
|
|
35493
|
-
|
|
35494
|
-
|
|
35495
|
-
|
|
35496
|
-
|
|
35497
|
-
let txHash;
|
|
35498
|
-
if (schemaId !== void 0) {
|
|
35499
|
-
txHash = await this.context.walletClient.writeContract({
|
|
35500
|
-
address: dataRegistryAddress,
|
|
35501
|
-
abi: dataRegistryAbi,
|
|
35502
|
-
functionName: "addFileWithSchema",
|
|
35503
|
-
args: [uploadResult.url, BigInt(schemaId)],
|
|
35504
|
-
account: this.context.walletClient.account || userAddress,
|
|
35505
|
-
chain: this.context.walletClient.chain || null
|
|
35506
|
-
});
|
|
35507
|
-
} else {
|
|
35508
|
-
txHash = await this.context.walletClient.writeContract({
|
|
35509
|
-
address: dataRegistryAddress,
|
|
35510
|
-
abi: dataRegistryAbi,
|
|
35511
|
-
functionName: "addFile",
|
|
35512
|
-
args: [uploadResult.url],
|
|
35513
|
-
account: this.context.walletClient.account || userAddress,
|
|
35514
|
-
chain: this.context.walletClient.chain || null
|
|
35515
|
-
});
|
|
35516
|
-
}
|
|
35517
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt({
|
|
35518
|
-
hash: txHash,
|
|
35519
|
-
timeout: 3e4
|
|
35520
|
-
// 30 seconds timeout
|
|
35521
|
-
});
|
|
35522
|
-
let fileId = 0;
|
|
35523
|
-
for (const log of receipt.logs) {
|
|
35524
|
-
try {
|
|
35525
|
-
const decoded = decodeEventLog({
|
|
35526
|
-
abi: dataRegistryAbi,
|
|
35527
|
-
data: log.data,
|
|
35528
|
-
topics: log.topics
|
|
35529
|
-
});
|
|
35530
|
-
if (decoded.eventName === "FileAdded") {
|
|
35531
|
-
fileId = Number(decoded.args.fileId);
|
|
35532
|
-
break;
|
|
35531
|
+
encryptedPermissions = await Promise.all(
|
|
35532
|
+
permissions.map(async (permission) => {
|
|
35533
|
+
const publicKey = permission.publicKey;
|
|
35534
|
+
if (!publicKey) {
|
|
35535
|
+
throw new Error(
|
|
35536
|
+
`Public key required for permission to ${permission.to}`
|
|
35537
|
+
);
|
|
35533
35538
|
}
|
|
35534
|
-
|
|
35539
|
+
const encryptedKey = await encryptWithWalletPublicKey(
|
|
35540
|
+
userEncryptionKey,
|
|
35541
|
+
publicKey,
|
|
35542
|
+
this.context.platform
|
|
35543
|
+
);
|
|
35544
|
+
return {
|
|
35545
|
+
account: permission.to,
|
|
35546
|
+
key: encryptedKey
|
|
35547
|
+
};
|
|
35548
|
+
})
|
|
35549
|
+
);
|
|
35550
|
+
}
|
|
35551
|
+
let result;
|
|
35552
|
+
if (this.context.relayerCallbacks?.submitFileAdditionComplete) {
|
|
35553
|
+
result = await this.context.relayerCallbacks.submitFileAdditionComplete(
|
|
35554
|
+
{
|
|
35555
|
+
url: uploadResult.url,
|
|
35556
|
+
userAddress,
|
|
35557
|
+
permissions: encryptedPermissions,
|
|
35558
|
+
schemaId: schemaId || 0
|
|
35535
35559
|
}
|
|
35560
|
+
);
|
|
35561
|
+
} else if (this.context.relayerCallbacks?.submitFileAddition) {
|
|
35562
|
+
const needsComplexRegistration = schemaId !== void 0 || encryptedPermissions.length > 0;
|
|
35563
|
+
if (needsComplexRegistration) {
|
|
35564
|
+
throw new Error(
|
|
35565
|
+
"The configured relay callback does not support schemas or permissions. Please update your relay server implementation to provide the `submitFileAdditionComplete` callback."
|
|
35566
|
+
);
|
|
35536
35567
|
}
|
|
35537
|
-
|
|
35538
|
-
|
|
35539
|
-
|
|
35540
|
-
|
|
35568
|
+
result = await this.context.relayerCallbacks.submitFileAddition(
|
|
35569
|
+
uploadResult.url,
|
|
35570
|
+
userAddress
|
|
35571
|
+
);
|
|
35572
|
+
} else {
|
|
35573
|
+
result = await this.addFileWithPermissionsAndSchema(
|
|
35574
|
+
uploadResult.url,
|
|
35575
|
+
userAddress,
|
|
35576
|
+
encryptedPermissions,
|
|
35577
|
+
schemaId || 0
|
|
35578
|
+
);
|
|
35541
35579
|
}
|
|
35542
35580
|
return {
|
|
35543
|
-
fileId:
|
|
35581
|
+
fileId: result.fileId,
|
|
35544
35582
|
url: uploadResult.url,
|
|
35545
|
-
transactionHash:
|
|
35583
|
+
transactionHash: result.transactionHash,
|
|
35546
35584
|
size: uploadResult.size,
|
|
35547
35585
|
isValid,
|
|
35548
35586
|
validationErrors: validationErrors.length > 0 ? validationErrors : void 0
|
|
@@ -36532,6 +36570,66 @@ var DataController = class {
|
|
|
36532
36570
|
);
|
|
36533
36571
|
}
|
|
36534
36572
|
}
|
|
36573
|
+
/**
|
|
36574
|
+
* Adds a file to the registry with permissions and schema.
|
|
36575
|
+
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
36576
|
+
*
|
|
36577
|
+
* @param url - The URL of the file to register
|
|
36578
|
+
* @param ownerAddress - The address of the file owner
|
|
36579
|
+
* @param permissions - Array of permissions to grant (account and encrypted key)
|
|
36580
|
+
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
36581
|
+
* @returns Promise resolving to object with fileId and transactionHash
|
|
36582
|
+
*/
|
|
36583
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
36584
|
+
try {
|
|
36585
|
+
const chainId = this.context.walletClient.chain?.id;
|
|
36586
|
+
if (!chainId) {
|
|
36587
|
+
throw new Error("Chain ID not available");
|
|
36588
|
+
}
|
|
36589
|
+
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
36590
|
+
const dataRegistryAbi = getAbi("DataRegistry");
|
|
36591
|
+
const txHash = await this.context.walletClient.writeContract({
|
|
36592
|
+
address: dataRegistryAddress,
|
|
36593
|
+
abi: dataRegistryAbi,
|
|
36594
|
+
functionName: "addFileWithPermissionsAndSchema",
|
|
36595
|
+
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
36596
|
+
account: this.context.walletClient.account || ownerAddress,
|
|
36597
|
+
chain: this.context.walletClient.chain || null
|
|
36598
|
+
});
|
|
36599
|
+
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
36600
|
+
{
|
|
36601
|
+
hash: txHash,
|
|
36602
|
+
timeout: 3e4
|
|
36603
|
+
// 30 seconds timeout
|
|
36604
|
+
}
|
|
36605
|
+
);
|
|
36606
|
+
let fileId = 0;
|
|
36607
|
+
for (const log of receipt.logs) {
|
|
36608
|
+
try {
|
|
36609
|
+
const decoded = decodeEventLog({
|
|
36610
|
+
abi: dataRegistryAbi,
|
|
36611
|
+
data: log.data,
|
|
36612
|
+
topics: log.topics
|
|
36613
|
+
});
|
|
36614
|
+
if (decoded.eventName === "FileAdded") {
|
|
36615
|
+
fileId = Number(decoded.args.fileId);
|
|
36616
|
+
break;
|
|
36617
|
+
}
|
|
36618
|
+
} catch {
|
|
36619
|
+
continue;
|
|
36620
|
+
}
|
|
36621
|
+
}
|
|
36622
|
+
return {
|
|
36623
|
+
fileId,
|
|
36624
|
+
transactionHash: txHash
|
|
36625
|
+
};
|
|
36626
|
+
} catch (error) {
|
|
36627
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
36628
|
+
throw new Error(
|
|
36629
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
36630
|
+
);
|
|
36631
|
+
}
|
|
36632
|
+
}
|
|
36535
36633
|
/**
|
|
36536
36634
|
* Adds a new schema to the DataRefinerRegistry.
|
|
36537
36635
|
*
|
|
@@ -36686,7 +36784,7 @@ var DataController = class {
|
|
|
36686
36784
|
const txHash = await this.context.walletClient.writeContract({
|
|
36687
36785
|
address: dataRefinerRegistryAddress,
|
|
36688
36786
|
abi: dataRefinerRegistryAbi,
|
|
36689
|
-
functionName: "
|
|
36787
|
+
functionName: "addRefinerWithSchemaId",
|
|
36690
36788
|
args: [
|
|
36691
36789
|
BigInt(params.dlpId),
|
|
36692
36790
|
params.name,
|