@rudderhq/identity-core 0.7.0 → 0.7.1

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 CHANGED
@@ -2,4 +2,5 @@ export * from "./email.js";
2
2
  export * from "./offline-grant.js";
3
3
  export * from "./release-policy.js";
4
4
  export * from "./secrets.js";
5
+ export * from "./telemetry-assertion.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ export * from "./email.js";
2
2
  export * from "./offline-grant.js";
3
3
  export * from "./release-policy.js";
4
4
  export * from "./secrets.js";
5
+ export * from "./telemetry-assertion.js";
5
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ export declare const PRODUCT_ANALYTICS_ASSERTION_AUDIENCE: "telemetry-collector";
3
+ export declare const MAX_PRODUCT_ANALYTICS_ASSERTION_LIFETIME_MS: number;
4
+ export declare function deriveProductAnalyticsSubject(secret: string, subject: string): string;
5
+ export declare function deriveProductAnalyticsInstallationId(secret: string, installationId: string): string;
6
+ export type ProductAnalyticsAssertionClaims = {
7
+ version: 1;
8
+ issuer: string;
9
+ audience: typeof PRODUCT_ANALYTICS_ASSERTION_AUDIENCE;
10
+ installationId: string;
11
+ pseudonymousInstallationId: string;
12
+ analyticsSubject: string | null;
13
+ consentVersion: string;
14
+ consentEpoch: number;
15
+ issuedAtMs: number;
16
+ expiresAtMs: number;
17
+ jti: string;
18
+ };
19
+ export declare function issueProductAnalyticsAssertion(input: {
20
+ signingPrivateKey: KeyObject | string | Buffer;
21
+ keyId: string;
22
+ issuer: string;
23
+ installationId: string;
24
+ pseudonymousInstallationId: string;
25
+ analyticsSubject?: string | null;
26
+ consentVersion: string;
27
+ consentEpoch: number;
28
+ nowMs: number;
29
+ expiresAtMs?: number;
30
+ jti: string;
31
+ }): string;
32
+ export declare function verifyProductAnalyticsAssertion(input: {
33
+ assertion: string;
34
+ identityPublicKey: KeyObject | string | Buffer;
35
+ expectedKeyId: string;
36
+ expectedIssuer: string;
37
+ expectedInstallationId: string;
38
+ nowMs: number;
39
+ expectedConsentEpoch?: number;
40
+ expectedAnalyticsSubject?: string | null;
41
+ }): ProductAnalyticsAssertionClaims;
42
+ export declare function generateProductAnalyticsAssertionKeyPair(): import("crypto").KeyPairKeyObjectResult;
43
+ //# sourceMappingURL=telemetry-assertion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-assertion.d.ts","sourceRoot":"","sources":["../src/telemetry-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoF,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/H,eAAO,MAAM,oCAA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AAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C,GAAG,+BAA+B,CAYlC;AAED,wBAAgB,wCAAwC,4CAEvD"}
@@ -0,0 +1,78 @@
1
+ import { createHmac, createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from "node:crypto";
2
+ export const PRODUCT_ANALYTICS_ASSERTION_AUDIENCE = "telemetry-collector";
3
+ export const MAX_PRODUCT_ANALYTICS_ASSERTION_LIFETIME_MS = 15 * 60 * 1000;
4
+ export function deriveProductAnalyticsSubject(secret, subject) {
5
+ return createHmac("sha256", secret).update(`rudder-telemetry-subject:v1:${subject}`).digest("hex");
6
+ }
7
+ export function deriveProductAnalyticsInstallationId(secret, installationId) {
8
+ return createHmac("sha256", secret).update(`rudder-telemetry-installation:v1:${installationId}`).digest("hex");
9
+ }
10
+ function stableJson(value) {
11
+ if (value === null || typeof value !== "object")
12
+ return JSON.stringify(value);
13
+ if (Array.isArray(value))
14
+ return `[${value.map(stableJson).join(",")}]`;
15
+ return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => `${JSON.stringify(key)}:${stableJson(entry)}`).join(",")}}`;
16
+ }
17
+ function encode(value) {
18
+ return Buffer.from(stableJson(value)).toString("base64url");
19
+ }
20
+ function decode(value) {
21
+ return JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
22
+ }
23
+ function key(value, privateKey) {
24
+ const isKeyObject = typeof value === "object" && value !== null && "type" in value;
25
+ return isKeyObject ? value : privateKey ? createPrivateKey(value) : createPublicKey(value);
26
+ }
27
+ function assertClaimShape(claims) {
28
+ if (claims.version !== 1 || claims.audience !== PRODUCT_ANALYTICS_ASSERTION_AUDIENCE
29
+ || typeof claims.issuer !== "string" || typeof claims.installationId !== "string"
30
+ || typeof claims.pseudonymousInstallationId !== "string" || (claims.analyticsSubject !== null && typeof claims.analyticsSubject !== "string")
31
+ || typeof claims.consentVersion !== "string" || !Number.isInteger(claims.consentEpoch) || claims.consentEpoch < 1
32
+ || !Number.isSafeInteger(claims.issuedAtMs) || !Number.isSafeInteger(claims.expiresAtMs)
33
+ || claims.expiresAtMs <= claims.issuedAtMs || claims.expiresAtMs - claims.issuedAtMs > MAX_PRODUCT_ANALYTICS_ASSERTION_LIFETIME_MS
34
+ || typeof claims.jti !== "string")
35
+ throw new Error("invalid_telemetry_assertion");
36
+ }
37
+ export function issueProductAnalyticsAssertion(input) {
38
+ const claims = {
39
+ version: 1,
40
+ issuer: input.issuer,
41
+ audience: PRODUCT_ANALYTICS_ASSERTION_AUDIENCE,
42
+ installationId: input.installationId,
43
+ pseudonymousInstallationId: input.pseudonymousInstallationId,
44
+ analyticsSubject: input.analyticsSubject ?? null,
45
+ consentVersion: input.consentVersion,
46
+ consentEpoch: input.consentEpoch,
47
+ issuedAtMs: input.nowMs,
48
+ expiresAtMs: input.expiresAtMs ?? input.nowMs + MAX_PRODUCT_ANALYTICS_ASSERTION_LIFETIME_MS,
49
+ jti: input.jti,
50
+ };
51
+ assertClaimShape(claims);
52
+ const header = { alg: "EdDSA", typ: "rudder-telemetry-assertion+jwt", kid: input.keyId };
53
+ const signingInput = `${encode(header)}.${encode(claims)}`;
54
+ return `${signingInput}.${sign(null, Buffer.from(signingInput), key(input.signingPrivateKey, true)).toString("base64url")}`;
55
+ }
56
+ export function verifyProductAnalyticsAssertion(input) {
57
+ const parts = input.assertion.split(".");
58
+ if (parts.length !== 3)
59
+ throw new Error("invalid_telemetry_assertion");
60
+ const header = decode(parts[0]);
61
+ const claims = decode(parts[1]);
62
+ if (header.alg !== "EdDSA" || header.typ !== "rudder-telemetry-assertion+jwt" || header.kid !== input.expectedKeyId)
63
+ throw new Error("invalid_telemetry_assertion");
64
+ if (!verify(null, Buffer.from(`${parts[0]}.${parts[1]}`), key(input.identityPublicKey, false), Buffer.from(parts[2], "base64url")))
65
+ throw new Error("invalid_telemetry_assertion");
66
+ assertClaimShape(claims);
67
+ if (claims.issuer !== input.expectedIssuer || claims.installationId !== input.expectedInstallationId || claims.expiresAtMs <= input.nowMs || claims.issuedAtMs > input.nowMs + 60_000)
68
+ throw new Error("invalid_telemetry_assertion");
69
+ if (input.expectedConsentEpoch !== undefined && claims.consentEpoch !== input.expectedConsentEpoch)
70
+ throw new Error("telemetry_consent_revoked");
71
+ if (input.expectedAnalyticsSubject !== undefined && claims.analyticsSubject !== input.expectedAnalyticsSubject)
72
+ throw new Error("telemetry_subject_mismatch");
73
+ return claims;
74
+ }
75
+ export function generateProductAnalyticsAssertionKeyPair() {
76
+ return generateKeyPairSync("ed25519");
77
+ }
78
+ //# sourceMappingURL=telemetry-assertion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-assertion.js","sourceRoot":"","sources":["../src/telemetry-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,EAAkB,MAAM,aAAa,CAAC;AAE/H,MAAM,CAAC,MAAM,oCAAoC,GAAG,qBAA8B,CAAC;AACnF,MAAM,CAAC,MAAM,2CAA2C,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE1E,MAAM,UAAU,6BAA6B,CAAC,MAAc,EAAE,OAAe;IAC3E,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,+BAA+B,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrG,CAAC;AAED,MAAM,UAAU,oCAAoC,CAAC,MAAc,EAAE,cAAsB;IACzF,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,oCAAoC,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,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CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,WAAW,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACpL,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,cAAc,IAAI,MAAM,CAAC,cAAc,KAAK,KAAK,CAAC,sBAAsB,IAAI,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,GAAG,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACtO,IAAI,KAAK,CAAC,oBAAoB,KAAK,SAAS,IAAI,MAAM,CAAC,YAAY,KAAK,KAAK,CAAC,oBAAoB;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACjJ,IAAI,KAAK,CAAC,wBAAwB,KAAK,SAAS,IAAI,MAAM,CAAC,gBAAgB,KAAK,KAAK,CAAC,wBAAwB;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC9J,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,wCAAwC;IACtD,OAAO,mBAAmB,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=telemetry-assertion.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-assertion.test.d.ts","sourceRoot":"","sources":["../src/telemetry-assertion.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { generateProductAnalyticsAssertionKeyPair, issueProductAnalyticsAssertion, verifyProductAnalyticsAssertion, } from "./telemetry-assertion.js";
3
+ describe("product analytics assertion", () => {
4
+ it("requires the telemetry audience and short lifetime", () => {
5
+ const keys = generateProductAnalyticsAssertionKeyPair();
6
+ const assertion = issueProductAnalyticsAssertion({
7
+ signingPrivateKey: keys.privateKey,
8
+ keyId: "telemetry-key-1",
9
+ issuer: "https://accounts.rudderhq.dev",
10
+ installationId: "install-1",
11
+ pseudonymousInstallationId: "install-hash",
12
+ analyticsSubject: "subject-hash",
13
+ consentVersion: "v1",
14
+ consentEpoch: 2,
15
+ nowMs: 1_000,
16
+ expiresAtMs: 2_000,
17
+ jti: "assertion-1",
18
+ });
19
+ expect(verifyProductAnalyticsAssertion({
20
+ assertion,
21
+ identityPublicKey: keys.publicKey,
22
+ expectedKeyId: "telemetry-key-1",
23
+ expectedIssuer: "https://accounts.rudderhq.dev",
24
+ expectedInstallationId: "install-1",
25
+ expectedConsentEpoch: 2,
26
+ expectedAnalyticsSubject: "subject-hash",
27
+ nowMs: 1_500,
28
+ }).audience).toBe("telemetry-collector");
29
+ expect(() => verifyProductAnalyticsAssertion({
30
+ assertion,
31
+ identityPublicKey: keys.publicKey,
32
+ expectedKeyId: "telemetry-key-1",
33
+ expectedIssuer: "https://accounts.rudderhq.dev",
34
+ expectedInstallationId: "install-1",
35
+ nowMs: 2_001,
36
+ })).toThrow("invalid_telemetry_assertion");
37
+ });
38
+ });
39
+ //# sourceMappingURL=telemetry-assertion.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-assertion.test.js","sourceRoot":"","sources":["../src/telemetry-assertion.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,wCAAwC,EACxC,8BAA8B,EAC9B,+BAA+B,GAChC,MAAM,0BAA0B,CAAC;AA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",
5
5
  "homepage": "https://github.com/Undertone0809/rudder",
6
6
  "bugs": {