retell-sdk 5.31.0 → 5.32.0

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.
Files changed (128) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/client.d.mts +9 -11
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +9 -11
  5. package/client.d.ts.map +1 -1
  6. package/client.js +0 -3
  7. package/client.js.map +1 -1
  8. package/client.mjs +0 -3
  9. package/client.mjs.map +1 -1
  10. package/index.d.mts +0 -1
  11. package/index.d.mts.map +1 -1
  12. package/index.d.ts +0 -1
  13. package/index.d.ts.map +1 -1
  14. package/index.js +1 -4
  15. package/index.js.map +1 -1
  16. package/index.mjs +0 -1
  17. package/index.mjs.map +1 -1
  18. package/internal/uploads.js +2 -12
  19. package/internal/uploads.js.map +1 -1
  20. package/internal/uploads.mjs +2 -12
  21. package/internal/uploads.mjs.map +1 -1
  22. package/package.json +1 -11
  23. package/resources/agent.d.mts +44 -44
  24. package/resources/agent.d.mts.map +1 -1
  25. package/resources/agent.d.ts +44 -44
  26. package/resources/agent.d.ts.map +1 -1
  27. package/resources/agent.js +25 -25
  28. package/resources/agent.js.map +1 -1
  29. package/resources/agent.mjs +25 -25
  30. package/resources/agent.mjs.map +1 -1
  31. package/resources/call.d.mts +1367 -1367
  32. package/resources/call.d.mts.map +1 -1
  33. package/resources/call.d.ts +1367 -1367
  34. package/resources/call.d.ts.map +1 -1
  35. package/resources/call.js +60 -60
  36. package/resources/call.js.map +1 -1
  37. package/resources/call.mjs +60 -60
  38. package/resources/call.mjs.map +1 -1
  39. package/resources/chat-agent.d.mts +46 -46
  40. package/resources/chat-agent.d.mts.map +1 -1
  41. package/resources/chat-agent.d.ts +46 -46
  42. package/resources/chat-agent.d.ts.map +1 -1
  43. package/resources/chat-agent.js +27 -27
  44. package/resources/chat-agent.js.map +1 -1
  45. package/resources/chat-agent.mjs +27 -27
  46. package/resources/chat-agent.mjs.map +1 -1
  47. package/resources/chat.d.mts +92 -92
  48. package/resources/chat.d.mts.map +1 -1
  49. package/resources/chat.d.ts +92 -92
  50. package/resources/chat.d.ts.map +1 -1
  51. package/resources/chat.js +55 -55
  52. package/resources/chat.js.map +1 -1
  53. package/resources/chat.mjs +55 -55
  54. package/resources/chat.mjs.map +1 -1
  55. package/resources/conversation-flow-component.d.mts +25 -25
  56. package/resources/conversation-flow-component.d.mts.map +1 -1
  57. package/resources/conversation-flow-component.d.ts +25 -25
  58. package/resources/conversation-flow-component.d.ts.map +1 -1
  59. package/resources/conversation-flow-component.js +12 -12
  60. package/resources/conversation-flow-component.js.map +1 -1
  61. package/resources/conversation-flow-component.mjs +12 -12
  62. package/resources/conversation-flow-component.mjs.map +1 -1
  63. package/resources/conversation-flow.d.mts +26 -26
  64. package/resources/conversation-flow.d.mts.map +1 -1
  65. package/resources/conversation-flow.d.ts +26 -26
  66. package/resources/conversation-flow.d.ts.map +1 -1
  67. package/resources/conversation-flow.js +12 -12
  68. package/resources/conversation-flow.js.map +1 -1
  69. package/resources/conversation-flow.mjs +12 -12
  70. package/resources/conversation-flow.mjs.map +1 -1
  71. package/resources/index.d.mts +9 -9
  72. package/resources/index.d.mts.map +1 -1
  73. package/resources/index.d.ts +9 -9
  74. package/resources/index.d.ts.map +1 -1
  75. package/resources/llm.d.mts +24 -24
  76. package/resources/llm.d.mts.map +1 -1
  77. package/resources/llm.d.ts +24 -24
  78. package/resources/llm.d.ts.map +1 -1
  79. package/resources/llm.js +11 -11
  80. package/resources/llm.js.map +1 -1
  81. package/resources/llm.mjs +11 -11
  82. package/resources/llm.mjs.map +1 -1
  83. package/resources/phone-number.d.mts +8 -8
  84. package/resources/phone-number.d.ts +8 -8
  85. package/resources/tests.d.mts +95 -95
  86. package/resources/tests.d.mts.map +1 -1
  87. package/resources/tests.d.ts +95 -95
  88. package/resources/tests.d.ts.map +1 -1
  89. package/resources/tests.js +27 -27
  90. package/resources/tests.js.map +1 -1
  91. package/resources/tests.mjs +27 -27
  92. package/resources/tests.mjs.map +1 -1
  93. package/resources/voice.d.mts +8 -8
  94. package/resources/voice.d.mts.map +1 -1
  95. package/resources/voice.d.ts +8 -8
  96. package/resources/voice.d.ts.map +1 -1
  97. package/resources/voice.js +12 -12
  98. package/resources/voice.js.map +1 -1
  99. package/resources/voice.mjs +12 -12
  100. package/resources/voice.mjs.map +1 -1
  101. package/src/client.ts +18 -22
  102. package/src/index.ts +0 -1
  103. package/src/internal/uploads.ts +4 -12
  104. package/src/resources/agent.ts +61 -61
  105. package/src/resources/call.ts +2364 -2364
  106. package/src/resources/chat-agent.ts +63 -63
  107. package/src/resources/chat.ts +107 -107
  108. package/src/resources/conversation-flow-component.ts +34 -34
  109. package/src/resources/conversation-flow.ts +35 -35
  110. package/src/resources/index.ts +18 -18
  111. package/src/resources/llm.ts +30 -30
  112. package/src/resources/phone-number.ts +8 -8
  113. package/src/resources/tests.ts +136 -136
  114. package/src/resources/voice.ts +12 -12
  115. package/src/version.ts +1 -1
  116. package/version.d.mts +1 -1
  117. package/version.d.ts +1 -1
  118. package/version.js +1 -1
  119. package/version.mjs +1 -1
  120. package/lib/webhook_auth.d.mts +0 -11
  121. package/lib/webhook_auth.d.mts.map +0 -1
  122. package/lib/webhook_auth.d.ts +0 -11
  123. package/lib/webhook_auth.d.ts.map +0 -1
  124. package/lib/webhook_auth.js +0 -48
  125. package/lib/webhook_auth.js.map +0 -1
  126. package/lib/webhook_auth.mjs +0 -43
  127. package/lib/webhook_auth.mjs.map +0 -1
  128. package/src/lib/webhook_auth.ts +0 -76
@@ -9,31 +9,31 @@ import { path } from '../internal/utils/path';
9
9
 
10
10
  export class Voice extends APIResource {
11
11
  /**
12
- * Retrieve details of a specific voice
12
+ * Add a community voice to the voice library
13
13
  */
14
- retrieve(voiceID: string, options?: RequestOptions): APIPromise<VoiceResponse> {
15
- return this._client.get(path`/get-voice/${voiceID}`, options);
14
+ addResource(body: VoiceAddResourceParams, options?: RequestOptions): APIPromise<VoiceResponse> {
15
+ return this._client.post('/add-community-voice', { body, ...options });
16
16
  }
17
17
 
18
18
  /**
19
- * List all voices available to the user
19
+ * Clone a voice from audio files
20
20
  */
21
- list(options?: RequestOptions): APIPromise<VoiceListResponse> {
22
- return this._client.get('/list-voices', options);
21
+ clone(body: VoiceCloneParams, options?: RequestOptions): APIPromise<VoiceResponse> {
22
+ return this._client.post('/clone-voice', multipartFormRequestOptions({ body, ...options }, this._client));
23
23
  }
24
24
 
25
25
  /**
26
- * Add a community voice to the voice library
26
+ * Retrieve details of a specific voice
27
27
  */
28
- addResource(body: VoiceAddResourceParams, options?: RequestOptions): APIPromise<VoiceResponse> {
29
- return this._client.post('/add-community-voice', { body, ...options });
28
+ retrieve(voiceID: string, options?: RequestOptions): APIPromise<VoiceResponse> {
29
+ return this._client.get(path`/get-voice/${voiceID}`, options);
30
30
  }
31
31
 
32
32
  /**
33
- * Clone a voice from audio files
33
+ * List all voices available to the user
34
34
  */
35
- clone(body: VoiceCloneParams, options?: RequestOptions): APIPromise<VoiceResponse> {
36
- return this._client.post('/clone-voice', multipartFormRequestOptions({ body, ...options }, this._client));
35
+ list(options?: RequestOptions): APIPromise<VoiceListResponse> {
36
+ return this._client.get('/list-voices', options);
37
37
  }
38
38
 
39
39
  /**
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '5.31.0'; // x-release-please-version
1
+ export const VERSION = '5.32.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "5.31.0";
1
+ export declare const VERSION = "5.32.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "5.31.0";
1
+ export declare const VERSION = "5.32.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '5.31.0'; // x-release-please-version
4
+ exports.VERSION = '5.32.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '5.31.0'; // x-release-please-version
1
+ export const VERSION = '5.32.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map
@@ -1,11 +0,0 @@
1
- export interface SecureWebhooks {
2
- sign(input: string, secret: string, timestamp?: number): Promise<string>;
3
- verify(input: string, secret: string, signature: string, opts?: {
4
- timeout?: number;
5
- timestamp?: number;
6
- }): Promise<boolean>;
7
- }
8
- export declare const symmetric: SecureWebhooks;
9
- export declare const verify: (body: string, apiKey: string, signature: string) => Promise<boolean>;
10
- export declare const sign: (body: string, apiKey: string) => Promise<string>;
11
- //# sourceMappingURL=webhook_auth.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook_auth.d.mts","sourceRoot":"","sources":["../src/lib/webhook_auth.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzE,MAAM,CACJ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9C,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAED,eAAO,MAAM,SAAS,EAAE,cAwBvB,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,OAAO,CAAC,OAAO,CAEvF,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CAEjE,CAAC"}
@@ -1,11 +0,0 @@
1
- export interface SecureWebhooks {
2
- sign(input: string, secret: string, timestamp?: number): Promise<string>;
3
- verify(input: string, secret: string, signature: string, opts?: {
4
- timeout?: number;
5
- timestamp?: number;
6
- }): Promise<boolean>;
7
- }
8
- export declare const symmetric: SecureWebhooks;
9
- export declare const verify: (body: string, apiKey: string, signature: string) => Promise<boolean>;
10
- export declare const sign: (body: string, apiKey: string) => Promise<string>;
11
- //# sourceMappingURL=webhook_auth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook_auth.d.ts","sourceRoot":"","sources":["../src/lib/webhook_auth.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzE,MAAM,CACJ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9C,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAED,eAAO,MAAM,SAAS,EAAE,cAwBvB,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,OAAO,CAAC,OAAO,CAEvF,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CAEjE,CAAC"}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sign = exports.verify = exports.symmetric = void 0;
4
- const FIVE_MINUTES = 5 * 60 * 1000;
5
- async function hmacSha256Hex(secret, input) {
6
- const enc = new TextEncoder();
7
- const key = await globalThis.crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
8
- const sig = await globalThis.crypto.subtle.sign('HMAC', key, enc.encode(input));
9
- return Array.from(new Uint8Array(sig))
10
- .map((b) => b.toString(16).padStart(2, '0'))
11
- .join('');
12
- }
13
- async function hmacSha256Verify(secret, input, digest) {
14
- const enc = new TextEncoder();
15
- const key = await globalThis.crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['verify']);
16
- const digestBytes = new Uint8Array(digest.length / 2);
17
- for (let i = 0; i < digest.length; i += 2) {
18
- digestBytes[i / 2] = parseInt(digest.slice(i, i + 2), 16);
19
- }
20
- return globalThis.crypto.subtle.verify('HMAC', key, digestBytes, enc.encode(input));
21
- }
22
- exports.symmetric = {
23
- async sign(input, secret, timestamp = Date.now()) {
24
- const digest = await hmacSha256Hex(secret, input + timestamp);
25
- return `v=${timestamp},d=${digest}`;
26
- },
27
- async verify(input, secret, signature, opts = {}) {
28
- const match = /v=(\d+),d=(.*)/.exec(signature);
29
- if (!match)
30
- return false;
31
- const poststamp = Number(match[1]);
32
- const postDigest = match[2];
33
- const timestamp = opts.timestamp ?? Date.now();
34
- const timeout = opts.timeout ?? FIVE_MINUTES;
35
- if (Math.abs(timestamp - poststamp) > timeout)
36
- return false;
37
- return hmacSha256Verify(secret, input + poststamp, postDigest);
38
- },
39
- };
40
- const verify = (body, apiKey, signature) => {
41
- return exports.symmetric.verify(body, apiKey, signature);
42
- };
43
- exports.verify = verify;
44
- const sign = (body, apiKey) => {
45
- return exports.symmetric.sign(body, apiKey);
46
- };
47
- exports.sign = sign;
48
- //# sourceMappingURL=webhook_auth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook_auth.js","sourceRoot":"","sources":["../src/lib/webhook_auth.ts"],"names":[],"mappings":";;;AAAA,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,KAAK,UAAU,aAA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E,CAAC;CACF,CAAC;AAEK,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,SAAiB,EAAoB,EAAE;IAC1F,OAAO,iBAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEK,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,MAAc,EAAmB,EAAE;IACpE,OAAO,iBAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC,CAAC;AAFW,QAAA,IAAI,QAEf"}
@@ -1,43 +0,0 @@
1
- const FIVE_MINUTES = 5 * 60 * 1000;
2
- async function hmacSha256Hex(secret, input) {
3
- const enc = new TextEncoder();
4
- const key = await globalThis.crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
5
- const sig = await globalThis.crypto.subtle.sign('HMAC', key, enc.encode(input));
6
- return Array.from(new Uint8Array(sig))
7
- .map((b) => b.toString(16).padStart(2, '0'))
8
- .join('');
9
- }
10
- async function hmacSha256Verify(secret, input, digest) {
11
- const enc = new TextEncoder();
12
- const key = await globalThis.crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['verify']);
13
- const digestBytes = new Uint8Array(digest.length / 2);
14
- for (let i = 0; i < digest.length; i += 2) {
15
- digestBytes[i / 2] = parseInt(digest.slice(i, i + 2), 16);
16
- }
17
- return globalThis.crypto.subtle.verify('HMAC', key, digestBytes, enc.encode(input));
18
- }
19
- export const symmetric = {
20
- async sign(input, secret, timestamp = Date.now()) {
21
- const digest = await hmacSha256Hex(secret, input + timestamp);
22
- return `v=${timestamp},d=${digest}`;
23
- },
24
- async verify(input, secret, signature, opts = {}) {
25
- const match = /v=(\d+),d=(.*)/.exec(signature);
26
- if (!match)
27
- return false;
28
- const poststamp = Number(match[1]);
29
- const postDigest = match[2];
30
- const timestamp = opts.timestamp ?? Date.now();
31
- const timeout = opts.timeout ?? FIVE_MINUTES;
32
- if (Math.abs(timestamp - poststamp) > timeout)
33
- return false;
34
- return hmacSha256Verify(secret, input + poststamp, postDigest);
35
- },
36
- };
37
- export const verify = (body, apiKey, signature) => {
38
- return symmetric.verify(body, apiKey, signature);
39
- };
40
- export const sign = (body, apiKey) => {
41
- return symmetric.sign(body, apiKey);
42
- };
43
- //# sourceMappingURL=webhook_auth.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook_auth.mjs","sourceRoot":"","sources":["../src/lib/webhook_auth.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,KAAa;IACxD,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;IAC9B,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAClD,KAAK,EACL,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAClB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EACjC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IACF,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAChF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;SACnC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,MAAc,EAAE,KAAa,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C,KAAK;YAAE,OAAO,KAAK,CAAC;QAEzB,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;QAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,YAAY,CAAC;QAE7C,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,OAAO;YAAE,OAAO,KAAK,CAAC;QAE5D,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,EAAE,UAAU,CAAC,CAAC;IACjE,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,SAAiB,EAAoB,EAAE;IAC1F,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,MAAc,EAAmB,EAAE;IACpE,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC,CAAC"}
@@ -1,76 +0,0 @@
1
- const FIVE_MINUTES = 5 * 60 * 1000;
2
-
3
- async function hmacSha256Hex(secret: string, input: string): Promise<string> {
4
- const enc = new TextEncoder();
5
- const key = await globalThis.crypto.subtle.importKey(
6
- 'raw',
7
- enc.encode(secret),
8
- { name: 'HMAC', hash: 'SHA-256' },
9
- false,
10
- ['sign'],
11
- );
12
- const sig = await globalThis.crypto.subtle.sign('HMAC', key, enc.encode(input));
13
- return Array.from(new Uint8Array(sig))
14
- .map((b) => b.toString(16).padStart(2, '0'))
15
- .join('');
16
- }
17
-
18
- async function hmacSha256Verify(secret: string, input: string, digest: string): Promise<boolean> {
19
- const enc = new TextEncoder();
20
- const key = await globalThis.crypto.subtle.importKey(
21
- 'raw',
22
- enc.encode(secret),
23
- { name: 'HMAC', hash: 'SHA-256' },
24
- false,
25
- ['verify'],
26
- );
27
- const digestBytes = new Uint8Array(digest.length / 2);
28
- for (let i = 0; i < digest.length; i += 2) {
29
- digestBytes[i / 2] = parseInt(digest.slice(i, i + 2), 16);
30
- }
31
- return globalThis.crypto.subtle.verify('HMAC', key, digestBytes, enc.encode(input));
32
- }
33
-
34
- export interface SecureWebhooks {
35
- sign(input: string, secret: string, timestamp?: number): Promise<string>;
36
- verify(
37
- input: string,
38
- secret: string,
39
- signature: string,
40
- opts?: { timeout?: number; timestamp?: number },
41
- ): Promise<boolean>;
42
- }
43
-
44
- export const symmetric: SecureWebhooks = {
45
- async sign(input: string, secret: string, timestamp: number = Date.now()): Promise<string> {
46
- const digest = await hmacSha256Hex(secret, input + timestamp);
47
- return `v=${timestamp},d=${digest}`;
48
- },
49
-
50
- async verify(
51
- input: string,
52
- secret: string,
53
- signature: string,
54
- opts: { timeout?: number; timestamp?: number } = {},
55
- ): Promise<boolean> {
56
- const match = /v=(\d+),d=(.*)/.exec(signature);
57
- if (!match) return false;
58
-
59
- const poststamp = Number(match[1]);
60
- const postDigest = match[2]!;
61
- const timestamp = opts.timestamp ?? Date.now();
62
- const timeout = opts.timeout ?? FIVE_MINUTES;
63
-
64
- if (Math.abs(timestamp - poststamp) > timeout) return false;
65
-
66
- return hmacSha256Verify(secret, input + poststamp, postDigest);
67
- },
68
- };
69
-
70
- export const verify = (body: string, apiKey: string, signature: string): Promise<boolean> => {
71
- return symmetric.verify(body, apiKey, signature);
72
- };
73
-
74
- export const sign = (body: string, apiKey: string): Promise<string> => {
75
- return symmetric.sign(body, apiKey);
76
- };