@whistlex/sdk 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -76,6 +76,20 @@ const messageKit = await encryptWithTaco({
76
76
  });
77
77
  ```
78
78
 
79
+ ### Decrypt Intel (TACo)
80
+
81
+ ```ts
82
+ import { decryptIntelWithTaco } from "@whistlex/sdk";
83
+
84
+ const plaintext = await decryptIntelWithTaco({
85
+ ciphertext,
86
+ messageKit,
87
+ contributorAddress,
88
+ privateKey: process.env.TACO_PRIVATE_KEY
89
+ // or signer
90
+ });
91
+ ```
92
+
79
93
  ## Notes
80
94
 
81
95
  - **Intel is encrypted locally**. The SDK never sends plaintext to WhistleX.
package/dist/crypto.d.ts CHANGED
@@ -20,6 +20,13 @@ export declare function decryptIntelWithKey(params: {
20
20
  ciphertext: string;
21
21
  keyBytes: Uint8Array;
22
22
  }): Promise<string>;
23
+ export declare function decryptIntelWithTaco(params: {
24
+ ciphertext: string;
25
+ messageKit: string;
26
+ contributorAddress?: string;
27
+ privateKey?: string;
28
+ signer?: any;
29
+ }): Promise<string>;
23
30
  export declare const symmetricEncoding: {
24
31
  bytesToHex: typeof bytesToHex;
25
32
  hexToBytes: typeof hexToBytes;
package/dist/crypto.js CHANGED
@@ -89,4 +89,14 @@ export async function decryptIntelWithKey(params) {
89
89
  const plainBuffer = await subtle.decrypt({ name: "AES-GCM", iv: toArrayBuffer(ivBytes) }, aesKey, toArrayBuffer(cipherBytes));
90
90
  return new TextDecoder().decode(plainBuffer);
91
91
  }
92
+ export async function decryptIntelWithTaco(params) {
93
+ const { decryptWithTaco } = await import("./taco.js");
94
+ const keyBytes = await decryptWithTaco({
95
+ messageKit: params.messageKit,
96
+ contributorAddress: params.contributorAddress,
97
+ privateKey: params.privateKey,
98
+ signer: params.signer
99
+ });
100
+ return decryptIntelWithKey({ ciphertext: params.ciphertext, keyBytes });
101
+ }
92
102
  export const symmetricEncoding = { bytesToHex, hexToBytes };
package/dist/taco.d.ts CHANGED
@@ -43,4 +43,4 @@ export declare function encryptWithTaco(params: EncryptWithTacoParams): Promise<
43
43
  export declare function decryptWithTaco(params: TacoConfig & {
44
44
  messageKit: string;
45
45
  contributorAddress?: string;
46
- }): Promise<string>;
46
+ }): Promise<Uint8Array>;
package/dist/taco.js CHANGED
@@ -24,6 +24,22 @@ async function resolveConditionSigner(provider, key, signer) {
24
24
  function toHexString(bytes) {
25
25
  return Buffer.from(bytes).toString("hex");
26
26
  }
27
+ function parseMessageKitBytes(serialized) {
28
+ const normalized = serialized.trim();
29
+ const hex = normalized.startsWith("0x") ? normalized.slice(2) : normalized;
30
+ try {
31
+ return Uint8Array.from(Buffer.from(hex, "hex"));
32
+ }
33
+ catch {
34
+ // fallthrough to base64
35
+ }
36
+ try {
37
+ return Uint8Array.from(Buffer.from(normalized, "base64"));
38
+ }
39
+ catch {
40
+ throw new Error("Unsupported messageKit encoding; expected hex or base64");
41
+ }
42
+ }
27
43
  function encodePayload(data) {
28
44
  const normalized = data.trim();
29
45
  const hexMatch = normalized.match(/^0x[0-9a-fA-F]+$/);
@@ -86,7 +102,7 @@ export async function encryptWithTaco(params) {
86
102
  if (typeof kit === "string")
87
103
  return kit;
88
104
  if (kit?.toBytes)
89
- return toHexString(kit.toBytes());
105
+ return `0x${toHexString(kit.toBytes())}`;
90
106
  if (kit?.toString)
91
107
  return kit.toString();
92
108
  return JSON.stringify(kit);
@@ -109,12 +125,12 @@ export async function decryptWithTaco(params) {
109
125
  const conditionProvider = new providers.JsonRpcProvider(condition);
110
126
  const decryptorSigner = await resolveConditionSigner(conditionProvider, key, signer);
111
127
  const decryptorAddress = await decryptorSigner.getAddress();
112
- const kitBytes = Buffer.from(messageKit.replace(/^0x/, ""), "hex");
113
- const kit = ThresholdMessageKit.fromBytes(Uint8Array.from(kitBytes));
128
+ const kitBytes = parseMessageKitBytes(messageKit);
129
+ const kit = ThresholdMessageKit.fromBytes(kitBytes);
114
130
  const context = ConditionContext.fromMessageKit(kit);
115
131
  context.addCustomContextParameterValues({
116
132
  ":contributor": contributorAddress ? utils.getAddress(contributorAddress) : decryptorAddress
117
133
  });
118
134
  const decryptedBytes = await decrypt(conditionProvider, domains.TESTNET || domains.tapir, kit, context, domains.TESTNET?.porterUris);
119
- return new TextDecoder().decode(decryptedBytes);
135
+ return decryptedBytes;
120
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whistlex/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "WhistleX SDK for local encryption, TACo wrapping, and on-chain pool calldata",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",