@phantom/indexed-db-stamper 0.1.2 → 0.1.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/README.md CHANGED
@@ -28,7 +28,10 @@ import { IndexedDbStamper } from "@phantom/indexed-db-stamper";
28
28
  const stamper = new IndexedDbStamper({
29
29
  dbName: "my-app-keys", // optional, defaults to 'phantom-indexed-db-stamper'
30
30
  storeName: "crypto-keys", // optional, defaults to 'crypto-keys'
31
- keyName: "signing-key", // optional, defaults to 'signing-key'
31
+ keyName: "signing-key", // optional, defaults to 'signing-key',
32
+ type: "PKI", // optional, defaults to 'PKI', accepts 'PKI' or 'OIDC'
33
+ idToken?: undefined, // required for OIDC type, optional for PKI
34
+ salt?: undefined, // required for OIDC type, optional for PKI
32
35
  });
33
36
 
34
37
  // Initialize and generate/load keys
@@ -61,7 +64,7 @@ const binaryData = Buffer.from([1, 2, 3]);
61
64
  const jsonData = Buffer.from(JSON.stringify({ key: "value" }), "utf8");
62
65
 
63
66
  await stamper.stamp({ data: stringData });
64
- await stamper.stamp({ data: binaryData, type: "PKI" }); // explicit PKI type
67
+ await stamper.stamp({ data: binaryData }); // explicit PKI type
65
68
  await stamper.stamp({ data: jsonData });
66
69
 
67
70
  // OIDC type stamping (requires idToken and salt)
package/dist/index.d.ts CHANGED
@@ -5,6 +5,9 @@ type IndexedDbStamperConfig = {
5
5
  dbName?: string;
6
6
  storeName?: string;
7
7
  keyName?: string;
8
+ type?: "PKI" | "OIDC";
9
+ idToken?: string;
10
+ salt?: string;
8
11
  };
9
12
  /**
10
13
  * IndexedDB-based key manager that stores cryptographic keys securely in IndexedDB
@@ -25,6 +28,9 @@ declare class IndexedDbStamper implements StamperWithKeyManagement {
25
28
  private keyInfo;
26
29
  private cryptoKeyPair;
27
30
  algorithm: Algorithm;
31
+ type: "PKI" | "OIDC";
32
+ idToken?: string;
33
+ salt?: string;
28
34
  constructor(config?: IndexedDbStamperConfig);
29
35
  /**
30
36
  * Initialize the stamper by opening IndexedDB and retrieving or generating keys
package/dist/index.js CHANGED
@@ -37,18 +37,24 @@ var import_base64url = require("@phantom/base64url");
37
37
  var import_bs58 = __toESM(require("bs58"));
38
38
  var import_sdk_types = require("@phantom/sdk-types");
39
39
  var IndexedDbStamper = class {
40
- // Use Ed25519 for maximum security and performance
40
+ // Optional for PKI, required for OIDC
41
41
  constructor(config = {}) {
42
42
  this.db = null;
43
43
  this.keyInfo = null;
44
44
  this.cryptoKeyPair = null;
45
45
  this.algorithm = import_sdk_types.Algorithm.ed25519;
46
+ // Use Ed25519 for maximum security and performance
47
+ // The type of stamper, can be changed at any time
48
+ this.type = "PKI";
46
49
  if (typeof window === "undefined" || !window.indexedDB) {
47
50
  throw new Error("IndexedDbStamper requires a browser environment with IndexedDB support");
48
51
  }
49
52
  this.dbName = config.dbName || "phantom-indexed-db-stamper";
50
53
  this.storeName = config.storeName || "crypto-keys";
51
54
  this.keyName = config.keyName || "signing-key";
55
+ this.type = config.type || "PKI";
56
+ this.idToken = config.idToken;
57
+ this.salt = config.salt;
52
58
  }
53
59
  /**
54
60
  * Initialize the stamper by opening IndexedDB and retrieving or generating keys
@@ -85,7 +91,7 @@ var IndexedDbStamper = class {
85
91
  * @returns Complete X-Phantom-Stamp header value
86
92
  */
87
93
  async stamp(params) {
88
- const { data, type = "PKI" } = params;
94
+ const { data } = params;
89
95
  if (!this.keyInfo || !this.cryptoKeyPair) {
90
96
  throw new Error("Stamper not initialized. Call init() first.");
91
97
  }
@@ -99,7 +105,10 @@ var IndexedDbStamper = class {
99
105
  dataBytes
100
106
  );
101
107
  const signatureBase64url = (0, import_base64url.base64urlEncode)(new Uint8Array(signature));
102
- const stampData = type === "PKI" ? {
108
+ const stampType = params.type || this.type;
109
+ const idToken = params.type === "OIDC" ? params.idToken : this.idToken;
110
+ const salt = params.type === "OIDC" ? params.salt : this.salt;
111
+ const stampData = stampType === "PKI" ? {
103
112
  // Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
104
113
  publicKey: (0, import_base64url.base64urlEncode)(import_bs58.default.decode(this.keyInfo.publicKey)),
105
114
  signature: signatureBase64url,
@@ -107,9 +116,9 @@ var IndexedDbStamper = class {
107
116
  algorithm: this.algorithm
108
117
  } : {
109
118
  kind: "OIDC",
110
- idToken: params.idToken,
119
+ idToken,
111
120
  publicKey: (0, import_base64url.base64urlEncode)(import_bs58.default.decode(this.keyInfo.publicKey)),
112
- salt: params.salt,
121
+ salt,
113
122
  algorithm: this.algorithm,
114
123
  signature: signatureBase64url
115
124
  };
package/dist/index.mjs CHANGED
@@ -3,18 +3,24 @@ import { base64urlEncode } from "@phantom/base64url";
3
3
  import bs58 from "bs58";
4
4
  import { Algorithm } from "@phantom/sdk-types";
5
5
  var IndexedDbStamper = class {
6
- // Use Ed25519 for maximum security and performance
6
+ // Optional for PKI, required for OIDC
7
7
  constructor(config = {}) {
8
8
  this.db = null;
9
9
  this.keyInfo = null;
10
10
  this.cryptoKeyPair = null;
11
11
  this.algorithm = Algorithm.ed25519;
12
+ // Use Ed25519 for maximum security and performance
13
+ // The type of stamper, can be changed at any time
14
+ this.type = "PKI";
12
15
  if (typeof window === "undefined" || !window.indexedDB) {
13
16
  throw new Error("IndexedDbStamper requires a browser environment with IndexedDB support");
14
17
  }
15
18
  this.dbName = config.dbName || "phantom-indexed-db-stamper";
16
19
  this.storeName = config.storeName || "crypto-keys";
17
20
  this.keyName = config.keyName || "signing-key";
21
+ this.type = config.type || "PKI";
22
+ this.idToken = config.idToken;
23
+ this.salt = config.salt;
18
24
  }
19
25
  /**
20
26
  * Initialize the stamper by opening IndexedDB and retrieving or generating keys
@@ -51,7 +57,7 @@ var IndexedDbStamper = class {
51
57
  * @returns Complete X-Phantom-Stamp header value
52
58
  */
53
59
  async stamp(params) {
54
- const { data, type = "PKI" } = params;
60
+ const { data } = params;
55
61
  if (!this.keyInfo || !this.cryptoKeyPair) {
56
62
  throw new Error("Stamper not initialized. Call init() first.");
57
63
  }
@@ -65,7 +71,10 @@ var IndexedDbStamper = class {
65
71
  dataBytes
66
72
  );
67
73
  const signatureBase64url = base64urlEncode(new Uint8Array(signature));
68
- const stampData = type === "PKI" ? {
74
+ const stampType = params.type || this.type;
75
+ const idToken = params.type === "OIDC" ? params.idToken : this.idToken;
76
+ const salt = params.type === "OIDC" ? params.salt : this.salt;
77
+ const stampData = stampType === "PKI" ? {
69
78
  // Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
70
79
  publicKey: base64urlEncode(bs58.decode(this.keyInfo.publicKey)),
71
80
  signature: signatureBase64url,
@@ -73,9 +82,9 @@ var IndexedDbStamper = class {
73
82
  algorithm: this.algorithm
74
83
  } : {
75
84
  kind: "OIDC",
76
- idToken: params.idToken,
85
+ idToken,
77
86
  publicKey: base64urlEncode(bs58.decode(this.keyInfo.publicKey)),
78
- salt: params.salt,
87
+ salt,
79
88
  algorithm: this.algorithm,
80
89
  signature: signatureBase64url
81
90
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/indexed-db-stamper",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "IndexedDB stamper for Phantom Wallet SDK with non-extractable key storage",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -41,8 +41,8 @@
41
41
  "dependencies": {
42
42
  "@phantom/base64url": "^0.1.0",
43
43
  "@phantom/crypto": "^0.1.2",
44
- "@phantom/embedded-provider-core": "^0.1.3",
45
- "@phantom/sdk-types": "^0.1.2",
44
+ "@phantom/embedded-provider-core": "^0.1.5",
45
+ "@phantom/sdk-types": "^0.1.4",
46
46
  "bs58": "^6.0.0",
47
47
  "buffer": "^6.0.3"
48
48
  },