@eluvio/elv-client-js 3.1.94 → 3.1.95
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/ElvClient-min.js +15 -11
- package/dist/ElvClient-node-min.js +17 -13
- package/dist/ElvFrameClient-min.js +13 -9
- package/dist/ElvPermissionsClient-min.js +13 -9
- package/dist/src/AuthorizationClient.js +2248 -1990
- package/dist/src/ContentObjectVerification.js +164 -173
- package/dist/src/Crypto.js +376 -324
- package/dist/src/ElvClient.js +1214 -938
- package/dist/src/ElvWallet.js +119 -95
- package/dist/src/EthClient.js +1040 -896
- package/dist/src/FrameClient.js +331 -300
- package/dist/src/HttpClient.js +153 -147
- package/dist/src/Id.js +1 -3
- package/dist/src/PermissionsClient.js +1294 -1168
- package/dist/src/RemoteSigner.js +260 -200
- package/dist/src/UserProfileClient.js +1164 -1023
- package/dist/src/Utils.js +209 -177
- package/dist/src/client/ABRPublishing.js +895 -856
- package/dist/src/client/AccessGroups.js +1102 -959
- package/dist/src/client/ContentAccess.js +3718 -3425
- package/dist/src/client/ContentManagement.js +2252 -2068
- package/dist/src/client/Contracts.js +647 -563
- package/dist/src/client/Files.js +1886 -1757
- package/dist/src/client/NFT.js +126 -112
- package/dist/src/client/NTP.js +478 -422
- package/package.json +1 -1
- package/src/ElvClient.js +62 -1
- package/src/RemoteSigner.js +22 -18
- package/testScripts/Test.js +0 -19
- package/package-lock.json +0 -26979
package/package.json
CHANGED
package/src/ElvClient.js
CHANGED
|
@@ -694,6 +694,67 @@ class ElvClient {
|
|
|
694
694
|
return this.utils.FormatAddress(this.signer.address);
|
|
695
695
|
}
|
|
696
696
|
|
|
697
|
+
/*
|
|
698
|
+
TOKEN 211b PREFIX + BODY | aplsjcJf1HYcDDUuCdXcSZtU86nYK162YmYJeuqwMczEBJVkD5D5EvsBvVwYDRsf4hzDvBWMoe9piBpqx...
|
|
699
|
+
PREFIX 6b aplsjc | apl=plain s=ES256K jc=json-compressed
|
|
700
|
+
BODY 205b base58(SIGNATURE + PAYLOAD)
|
|
701
|
+
SIGNATURE + PAYLOAD 151b 151b * 138 / 100 + 1 = 209b (>= 205b)
|
|
702
|
+
SIGNATURE 66b ES256K_Di9Lu83mz4wMoehCEeQhKpJJ7ApmDZLumAa2Cge48F6EHYnbn8msATGGpjucScwimei1TWGd7aeyQY45AdXd5tT1Z
|
|
703
|
+
PAYLOAD 85b json-compressed
|
|
704
|
+
json 79b {"adr":"VVf4DQU357tDnZGYQeDrntRJ5rs=","spc":"ispc3ANoVSzNA3P6t7abLR69ho5YPPZU"}
|
|
705
|
+
*/
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Create a signed authorization token that can be used to authorize against the fabric
|
|
709
|
+
*
|
|
710
|
+
* @methodGroup Authorization
|
|
711
|
+
* @namedParams
|
|
712
|
+
* @param {number} duration=86400000 - Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000). Default is 24 hours.
|
|
713
|
+
* @param {Object=} spec - Additional attributes for this token
|
|
714
|
+
* @param {string=} address - Address of the signing account - if not specified, the current signer address will be used.
|
|
715
|
+
* @param {function=} Sign - If specified, this function will be used to produce the signature instead of the client's current signer
|
|
716
|
+
* @param {boolean=} addEthereumPrefix=true - If specified, the 'Ethereum Signed Message' prefixed hash format will be performed. Disable this if the provided Sign method already does this (e.g. Metamask)
|
|
717
|
+
*/
|
|
718
|
+
async CreateFabricToken({
|
|
719
|
+
duration=24 * 60 * 60 * 1000,
|
|
720
|
+
spec={},
|
|
721
|
+
address,
|
|
722
|
+
Sign,
|
|
723
|
+
addEthereumPrefix=true,
|
|
724
|
+
}={}) {
|
|
725
|
+
address = address || this.CurrentAccountAddress();
|
|
726
|
+
|
|
727
|
+
let token = {
|
|
728
|
+
...spec,
|
|
729
|
+
sub:`iusr${Utils.AddressToHash(address)}`,
|
|
730
|
+
adr: Buffer.from(address.replace(/^0x/, ""), "hex").toString("base64"),
|
|
731
|
+
spc: await this.ContentSpaceId(),
|
|
732
|
+
iat: Date.now(),
|
|
733
|
+
exp: Date.now() + duration,
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
if(!Sign) {
|
|
737
|
+
Sign = async message => this.authClient.Sign(message);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
let message = `Eluvio Content Fabric Access Token 1.0\n${JSON.stringify(token)}`;
|
|
741
|
+
|
|
742
|
+
if(addEthereumPrefix) {
|
|
743
|
+
message = Ethers.utils.keccak256(Buffer.from(`\x19Ethereum Signed Message:\n${message.length}${message}`, "utf-8"));
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
const signature = await Sign(message);
|
|
747
|
+
|
|
748
|
+
const compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
|
|
749
|
+
return `acspjc${this.utils.B58(
|
|
750
|
+
Buffer.concat([
|
|
751
|
+
Buffer.from(signature.replace(/^0x/, ""), "hex"),
|
|
752
|
+
Buffer.from(compressedToken)
|
|
753
|
+
])
|
|
754
|
+
)}`;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
|
|
697
758
|
/**
|
|
698
759
|
* Issue a self-signed authorization token
|
|
699
760
|
*
|
|
@@ -705,7 +766,7 @@ class ElvClient {
|
|
|
705
766
|
* @param {string=} policyId - The object ID of the policy for this token
|
|
706
767
|
* @param {string=} subject - The subject of the token
|
|
707
768
|
* @param {string} grantType=read - Permissions to grant for this token. Options: "access", "read", "create", "update", "read-crypt"
|
|
708
|
-
* @param {number} duration - Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000)
|
|
769
|
+
* @param {number} duration - Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000)
|
|
709
770
|
* @param {boolean} allowDecryption=false - If specified, the re-encryption key will be included in the token,
|
|
710
771
|
* enabling the user of this token to download encrypted content from the specified object
|
|
711
772
|
* @param {Object=} context - Additional JSON context
|
package/src/RemoteSigner.js
CHANGED
|
@@ -85,24 +85,28 @@ class RemoteSigner extends Ethers.Signer {
|
|
|
85
85
|
*/
|
|
86
86
|
async signDigest(digest) {
|
|
87
87
|
if(!this.signatureCache[digest]) {
|
|
88
|
-
this.signatureCache[digest] = new Promise(async resolve => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
88
|
+
this.signatureCache[digest] = new Promise(async (resolve, reject) => {
|
|
89
|
+
try {
|
|
90
|
+
let signature = await Utils.ResponseToJson(
|
|
91
|
+
this.HttpClient.Request({
|
|
92
|
+
method: "POST",
|
|
93
|
+
path: UrlJoin("as", "wlt", "sign", "eth", this.id),
|
|
94
|
+
headers: {
|
|
95
|
+
Authorization: `Bearer ${this.authToken}`
|
|
96
|
+
},
|
|
97
|
+
body: {
|
|
98
|
+
hash: digest
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
signature.v = parseInt(signature.v, 16);
|
|
104
|
+
signature.recoveryParam = signature.v - 27;
|
|
105
|
+
|
|
106
|
+
resolve(signature);
|
|
107
|
+
} catch(error) {
|
|
108
|
+
reject(error);
|
|
109
|
+
}
|
|
106
110
|
});
|
|
107
111
|
}
|
|
108
112
|
|
package/testScripts/Test.js
CHANGED
|
@@ -13,25 +13,6 @@ const Test = async () => {
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
client.SetSigner({signer});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const ethUrl = "https://host-216-66-40-19.contentfabric.io/eth";
|
|
19
|
-
const asUrl = "https://host-66-220-3-86.contentfabric.io";
|
|
20
|
-
|
|
21
|
-
client.SetNodes({
|
|
22
|
-
ethereumURIs: [
|
|
23
|
-
ethUrl
|
|
24
|
-
],
|
|
25
|
-
authServiceURIs: [
|
|
26
|
-
asUrl
|
|
27
|
-
]
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
console.log(
|
|
31
|
-
await client.ContentObjectTenantId({
|
|
32
|
-
objectId: "iq__3PXRZX5NCzPQsfTEquCctB2K3KJh"
|
|
33
|
-
})
|
|
34
|
-
)
|
|
35
16
|
} catch(error) {
|
|
36
17
|
console.error(error);
|
|
37
18
|
console.error(JSON.stringify(error, null, 2));
|