@storacha/clawracha 0.3.2 → 0.3.4
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/sync.d.ts.map +1 -1
- package/dist/sync.js +4 -3
- package/dist/utils/crypto.d.ts +3 -0
- package/dist/utils/crypto.d.ts.map +1 -1
- package/dist/utils/crypto.js +12 -0
- package/package.json +1 -1
package/dist/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA4BxE,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,KAAK,CAAiD;IAC9D,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,gBAAgB,CAAC,CAAmB;IAC5C,OAAO,CAAC,gBAAgB,CAAC,CAAmB;IAC5C,OAAO,CAAC,eAAe,CAAC,CAAkB;gBAE9B,SAAS,EAAE,MAAM;IAK7B;;;OAGG;IACG,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAmE/C;;OAEG;IACH,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;OAGG;IACG,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB1D;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAMb,UAAU;IAwDxB;;OAEG;YACW,iBAAiB;IAe/B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAc5C;;OAEG;YACW,kBAAkB;IAYhC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;YAMrB,gBAAgB;IA4B9B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC;QACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,SAAS,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,UAAU,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC5D,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAkBI,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC;IAW5B,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;YAM5B,WAAW;CAK1B"}
|
package/dist/sync.js
CHANGED
|
@@ -19,7 +19,7 @@ import { makeTempCar } from "./utils/tempcar.js";
|
|
|
19
19
|
import { createStorachaClient } from "./utils/client.js";
|
|
20
20
|
import { decodeDelegation, encodeDelegation } from "./utils/delegation.js";
|
|
21
21
|
import { extract } from "@storacha/client/delegation";
|
|
22
|
-
import { makeEncryptionConfig, makeDecryptionConfig, getEncryptedClient } from "./utils/crypto.js";
|
|
22
|
+
import { makeEncryptionConfig, makeDecryptionConfig, getEncryptedClient, delegatePlanningDelegationToKMS, } from "./utils/crypto.js";
|
|
23
23
|
export class SyncEngine {
|
|
24
24
|
workspace;
|
|
25
25
|
blocks;
|
|
@@ -71,12 +71,13 @@ export class SyncEngine {
|
|
|
71
71
|
const { ok: planDel } = await extract(planBytes);
|
|
72
72
|
if (!planDel)
|
|
73
73
|
throw new Error("Failed to extract plan delegation");
|
|
74
|
-
|
|
75
|
-
// For decrypt, uploadDelegation covers space/content/decrypt
|
|
74
|
+
const planDelForKMS = await delegatePlanningDelegationToKMS(agent, planDel);
|
|
76
75
|
const uploadBytes = decodeDelegation(config.uploadDelegation);
|
|
77
76
|
const { ok: uploadDel } = await extract(uploadBytes);
|
|
78
77
|
if (!uploadDel)
|
|
79
78
|
throw new Error("Failed to extract upload delegation");
|
|
79
|
+
this.encryptionConfig = makeEncryptionConfig(agent, config.spaceDID, [planDelForKMS, uploadDel]);
|
|
80
|
+
// For decrypt, uploadDelegation covers space/content/decrypt
|
|
80
81
|
this.decryptionConfig = makeDecryptionConfig(config.spaceDID, uploadDel);
|
|
81
82
|
this.encryptedClient = await getEncryptedClient(storachaClient);
|
|
82
83
|
}
|
package/dist/utils/crypto.d.ts
CHANGED
|
@@ -8,8 +8,11 @@ import type { Client } from "@storacha/client";
|
|
|
8
8
|
import type { Proof } from "@ucanto/interface";
|
|
9
9
|
type SpaceDID = `did:key:${string}`;
|
|
10
10
|
import type { CryptoAdapter, EncryptionConfig, DecryptionConfig, BlobLike, EncryptedClient } from "@storacha/encrypt-upload-client/types";
|
|
11
|
+
import { Delegation } from "@ucanto/interface";
|
|
12
|
+
import { EdSigner } from "@storacha/client/principal/ed25519";
|
|
11
13
|
export declare function getKMSCryptoAdapter(): CryptoAdapter;
|
|
12
14
|
export declare function getEncryptedClient(storachaClient: Client): Promise<EncryptedClient>;
|
|
15
|
+
export declare function delegatePlanningDelegationToKMS(agent: EdSigner, planDelegation: Delegation): Promise<Proof>;
|
|
13
16
|
export declare function makeEncryptionConfig(issuer: {
|
|
14
17
|
did: () => `did:key:${string}`;
|
|
15
18
|
}, spaceDID: SpaceDID, proofs: Proof[]): EncryptionConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,KAAK,QAAQ,GAAG,WAAW,MAAM,EAAE,CAAC;AACpC,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,eAAe,EAChB,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,KAAK,QAAQ,GAAG,WAAW,MAAM,EAAE,CAAC;AACpC,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,eAAe,EAChB,MAAM,uCAAuC,CAAC;AAO/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAQ9D,wBAAgB,mBAAmB,IAAI,aAAa,CAInD;AAED,wBAAsB,kBAAkB,CACtC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,eAAe,CAAC,CAM1B;AAED,wBAAsB,+BAA+B,CACnD,KAAK,EAAE,QAAQ,EACf,cAAc,EAAE,UAAU,GACzB,OAAO,CAAC,KAAK,CAAC,CAUhB;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,WAAW,MAAM,EAAE,CAAA;CAAE,EAC1C,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,KAAK,EAAE,GACd,gBAAgB,CAMlB;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,QAAQ,EAClB,iBAAiB,EAAE,KAAK,EACxB,MAAM,CAAC,EAAE,KAAK,EAAE,GACf,gBAAgB,CAMlB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,QAAQ,EACd,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAIhC;AAuBD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,eAAe,EAAE,eAAe,EAChC,gBAAgB,EAAE,gBAAgB,GACjC,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,CAQnC"}
|
package/dist/utils/crypto.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { createGenericKMSAdapter } from "@storacha/encrypt-upload-client/factories.node";
|
|
6
6
|
import { create as createEncryptedClient } from "@storacha/encrypt-upload-client";
|
|
7
7
|
import { encryptFile, encryptedBlockStream, } from "@storacha/encrypt-upload-client/utils/encrypt";
|
|
8
|
+
import { delegate } from "@ucanto/core";
|
|
8
9
|
const KMS_SERVICE_URL = "https://ucan-kms-production.protocol-labs.workers.dev";
|
|
9
10
|
const KMS_SERVICE_DID = "did:key:z6MksQJobJmBfPhjHWgFXVppqM6Fcjc1k7xu4z6xvusVrtKv";
|
|
10
11
|
let cachedAdapter = null;
|
|
@@ -21,6 +22,17 @@ export async function getEncryptedClient(storachaClient) {
|
|
|
21
22
|
cryptoAdapter,
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
export async function delegatePlanningDelegationToKMS(agent, planDelegation) {
|
|
26
|
+
return await delegate({
|
|
27
|
+
issuer: agent,
|
|
28
|
+
audience: { did: () => KMS_SERVICE_DID },
|
|
29
|
+
capabilities: [
|
|
30
|
+
{ can: "plan/get", with: planDelegation.capabilities[0].with },
|
|
31
|
+
],
|
|
32
|
+
proofs: [planDelegation],
|
|
33
|
+
expiration: Infinity,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
24
36
|
export function makeEncryptionConfig(issuer, spaceDID, proofs) {
|
|
25
37
|
return {
|
|
26
38
|
issuer: issuer,
|