@phantom/api-key-stamper 0.1.0 → 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
@@ -28,7 +28,7 @@ const stamper = new ApiKeyStamper({
28
28
  // Use it with PhantomClient
29
29
  const client = new PhantomClient(
30
30
  {
31
- apiBaseUrl: "https://api.phantom.com",
31
+ apiBaseUrl: "https://api.phantom.app/v1/wallets",
32
32
  organizationId: "your-org-id",
33
33
  },
34
34
  stamper,
@@ -47,7 +47,7 @@ import { ServerSDK } from "@phantom/server-sdk";
47
47
 
48
48
  const sdk = new ServerSDK({
49
49
  organizationId: "your-org-id",
50
- apiBaseUrl: "https://api.phantom.com",
50
+ apiBaseUrl: "https://api.phantom.app/v1/wallets",
51
51
  apiPrivateKey: "your-base58-encoded-secret-key",
52
52
  });
53
53
 
package/dist/index.d.ts CHANGED
@@ -1,18 +1,25 @@
1
- import { AxiosRequestConfig } from 'axios';
1
+ import { Buffer } from 'buffer';
2
+ import { Stamper, Algorithm } from '@phantom/sdk-types';
2
3
 
3
4
  interface ApiKeyStamperConfig {
4
5
  apiSecretKey: string;
5
6
  }
6
7
  /**
7
- * ApiKeyStamper that signs requests with Ed25519
8
+ * Simple stamper that takes a pre-existing secret key and creates stamps
9
+ * Does not manage keys - just signs with the provided secret key
8
10
  */
9
- declare class ApiKeyStamper {
11
+ declare class ApiKeyStamper implements Stamper {
12
+ algorithm: Algorithm;
10
13
  private keypair;
11
14
  constructor(config: ApiKeyStamperConfig);
12
15
  /**
13
- * Stamp (sign) an axios request configuration
16
+ * Create X-Phantom-Stamp header value
17
+ * @param params - Parameters object with data to sign
18
+ * @returns Complete X-Phantom-Stamp header value
14
19
  */
15
- stamp(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
20
+ stamp({ data }: {
21
+ data: Buffer;
22
+ }): Promise<string>;
16
23
  }
17
24
 
18
25
  export { ApiKeyStamper, ApiKeyStamperConfig };
package/dist/index.js CHANGED
@@ -33,32 +33,32 @@ __export(src_exports, {
33
33
  ApiKeyStamper: () => ApiKeyStamper
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_buffer = require("buffer");
37
36
  var import_base64url = require("@phantom/base64url");
38
37
  var import_crypto = require("@phantom/crypto");
39
38
  var import_bs58 = __toESM(require("bs58"));
39
+ var import_sdk_types = require("@phantom/sdk-types");
40
40
  var ApiKeyStamper = class {
41
41
  constructor(config) {
42
+ this.algorithm = import_sdk_types.Algorithm.ed25519;
42
43
  this.keypair = (0, import_crypto.createKeyPairFromSecret)(config.apiSecretKey);
43
44
  }
44
45
  /**
45
- * Stamp (sign) an axios request configuration
46
+ * Create X-Phantom-Stamp header value
47
+ * @param params - Parameters object with data to sign
48
+ * @returns Complete X-Phantom-Stamp header value
46
49
  */
47
- async stamp(config) {
48
- const requestBody = typeof config.data === "string" ? config.data : config.data === void 0 ? "" : JSON.stringify(config.data);
49
- const dataUtf8 = import_buffer.Buffer.from(requestBody, "utf8");
50
- const signature = (0, import_crypto.signWithSecret)(this.keypair.secretKey, dataUtf8);
50
+ async stamp({
51
+ data
52
+ }) {
53
+ const signature = (0, import_crypto.signWithSecret)(this.keypair.secretKey, data);
54
+ const signatureBase64url = (0, import_base64url.base64urlEncode)(signature);
51
55
  const stampData = {
52
- // The keypair is bs58 encoded, need to decode and then base64url encode the public key
53
56
  publicKey: (0, import_base64url.base64urlEncode)(import_bs58.default.decode(this.keypair.publicKey)),
54
- signature: (0, import_base64url.base64urlEncode)(signature),
57
+ signature: signatureBase64url,
55
58
  kind: "PKI"
56
59
  };
57
60
  const stampJson = JSON.stringify(stampData);
58
- const stamp = (0, import_base64url.stringToBase64url)(stampJson);
59
- config.headers = config.headers || {};
60
- config.headers["X-Phantom-Stamp"] = stamp;
61
- return Promise.resolve(config);
61
+ return Promise.resolve((0, import_base64url.base64urlEncode)(new TextEncoder().encode(stampJson)));
62
62
  }
63
63
  };
64
64
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -1,30 +1,30 @@
1
1
  // src/index.ts
2
- import { Buffer } from "buffer";
3
- import { base64urlEncode, stringToBase64url } from "@phantom/base64url";
2
+ import { base64urlEncode } from "@phantom/base64url";
4
3
  import { createKeyPairFromSecret, signWithSecret } from "@phantom/crypto";
5
4
  import bs58 from "bs58";
5
+ import { Algorithm } from "@phantom/sdk-types";
6
6
  var ApiKeyStamper = class {
7
7
  constructor(config) {
8
+ this.algorithm = Algorithm.ed25519;
8
9
  this.keypair = createKeyPairFromSecret(config.apiSecretKey);
9
10
  }
10
11
  /**
11
- * Stamp (sign) an axios request configuration
12
+ * Create X-Phantom-Stamp header value
13
+ * @param params - Parameters object with data to sign
14
+ * @returns Complete X-Phantom-Stamp header value
12
15
  */
13
- async stamp(config) {
14
- const requestBody = typeof config.data === "string" ? config.data : config.data === void 0 ? "" : JSON.stringify(config.data);
15
- const dataUtf8 = Buffer.from(requestBody, "utf8");
16
- const signature = signWithSecret(this.keypair.secretKey, dataUtf8);
16
+ async stamp({
17
+ data
18
+ }) {
19
+ const signature = signWithSecret(this.keypair.secretKey, data);
20
+ const signatureBase64url = base64urlEncode(signature);
17
21
  const stampData = {
18
- // The keypair is bs58 encoded, need to decode and then base64url encode the public key
19
22
  publicKey: base64urlEncode(bs58.decode(this.keypair.publicKey)),
20
- signature: base64urlEncode(signature),
23
+ signature: signatureBase64url,
21
24
  kind: "PKI"
22
25
  };
23
26
  const stampJson = JSON.stringify(stampData);
24
- const stamp = stringToBase64url(stampJson);
25
- config.headers = config.headers || {};
26
- config.headers["X-Phantom-Stamp"] = stamp;
27
- return Promise.resolve(config);
27
+ return Promise.resolve(base64urlEncode(new TextEncoder().encode(stampJson)));
28
28
  }
29
29
  };
30
30
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/api-key-stamper",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "API key stamper for Phantom Wallet SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -21,6 +21,7 @@
21
21
  "test": "jest",
22
22
  "test:watch": "jest --watch",
23
23
  "lint": "tsc --noEmit && eslint --cache . --ext .ts,.tsx",
24
+ "check-types": "tsc --noEmit",
24
25
  "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
25
26
  },
26
27
  "devDependencies": {
@@ -37,7 +38,8 @@
37
38
  },
38
39
  "dependencies": {
39
40
  "@phantom/base64url": "^0.1.0",
40
- "@phantom/crypto": "^0.1.0",
41
+ "@phantom/crypto": "^0.1.1",
42
+ "@phantom/sdk-types": "^0.1.1",
41
43
  "axios": "^1.10.0",
42
44
  "bs58": "^6.0.0",
43
45
  "buffer": "^6.0.3"