@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 +2 -2
- package/dist/index.d.ts +12 -5
- package/dist/index.js +12 -12
- package/dist/index.mjs +13 -13
- package/package.json +4 -2
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.
|
|
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.
|
|
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 {
|
|
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
|
-
*
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const signature = (0, import_crypto.signWithSecret)(this.keypair.secretKey,
|
|
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:
|
|
57
|
+
signature: signatureBase64url,
|
|
55
58
|
kind: "PKI"
|
|
56
59
|
};
|
|
57
60
|
const stampJson = JSON.stringify(stampData);
|
|
58
|
-
|
|
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 {
|
|
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
|
|
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(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const signature = signWithSecret(this.keypair.secretKey,
|
|
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:
|
|
23
|
+
signature: signatureBase64url,
|
|
21
24
|
kind: "PKI"
|
|
22
25
|
};
|
|
23
26
|
const stampJson = JSON.stringify(stampData);
|
|
24
|
-
|
|
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.
|
|
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.
|
|
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"
|