@pay-skill/sdk 0.1.12 → 0.1.13

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.
@@ -2,6 +2,9 @@
2
2
  * OS keychain reader — reads the private key stored by `pay` CLI.
3
3
  * Service: "pay", account: "default".
4
4
  *
5
+ * The CLI stores keys as 0x-prefixed hex strings (66 chars). Legacy entries
6
+ * stored as raw 32 bytes are converted to hex on read.
7
+ *
5
8
  * keytar is an optional dependency. If not installed, returns null.
6
9
  */
7
10
  export declare function readFromKeychain(): Promise<string | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"keychain.d.ts","sourceRoot":"","sources":["../src/keychain.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAU/D"}
1
+ {"version":3,"file":"keychain.d.ts","sourceRoot":"","sources":["../src/keychain.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA2B/D"}
package/dist/keychain.js CHANGED
@@ -2,13 +2,33 @@
2
2
  * OS keychain reader — reads the private key stored by `pay` CLI.
3
3
  * Service: "pay", account: "default".
4
4
  *
5
+ * The CLI stores keys as 0x-prefixed hex strings (66 chars). Legacy entries
6
+ * stored as raw 32 bytes are converted to hex on read.
7
+ *
5
8
  * keytar is an optional dependency. If not installed, returns null.
6
9
  */
10
+ const HEX_KEY_RE = /^0x[0-9a-fA-F]{64}$/;
7
11
  export async function readFromKeychain() {
8
12
  try {
9
13
  const moduleName = "keytar";
10
14
  const keytar = (await import(moduleName));
11
- return await keytar.default.getPassword("pay", "default");
15
+ const value = await keytar.default.getPassword("pay", "default");
16
+ if (!value)
17
+ return null;
18
+ // New format: 0x-prefixed hex string (written by CLI >= 0.3)
19
+ const trimmed = value.trim();
20
+ if (HEX_KEY_RE.test(trimmed))
21
+ return trimmed;
22
+ // Legacy format: raw 32 bytes stored via set_secret().
23
+ // keytar.getPassword reads them as a string — convert byte values to hex.
24
+ if (value.length === 32) {
25
+ const hex = "0x" +
26
+ Array.from(value, (ch) => ch.charCodeAt(0).toString(16).padStart(2, "0")).join("");
27
+ if (HEX_KEY_RE.test(hex))
28
+ return hex;
29
+ }
30
+ // Unrecognised format
31
+ return null;
12
32
  }
13
33
  catch {
14
34
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"keychain.js","sourceRoot":"","sources":["../src/keychain.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC;QAC5B,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,CAEvC,CAAC;QACF,OAAO,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"keychain.js","sourceRoot":"","sources":["../src/keychain.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC;QAC5B,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,CAEvC,CAAC;QACF,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACjE,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,6DAA6D;QAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,OAAO,CAAC;QAE7C,uDAAuD;QACvD,0EAA0E;QAC1E,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACxB,MAAM,GAAG,GACP,IAAI;gBACJ,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACrF,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,GAAG,CAAC;QACvC,CAAC;QAED,sBAAsB;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
package/jsr.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pay-skill/sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "exports": "./src/index.ts",
6
6
  "publish": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pay-skill/sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "TypeScript SDK for pay — payment infrastructure for AI agents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/keychain.ts CHANGED
@@ -2,16 +2,38 @@
2
2
  * OS keychain reader — reads the private key stored by `pay` CLI.
3
3
  * Service: "pay", account: "default".
4
4
  *
5
+ * The CLI stores keys as 0x-prefixed hex strings (66 chars). Legacy entries
6
+ * stored as raw 32 bytes are converted to hex on read.
7
+ *
5
8
  * keytar is an optional dependency. If not installed, returns null.
6
9
  */
7
10
 
11
+ const HEX_KEY_RE = /^0x[0-9a-fA-F]{64}$/;
12
+
8
13
  export async function readFromKeychain(): Promise<string | null> {
9
14
  try {
10
15
  const moduleName = "keytar";
11
16
  const keytar = (await import(moduleName)) as {
12
17
  default: { getPassword(service: string, account: string): Promise<string | null> };
13
18
  };
14
- return await keytar.default.getPassword("pay", "default");
19
+ const value = await keytar.default.getPassword("pay", "default");
20
+ if (!value) return null;
21
+
22
+ // New format: 0x-prefixed hex string (written by CLI >= 0.3)
23
+ const trimmed = value.trim();
24
+ if (HEX_KEY_RE.test(trimmed)) return trimmed;
25
+
26
+ // Legacy format: raw 32 bytes stored via set_secret().
27
+ // keytar.getPassword reads them as a string — convert byte values to hex.
28
+ if (value.length === 32) {
29
+ const hex =
30
+ "0x" +
31
+ Array.from(value, (ch) => ch.charCodeAt(0).toString(16).padStart(2, "0")).join("");
32
+ if (HEX_KEY_RE.test(hex)) return hex;
33
+ }
34
+
35
+ // Unrecognised format
36
+ return null;
15
37
  } catch {
16
38
  return null;
17
39
  }