Skip to content

Commit 0052b70

Browse files
authored
Merge pull request #9 from phasehq/custom-kms-host
feat: add support for custom kms hosts
2 parents b6ac744 + 0731475 commit 0052b70

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phase.dev/phase-node",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Node.js Server SDK for Phase",
55
"main": "dist/index.js",
66
"types": "dist/src/index.d.ts",

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
serverSessionKeys,
1010
} from "./utils/crypto";
1111

12-
const PH_VERSION = "v1";
1312
type PhaseCiphertext = `ph:${string}:${string}:${string}:${string}`;
1413
type PhaseAppId = `phApp:${string}:${string}`;
1514
type PhaseAppSecret = `pss:${string}:${string}:${string}${string}`;
1615

16+
const PH_VERSION = "v1";
17+
const DEFAULT_KMS_HOST = "https://kms.phase.dev";
18+
1719
export default class Phase {
1820
appId: string;
1921
appPubKey: string;
@@ -24,10 +26,10 @@ export default class Phase {
2426
keyshare0: string;
2527
keyshare1UnwrapKey: string;
2628
};
29+
kmsHost: string;
2730

28-
constructor(appId: string, appSecret: string) {
31+
constructor(appId: string, appSecret: string, kmsHost?: string) {
2932
const appIdRegex = /^phApp:v(\d+):([a-fA-F0-9]{64})$/;
30-
// Update regex after switching to XOR based shares
3133
const appSecretRegex =
3234
/^pss:v(\d+):([a-fA-F0-9]{64}):([a-fA-F0-9]{64,128}):([a-fA-F0-9]{64})/gm;
3335

@@ -37,6 +39,7 @@ export default class Phase {
3739

3840
this.appId = appId;
3941
this.appPubKey = appId.split(":")[2];
42+
this.kmsHost = kmsHost ? `${kmsHost}/kms` : DEFAULT_KMS_HOST;
4043

4144
const appSecretSegments = appSecret.split(":");
4245

@@ -111,7 +114,8 @@ export default class Phase {
111114
this.appSecret.appToken,
112115
this.appSecret.keyshare1UnwrapKey,
113116
this.appId,
114-
ciphertext.data.length / 2
117+
ciphertext.data.length / 2,
118+
this.kmsHost
115119
);
116120

117121
const appPrivKey = await reconstructSecret([

src/utils/wrappedShare.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export const fetchAppKeyShare = async (
1313
appToken: string,
1414
wrapKey: string,
1515
appId: string,
16-
dataSize: number
16+
dataSize: number,
17+
host: string
1718
) => {
1819
await _sodium.ready;
1920
const sodium = _sodium;
2021

21-
const PHASE_KMS_URI = `https://kms.phase.dev/${appId}`;
22+
const PHASE_KMS_URI = `${host}/${appId}`;
2223

2324
const headers = {
2425
Authorization: `Bearer ${appToken}`,

version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const LIB_VERSION = "2.0.1";
1+
export const LIB_VERSION = "2.1.0";

0 commit comments

Comments
 (0)