@phantom/api-key-stamper 0.1.3 → 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/dist/index.d.ts +12 -1
- package/dist/index.js +15 -3
- package/dist/index.mjs +15 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ interface ApiKeyStamperConfig {
|
|
|
10
10
|
*/
|
|
11
11
|
declare class ApiKeyStamper implements Stamper {
|
|
12
12
|
algorithm: Algorithm;
|
|
13
|
+
type: "PKI" | "OIDC";
|
|
14
|
+
idToken?: string;
|
|
15
|
+
salt?: string;
|
|
13
16
|
private keypair;
|
|
14
17
|
constructor(config: ApiKeyStamperConfig);
|
|
15
18
|
/**
|
|
@@ -17,8 +20,16 @@ declare class ApiKeyStamper implements Stamper {
|
|
|
17
20
|
* @param params - Parameters object with data to sign
|
|
18
21
|
* @returns Complete X-Phantom-Stamp header value
|
|
19
22
|
*/
|
|
20
|
-
stamp(
|
|
23
|
+
stamp(params: {
|
|
21
24
|
data: Buffer;
|
|
25
|
+
type?: "PKI";
|
|
26
|
+
idToken?: never;
|
|
27
|
+
salt?: never;
|
|
28
|
+
} | {
|
|
29
|
+
data: Buffer;
|
|
30
|
+
type: "OIDC";
|
|
31
|
+
idToken: string;
|
|
32
|
+
salt: string;
|
|
22
33
|
}): Promise<string>;
|
|
23
34
|
}
|
|
24
35
|
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,8 @@ var import_sdk_types = require("@phantom/sdk-types");
|
|
|
40
40
|
var ApiKeyStamper = class {
|
|
41
41
|
constructor(config) {
|
|
42
42
|
this.algorithm = import_sdk_types.Algorithm.ed25519;
|
|
43
|
+
// Use the same algorithm as the keypair
|
|
44
|
+
this.type = "PKI";
|
|
43
45
|
this.keypair = (0, import_crypto.createKeyPairFromSecret)(config.apiSecretKey);
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
@@ -47,13 +49,23 @@ var ApiKeyStamper = class {
|
|
|
47
49
|
* @param params - Parameters object with data to sign
|
|
48
50
|
* @returns Complete X-Phantom-Stamp header value
|
|
49
51
|
*/
|
|
50
|
-
async stamp(
|
|
52
|
+
async stamp(params) {
|
|
53
|
+
const { data } = params;
|
|
51
54
|
const signature = (0, import_crypto.signWithSecret)(this.keypair.secretKey, data);
|
|
52
55
|
const signatureBase64url = (0, import_base64url.base64urlEncode)(signature);
|
|
53
|
-
const
|
|
56
|
+
const stampType = params.type || this.type;
|
|
57
|
+
const stampData = stampType === "PKI" ? {
|
|
54
58
|
publicKey: (0, import_base64url.base64urlEncode)(import_bs58.default.decode(this.keypair.publicKey)),
|
|
55
59
|
signature: signatureBase64url,
|
|
56
|
-
kind: "PKI"
|
|
60
|
+
kind: "PKI",
|
|
61
|
+
algorithm: this.algorithm
|
|
62
|
+
} : {
|
|
63
|
+
kind: "OIDC",
|
|
64
|
+
idToken: params.type === "OIDC" ? params.idToken : this.idToken,
|
|
65
|
+
publicKey: (0, import_base64url.base64urlEncode)(import_bs58.default.decode(this.keypair.publicKey)),
|
|
66
|
+
salt: params.type === "OIDC" ? params.salt : this.salt,
|
|
67
|
+
algorithm: this.algorithm,
|
|
68
|
+
signature: signatureBase64url
|
|
57
69
|
};
|
|
58
70
|
const stampJson = JSON.stringify(stampData);
|
|
59
71
|
return Promise.resolve((0, import_base64url.base64urlEncode)(new TextEncoder().encode(stampJson)));
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import { Algorithm } from "@phantom/sdk-types";
|
|
|
6
6
|
var ApiKeyStamper = class {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
this.algorithm = Algorithm.ed25519;
|
|
9
|
+
// Use the same algorithm as the keypair
|
|
10
|
+
this.type = "PKI";
|
|
9
11
|
this.keypair = createKeyPairFromSecret(config.apiSecretKey);
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
@@ -13,13 +15,23 @@ var ApiKeyStamper = class {
|
|
|
13
15
|
* @param params - Parameters object with data to sign
|
|
14
16
|
* @returns Complete X-Phantom-Stamp header value
|
|
15
17
|
*/
|
|
16
|
-
async stamp(
|
|
18
|
+
async stamp(params) {
|
|
19
|
+
const { data } = params;
|
|
17
20
|
const signature = signWithSecret(this.keypair.secretKey, data);
|
|
18
21
|
const signatureBase64url = base64urlEncode(signature);
|
|
19
|
-
const
|
|
22
|
+
const stampType = params.type || this.type;
|
|
23
|
+
const stampData = stampType === "PKI" ? {
|
|
20
24
|
publicKey: base64urlEncode(bs58.decode(this.keypair.publicKey)),
|
|
21
25
|
signature: signatureBase64url,
|
|
22
|
-
kind: "PKI"
|
|
26
|
+
kind: "PKI",
|
|
27
|
+
algorithm: this.algorithm
|
|
28
|
+
} : {
|
|
29
|
+
kind: "OIDC",
|
|
30
|
+
idToken: params.type === "OIDC" ? params.idToken : this.idToken,
|
|
31
|
+
publicKey: base64urlEncode(bs58.decode(this.keypair.publicKey)),
|
|
32
|
+
salt: params.type === "OIDC" ? params.salt : this.salt,
|
|
33
|
+
algorithm: this.algorithm,
|
|
34
|
+
signature: signatureBase64url
|
|
23
35
|
};
|
|
24
36
|
const stampJson = JSON.stringify(stampData);
|
|
25
37
|
return Promise.resolve(base64urlEncode(new TextEncoder().encode(stampJson)));
|
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.4",
|
|
4
4
|
"description": "API key stamper for Phantom Wallet SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@phantom/base64url": "^0.1.0",
|
|
41
41
|
"@phantom/crypto": "^0.1.2",
|
|
42
|
-
"@phantom/sdk-types": "^0.1.
|
|
42
|
+
"@phantom/sdk-types": "^0.1.3",
|
|
43
43
|
"axios": "^1.10.0",
|
|
44
44
|
"bs58": "^6.0.0",
|
|
45
45
|
"buffer": "^6.0.3"
|