@stackable-labs/sdk-extension-react 1.28.0 → 1.30.0
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.d.ts +2 -2
- package/dist/index.js +19 -35
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ApiRequest, FetchRequestInit, FetchResponse, ToastPayload, ContextData, AllowedIconName } from '@stackable-labs/sdk-extension-contracts';
|
|
2
|
+
import { ApiRequest, FetchRequestInit, FetchResponse, ToastPayload, InvokeAction, ContextData, AllowedIconName } from '@stackable-labs/sdk-extension-contracts';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -62,7 +62,7 @@ declare const useCapabilities: () => {
|
|
|
62
62
|
};
|
|
63
63
|
actions: {
|
|
64
64
|
toast: (payload: ToastPayload) => Promise<void>;
|
|
65
|
-
invoke: <T = unknown>(action:
|
|
65
|
+
invoke: <T = unknown>(action: InvokeAction, payload?: Record<string, unknown>) => Promise<T>;
|
|
66
66
|
};
|
|
67
67
|
context: {
|
|
68
68
|
read: () => Promise<ContextData>;
|
package/dist/index.js
CHANGED
|
@@ -16,23 +16,7 @@ var ExtensionContext = createContext(null);
|
|
|
16
16
|
import { WebCrypto } from "@agnostack/verifyd/esm";
|
|
17
17
|
|
|
18
18
|
// ../../../lib/utils-js/src/crypto.ts
|
|
19
|
-
var
|
|
20
|
-
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
21
|
-
return globalThis.crypto;
|
|
22
|
-
}
|
|
23
|
-
throw new Error("Web Crypto API not available \u2014 requires Node.js 22+ or a modern browser");
|
|
24
|
-
};
|
|
25
|
-
var getSubtle = () => {
|
|
26
|
-
const crypto = getCrypto();
|
|
27
|
-
if (crypto.subtle) {
|
|
28
|
-
return crypto.subtle;
|
|
29
|
-
}
|
|
30
|
-
throw new Error("SubtleCrypto not available \u2014 requires a secure context (HTTPS) or Node.js 22+");
|
|
31
|
-
};
|
|
32
|
-
var importKeyForEncryption = (keyBase64) => {
|
|
33
|
-
const raw = Uint8Array.from(atob(keyBase64), (c) => c.charCodeAt(0));
|
|
34
|
-
return getSubtle().importKey("raw", raw, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
35
|
-
};
|
|
19
|
+
var base64ToBytes = (base64) => Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
36
20
|
|
|
37
21
|
// src/rpc-client.ts
|
|
38
22
|
var _webCrypto = null;
|
|
@@ -43,7 +27,7 @@ var encryptionKey = null;
|
|
|
43
27
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
44
28
|
var generateRequestId = () => `req_${++requestCounter}_${Date.now()}`;
|
|
45
29
|
var setEncryptionKey = async (keyBase64) => {
|
|
46
|
-
encryptionKey = await
|
|
30
|
+
encryptionKey = await getWebCrypto().importRawKey("secret", base64ToBytes(keyBase64), { extractable: false });
|
|
47
31
|
};
|
|
48
32
|
var initRpcListener = (extensionId) => {
|
|
49
33
|
registeredExtensionId = extensionId;
|
|
@@ -68,23 +52,6 @@ var initRpcListener = (extensionId) => {
|
|
|
68
52
|
});
|
|
69
53
|
};
|
|
70
54
|
var isEncryptedPayload = (value) => typeof value === "object" && value !== null && value.encrypted === true && Array.isArray(value.data);
|
|
71
|
-
var callCapability = async (capability, payload) => {
|
|
72
|
-
let actualPayload = payload;
|
|
73
|
-
if (capability === "data.fetch" && encryptionKey) {
|
|
74
|
-
const encrypted = await getWebCrypto().encryptMessage(JSON.stringify(payload), encryptionKey);
|
|
75
|
-
if (!encrypted) throw new Error("Failed to encrypt data.fetch payload");
|
|
76
|
-
actualPayload = { encrypted: true, data: encrypted };
|
|
77
|
-
}
|
|
78
|
-
const result = await sendCapabilityRequest(capability, actualPayload);
|
|
79
|
-
if (capability === "data.fetch" && encryptionKey) {
|
|
80
|
-
const fetchResult = result;
|
|
81
|
-
if (isEncryptedPayload(fetchResult.data)) {
|
|
82
|
-
const decrypted = await getWebCrypto().decryptMessage(fetchResult.data.data, encryptionKey);
|
|
83
|
-
fetchResult.data = JSON.parse(decrypted);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
88
55
|
var sendCapabilityRequest = (capability, payload) => new Promise((resolve, reject) => {
|
|
89
56
|
const id = generateRequestId();
|
|
90
57
|
pendingRequests.set(id, {
|
|
@@ -106,6 +73,23 @@ var sendCapabilityRequest = (capability, payload) => new Promise((resolve, rejec
|
|
|
106
73
|
}
|
|
107
74
|
}, 3e4);
|
|
108
75
|
});
|
|
76
|
+
var callCapability = async (capability, payload) => {
|
|
77
|
+
let actualPayload = payload;
|
|
78
|
+
if (capability === "data.fetch" && encryptionKey) {
|
|
79
|
+
const encrypted = await getWebCrypto().encryptMessage(JSON.stringify(payload), encryptionKey);
|
|
80
|
+
if (!encrypted) throw new Error("Failed to encrypt data.fetch payload");
|
|
81
|
+
actualPayload = { encrypted: true, data: encrypted };
|
|
82
|
+
}
|
|
83
|
+
const result = await sendCapabilityRequest(capability, actualPayload);
|
|
84
|
+
if (capability === "data.fetch" && encryptionKey) {
|
|
85
|
+
const fetchResult = result;
|
|
86
|
+
if (isEncryptedPayload(fetchResult.data)) {
|
|
87
|
+
const decrypted = await getWebCrypto().decryptMessage(fetchResult.data.data, encryptionKey);
|
|
88
|
+
fetchResult.data = JSON.parse(decrypted);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
109
93
|
|
|
110
94
|
// src/createExtension.tsx
|
|
111
95
|
import { jsx } from "react/jsx-runtime";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackable-labs/sdk-extension-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@agnostack/verifyd": "alpha",
|
|
16
|
-
"@stackable-labs/sdk-extension-contracts": "1.28.0",
|
|
17
16
|
"@remote-dom/core": "1.x",
|
|
18
|
-
"@remote-dom/react": "1.x"
|
|
17
|
+
"@remote-dom/react": "1.x",
|
|
18
|
+
"@stackable-labs/sdk-extension-contracts": "1.30.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=18.0.0 <19.0.0",
|