@trv-hq/trv-paystack-utils 0.0.0-stage → 1.0.6
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/.idea/modules.xml +8 -0
- package/.idea/trv-paystack-utils.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +1 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/src/index.js +2 -0
- package/package.json +30 -4
- package/skills/system/run-workflow/SKILL.md +192 -0
- package/src/index.ts +55 -0
- package/tsconfig.json +44 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/trv-paystack-utils.iml" filepath="$PROJECT_DIR$/.idea/trv-paystack-utils.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
|
5
|
+
<orderEntry type="inheritedJdk" />
|
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
+
</component>
|
|
8
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/README.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA0CA,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,oBAYlG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isPayloadValid = isPayloadValid;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const TOLERANCE_SECONDS = 300;
|
|
9
|
+
// Returns the key id (kid) of the signature that matched, or null.
|
|
10
|
+
function verifyPaystackSignature(rawBody, header, secrets, now = Math.floor(Date.now() / 1000)) {
|
|
11
|
+
if (!Buffer.isBuffer(rawBody) || typeof header !== 'string')
|
|
12
|
+
return null;
|
|
13
|
+
let t = null;
|
|
14
|
+
const entries = [];
|
|
15
|
+
for (const part of header.split(',')) {
|
|
16
|
+
const i = part.indexOf('=');
|
|
17
|
+
if (i === -1)
|
|
18
|
+
continue;
|
|
19
|
+
const key = part.slice(0, i).trim();
|
|
20
|
+
const value = part.slice(i + 1).trim();
|
|
21
|
+
if (key === 't') {
|
|
22
|
+
if (t !== null || !/^[0-9]+$/.test(value))
|
|
23
|
+
return null;
|
|
24
|
+
t = Number(value);
|
|
25
|
+
}
|
|
26
|
+
else if (key === 'v1') {
|
|
27
|
+
const j = value.indexOf(':');
|
|
28
|
+
if (j !== -1)
|
|
29
|
+
entries.push({ kid: value.slice(0, j), hex: value.slice(j + 1) });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (t === null || entries.length === 0)
|
|
33
|
+
return null;
|
|
34
|
+
if (Math.abs(now - t) > TOLERANCE_SECONDS)
|
|
35
|
+
return null;
|
|
36
|
+
for (const secret of secrets) {
|
|
37
|
+
const expected = crypto_1.default.createHmac('sha512', secret).update(t + '.').update(rawBody).digest();
|
|
38
|
+
for (const { kid, hex } of entries) {
|
|
39
|
+
if (!/^[0-9a-f]{128}$/.test(hex))
|
|
40
|
+
continue;
|
|
41
|
+
if (crypto_1.default.timingSafeEqual(expected, Buffer.from(hex, 'hex')))
|
|
42
|
+
return kid;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function verifyXPaystackSignature(rawBody, signature = '', secret) {
|
|
48
|
+
const hash = crypto_1.default.createHmac('sha512', secret).update(rawBody).digest();
|
|
49
|
+
return !(!/^[0-9a-f]{128}$/.test(signature) || !crypto_1.default.timingSafeEqual(hash, Buffer.from(signature, 'hex')));
|
|
50
|
+
}
|
|
51
|
+
async function isPayloadValid(request, rawBody, secret) {
|
|
52
|
+
const paystackSignature = request.headers.get('paystack-signature');
|
|
53
|
+
const xpaystackSignature = request.headers.get('x-paystack-signature');
|
|
54
|
+
if (paystackSignature) {
|
|
55
|
+
return !!verifyPaystackSignature(rawBody, paystackSignature, [secret]);
|
|
56
|
+
}
|
|
57
|
+
else if (xpaystackSignature) {
|
|
58
|
+
return verifyXPaystackSignature(rawBody, xpaystackSignature, secret);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AA0CA,wCAYC;AAtDD,oDAA2B;AAE3B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,mEAAmE;AACnE,SAAS,uBAAuB,CAAC,OAA4B,EAAE,MAAqB,EAAE,OAAiB,EAAE,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IACxI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAEzE,IAAI,CAAC,GAAG,IAAI,CAAC;IACb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;IAC1E,CAAC;SAAM,IAAI,kBAAkB,EAAE,CAAC;QAC5B,OAAO,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAA;IACxE,CAAC;SAAM,CAAC;QACJ,OAAO,KAAK,CAAA;IAChB,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trv-hq/trv-paystack-utils",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "paystack helpers",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"paystack",
|
|
7
|
+
"webhook"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/shiro-zoro/trv-paystack-utils#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/shiro-zoro/trv-paystack-utils/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/shiro-zoro/trv-paystack-utils.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"author": "Uchenna Nwaorgu",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish --access public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"undici-types": "^8.9.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^26.6.11",
|
|
30
|
+
"typescript": "^6.0.3"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: run-workflow
|
|
3
|
+
description: 'How to write and run a dynamic workflow script with the `run_workflow` tool: a Python script that orchestrates many agents with `agent`, `parallel`, `pipeline`, and `phase`. Use when a task splits into many independent or staged pieces of agent work (fan out over files, modules, bugs, or review angles, then aggregate), or when the user asks for a workflow. Don''t use for a single delegated task (use a subagent) or for legacy workflow files (see migrate-workflows).'
|
|
4
|
+
metadata:
|
|
5
|
+
namespace: system
|
|
6
|
+
---
|
|
7
|
+
# Dynamic workflows with `run_workflow`
|
|
8
|
+
|
|
9
|
+
A workflow is a short Python script that the `run_workflow` tool executes. The
|
|
10
|
+
script decides which agents to start, in what order, and what to do with their
|
|
11
|
+
results. Use it instead of many manual subagent calls when the orchestration
|
|
12
|
+
itself is code: loops over a list, fan-out then aggregate, or staged pipelines.
|
|
13
|
+
|
|
14
|
+
## Steps
|
|
15
|
+
|
|
16
|
+
1. Pass the script inline as `Script`, or write it to a file (for example in
|
|
17
|
+
the conversation scratch directory) and pass its absolute path as
|
|
18
|
+
`ScriptPath`. Set exactly one of them; a file is easier to fix and rerun.
|
|
19
|
+
2. Call `run_workflow(Script="...", Description="...")` or
|
|
20
|
+
`run_workflow(ScriptPath="/abs/path/workflow.py", Description="...")`.
|
|
21
|
+
`Description` is a one-line goal shown in the UI.
|
|
22
|
+
The workflow runs in the background, and you are notified when it ends.
|
|
23
|
+
For a quick script, such as a `call_tool` fan-out, set
|
|
24
|
+
`WaitMsBeforeAsync` (up to 10000) to get the result in the same turn if it
|
|
25
|
+
finishes in time.
|
|
26
|
+
To pass inputs, set `Args` to a JSON object; the script reads it as the
|
|
27
|
+
`args` dict. When `ScriptPath` is a saved workflow's entry script, `Args`
|
|
28
|
+
is validated against the args schema in its `workflow.json`.
|
|
29
|
+
3. Read the tool result: it contains the `log()` output (`Logs:`) and what the
|
|
30
|
+
script printed (`Output:`). Each agent is also linked from the workflow
|
|
31
|
+
step, so the user can open its conversation.
|
|
32
|
+
4. If the tool returns an error, fix the script at the reported line and run
|
|
33
|
+
it again.
|
|
34
|
+
|
|
35
|
+
## Script rules
|
|
36
|
+
|
|
37
|
+
The script runs in its own `python3` process, which needs Python 3.8 or later
|
|
38
|
+
on `PATH`:
|
|
39
|
+
|
|
40
|
+
- `await` works at the top level, and you can define `async def` helpers.
|
|
41
|
+
- Installed library workflows are importable by name (`import <library>` or
|
|
42
|
+
`from <library> import <name>`); library modules see the same primitives as
|
|
43
|
+
the script.
|
|
44
|
+
- What the script prints (`print()`, `stderr`, child-process output, and the
|
|
45
|
+
`repr` of a trailing expression) is returned in the tool result's `Output:`
|
|
46
|
+
section (and appended to the error when the workflow fails).
|
|
47
|
+
- An uncaught exception stops the workflow and reports the script line.
|
|
48
|
+
- `CONVERSATION_ID` and `STEP_INDEX` identify the `run_workflow` step.
|
|
49
|
+
`WORKSPACES` is a tuple of the workspace directories, primary first (empty
|
|
50
|
+
if there are none).
|
|
51
|
+
- The working directory is `Cwd` if given, else `WORKSPACES[0]`, so relative
|
|
52
|
+
paths resolve against it. Local modules are not importable.
|
|
53
|
+
|
|
54
|
+
## Primitives
|
|
55
|
+
|
|
56
|
+
| Primitive | Behavior |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `log(*args)` | Adds a line to the workflow output and the UI. |
|
|
59
|
+
| `phase(name)` | Starts a named phase; later logs and agents group under it. |
|
|
60
|
+
| `agent(prompt=None, schema=None, role=None, type_name="self", workspace="inherit", model=None)` | Defines an agent; nothing runs yet. `await agent(prompt, schema)` runs it once and returns its result. `a = agent(...)` then `await a(prompt, schema)` runs one turn in a conversation kept across calls. |
|
|
61
|
+
| `parallel(items, fn)` | Promise that calls `fn(item)` for each item and awaits all results concurrently; results are in item order. If one fails, the rest are cancelled. |
|
|
62
|
+
| `pipeline(items, fn)` | Promise that calls and awaits `fn(item)` one item at a time; results are in item order. |
|
|
63
|
+
| `trajectory(last=None, types=None, tools=None, min_index=None, max_index=None)` | `await trajectory()` returns steps before this `run_workflow` call started, oldest first. `min_index` and `max_index` bound `step.index` (inclusive); `types` and `tools` filter by step type or tool name; `last` keeps the last N matching steps. |
|
|
64
|
+
|
|
65
|
+
Arguments:
|
|
66
|
+
|
|
67
|
+
- `type_name`: the agent type to run. `"self"` uses the current agent's
|
|
68
|
+
configuration; any available custom agent name also works.
|
|
69
|
+
- `workspace`: `"inherit"` (the current workspace), `"branch"` (a new isolated
|
|
70
|
+
clone, for agents that edit code in parallel), or `"share"` (a new workspace
|
|
71
|
+
that shares the underlying repository). Other values are errors.
|
|
72
|
+
- `schema` (required): a JSON schema (dict or string) for the agent's result.
|
|
73
|
+
The agent returns the result by calling its `finish` tool, which checks it
|
|
74
|
+
against the schema, and `await agent(...)` returns the parsed value. An
|
|
75
|
+
agent that ends without calling `finish` fails the workflow. Use
|
|
76
|
+
`{"type": "string"}` for a free-form answer.
|
|
77
|
+
- `role`: an optional short title for the agent's card, such as
|
|
78
|
+
`"Security reviewer"`.
|
|
79
|
+
- `model`: the agent's model tier: `"inherit"` (default, your model),
|
|
80
|
+
`"flash_lite"`, `"flash"`, or `"pro"`. Use a lighter tier for simple,
|
|
81
|
+
high-fan-out work.
|
|
82
|
+
- `fn`: usually a `lambda` that returns `agent(...)`, or an `async def`
|
|
83
|
+
helper that awaits several agents. It must return something awaitable:
|
|
84
|
+
an `agent()` or a call on one, a nested `parallel()` / `pipeline()`, or
|
|
85
|
+
an `async def` call. Build per-item prompts and roles with f-strings.
|
|
86
|
+
|
|
87
|
+
Awaiting the same agent twice runs it once and returns the same result. An
|
|
88
|
+
`agent()` that is never awaited or called never runs, so always `await` it, or
|
|
89
|
+
pass it to `parallel` / `pipeline` and await that.
|
|
90
|
+
|
|
91
|
+
The workflow step shows one card per agent, in the order agents start, titled
|
|
92
|
+
with its `role`, or else the first line of its prompt, so set a role or start
|
|
93
|
+
each prompt with a short line that names the job.
|
|
94
|
+
|
|
95
|
+
## Agents that keep their context
|
|
96
|
+
|
|
97
|
+
When one agent should do several related turns, such as a reviewer that checks
|
|
98
|
+
the fixes for the bugs it found, call it instead of awaiting it. Each
|
|
99
|
+
`a(prompt, schema)` is lazy like an awaited `agent()` and returns that turn's
|
|
100
|
+
`finish` result; the agent's own `prompt`, if any, is its standing instructions
|
|
101
|
+
and leads the first turn. `schema` on a call defaults to the agent's. Turns on
|
|
102
|
+
one agent run one at a time, in the order they were started. A failed turn
|
|
103
|
+
raises, but the agent stays usable. An agent is either awaited or called, not
|
|
104
|
+
both. `del a` ends the agent, unless something else, such as a lambda, still
|
|
105
|
+
references it; every agent ends when the workflow ends.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
reviewer = agent("You review Go code for correctness.", role="Reviewer")
|
|
109
|
+
bugs = await reviewer("List the bugs in foo.go.", {"type": "array", "items": {"type": "string"}})
|
|
110
|
+
fixes = await parallel(bugs, lambda b: agent(f"Fix: {b}", {"type": "string"}))
|
|
111
|
+
ok = await reviewer(f"Fixes made: {fixes}. Are all your bugs fixed?", {"type": "boolean"})
|
|
112
|
+
del reviewer
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Calling tools from the script
|
|
116
|
+
|
|
117
|
+
Where the `run_workflow` tool description lists tools for `call_tool`, the
|
|
118
|
+
script can call them directly:
|
|
119
|
+
|
|
120
|
+
- `call_tool(name, **args)` returns a promise like `agent()` does. Awaiting it
|
|
121
|
+
runs the tool with the arguments you would pass to it directly and returns
|
|
122
|
+
the tool's output as a `str`.
|
|
123
|
+
- It raises `ToolError` (with `.tool` and `.message`) if the tool fails or
|
|
124
|
+
the call is denied. `.denied` is `True` when a pre-tool hook or the
|
|
125
|
+
permission check rejected the call before the tool ran, so a script can
|
|
126
|
+
skip denied calls and still fail on real errors.
|
|
127
|
+
- The user cannot be asked anything from a workflow: a call that needs user
|
|
128
|
+
approval that has not already been granted is denied.
|
|
129
|
+
- Tool outputs are not shown to you unless the script logs or prints them.
|
|
130
|
+
|
|
131
|
+
## Reading earlier conversation steps
|
|
132
|
+
|
|
133
|
+
Pass inputs you already have in `Args` (or inline in the script). Use
|
|
134
|
+
`await trajectory(...)` when the script needs to inspect steps from earlier in
|
|
135
|
+
this conversation—such as mining a failed `run_command` output without
|
|
136
|
+
rerunning it—and pass only the relevant slice into child `agent()` prompts.
|
|
137
|
+
|
|
138
|
+
Each returned `Step` is a `dict` that also supports attribute access (missing
|
|
139
|
+
fields return `None` as attributes):
|
|
140
|
+
|
|
141
|
+
- `index` (`int`): 0-based step index.
|
|
142
|
+
- `type` (`str`): step type, e.g. `"USER_INPUT"`, `"PLANNER_RESPONSE"`,
|
|
143
|
+
`"SYSTEM_MESSAGE"`, or `"GENERIC"` (tool calls).
|
|
144
|
+
- `status` (`str`): e.g. `"DONE"`, `"ERROR"`, or `"CLEARED"`.
|
|
145
|
+
- Message steps set `text` (`str`); tool steps set `tool` (`str`), `args`
|
|
146
|
+
(parsed `dict`), and `output` (`str`, truncated at 200k characters).
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
steps = await trajectory(tools=["run_command"], last=20)
|
|
150
|
+
errors = [s.output for s in steps if s.status == "ERROR" and s.output]
|
|
151
|
+
log(f"Found {len(errors)} failed command(s)")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`trajectory()` only returns steps before the `run_workflow` call started (steps
|
|
155
|
+
added while the workflow runs in the background are not included). Older tool
|
|
156
|
+
steps evicted from memory have `status == "CLEARED"` and `output == None`; read
|
|
157
|
+
the conversation's `transcript.jsonl` / `transcript_full.jsonl` when you need
|
|
158
|
+
cleared tool outputs or steps added after the workflow started.
|
|
159
|
+
|
|
160
|
+
## Behavior to know
|
|
161
|
+
|
|
162
|
+
- Workflow agents are main agents, not subagents. They are hidden from the
|
|
163
|
+
conversation list and reachable from the workflow step. An awaited agent
|
|
164
|
+
is single-use; a called agent lasts until deleted or the workflow ends.
|
|
165
|
+
- `await agent(...)` returns when the agent's run ends, with the result it
|
|
166
|
+
passed to `finish`.
|
|
167
|
+
- If one agent in `parallel` fails, the whole call fails and the other agents
|
|
168
|
+
in it are cancelled. Stopping the parent conversation stops all running
|
|
169
|
+
workflow agents.
|
|
170
|
+
- Agents do not see the script or each other. Put all the context an agent
|
|
171
|
+
needs in its prompt, and ask for a short, well-defined output.
|
|
172
|
+
|
|
173
|
+
## Example
|
|
174
|
+
|
|
175
|
+
Fan out over a list that an agent produces:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
phase("Discover")
|
|
179
|
+
files = await agent(
|
|
180
|
+
"List the Go files under pkg/foo that call Bar(). Paths only.",
|
|
181
|
+
schema={"type": "array", "items": {"type": "string"}},
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
phase("Review")
|
|
185
|
+
reviews = await parallel(files, lambda f: agent(
|
|
186
|
+
f"Review {f} for misuse of Bar(). Reply in 3 bullets or 'OK'.",
|
|
187
|
+
schema={"type": "string"},
|
|
188
|
+
role=f"Review {f}",
|
|
189
|
+
))
|
|
190
|
+
for r in reviews:
|
|
191
|
+
log(r)
|
|
192
|
+
```
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import crypto from "crypto"
|
|
2
|
+
|
|
3
|
+
const TOLERANCE_SECONDS = 300;
|
|
4
|
+
|
|
5
|
+
// Returns the key id (kid) of the signature that matched, or null.
|
|
6
|
+
function verifyPaystackSignature(rawBody: Buffer<ArrayBuffer>, header: string | null, secrets: string[], now = Math.floor(Date.now() / 1000)) {
|
|
7
|
+
if (!Buffer.isBuffer(rawBody) || typeof header !== 'string') return null;
|
|
8
|
+
|
|
9
|
+
let t = null;
|
|
10
|
+
const entries = [];
|
|
11
|
+
for (const part of header.split(',')) {
|
|
12
|
+
const i = part.indexOf('=');
|
|
13
|
+
if (i === -1) continue;
|
|
14
|
+
const key = part.slice(0, i).trim();
|
|
15
|
+
const value = part.slice(i + 1).trim();
|
|
16
|
+
if (key === 't') {
|
|
17
|
+
if (t !== null || !/^[0-9]+$/.test(value)) return null;
|
|
18
|
+
t = Number(value);
|
|
19
|
+
} else if (key === 'v1') {
|
|
20
|
+
const j = value.indexOf(':');
|
|
21
|
+
if (j !== -1) entries.push({kid: value.slice(0, j), hex: value.slice(j + 1)});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (t === null || entries.length === 0) return null;
|
|
25
|
+
if (Math.abs(now - t) > TOLERANCE_SECONDS) return null;
|
|
26
|
+
|
|
27
|
+
for (const secret of secrets) {
|
|
28
|
+
const expected = crypto.createHmac('sha512', secret).update(t + '.').update(rawBody).digest();
|
|
29
|
+
for (const {kid, hex} of entries) {
|
|
30
|
+
if (!/^[0-9a-f]{128}$/.test(hex)) continue;
|
|
31
|
+
if (crypto.timingSafeEqual(expected, Buffer.from(hex, 'hex'))) return kid;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function verifyXPaystackSignature(rawBody: Buffer<ArrayBuffer>, signature: string = '', secret: string) {
|
|
38
|
+
const hash = crypto.createHmac('sha512', secret).update(rawBody).digest();
|
|
39
|
+
return !(!/^[0-9a-f]{128}$/.test(signature) || !crypto.timingSafeEqual(hash, Buffer.from(signature, 'hex')));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export async function isPayloadValid(request: Request, rawBody: Buffer<ArrayBuffer>, secret: string) {
|
|
44
|
+
const paystackSignature = request.headers.get('paystack-signature')
|
|
45
|
+
const xpaystackSignature = request.headers.get('x-paystack-signature')
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if (paystackSignature) {
|
|
49
|
+
return !!verifyPaystackSignature(rawBody, paystackSignature, [secret])
|
|
50
|
+
} else if (xpaystackSignature) {
|
|
51
|
+
return verifyXPaystackSignature(rawBody, xpaystackSignature, secret)
|
|
52
|
+
} else {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "commonjs",
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
"types": ["node"],
|
|
13
|
+
// For nodejs:
|
|
14
|
+
"lib": ["esnext"],
|
|
15
|
+
// "types": ["node"],
|
|
16
|
+
// and npm install -D @types/node
|
|
17
|
+
|
|
18
|
+
// Other Outputs
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"declaration": true,
|
|
21
|
+
"declarationMap": true,
|
|
22
|
+
|
|
23
|
+
// Stricter Typechecking Options
|
|
24
|
+
"noUncheckedIndexedAccess": true,
|
|
25
|
+
"exactOptionalPropertyTypes": true,
|
|
26
|
+
|
|
27
|
+
// Style Options
|
|
28
|
+
// "noImplicitReturns": true,
|
|
29
|
+
// "noImplicitOverride": true,
|
|
30
|
+
// "noUnusedLocals": true,
|
|
31
|
+
// "noUnusedParameters": true,
|
|
32
|
+
// "noFallthroughCasesInSwitch": true,
|
|
33
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
34
|
+
|
|
35
|
+
// Recommended Options
|
|
36
|
+
"strict": true,
|
|
37
|
+
"jsx": "react-jsx",
|
|
38
|
+
"verbatimModuleSyntax": false,
|
|
39
|
+
"isolatedModules": true,
|
|
40
|
+
"noUncheckedSideEffectImports": true,
|
|
41
|
+
"moduleDetection": "force",
|
|
42
|
+
"skipLibCheck": true,
|
|
43
|
+
}
|
|
44
|
+
}
|