- Docs
- Platform
Authentication and request signing
Secret and publishable keys, and how live requests are signed.
Every request carries an API key. Secret keys stay on your server, publishable keys go in the browser, and live keys also sign each request with a separate secret.
Key types
Section titled “Key types”The prefix tells you what a key is and where it may live. A test key works only against the sandbox and a live key only against production. They are separate systems, so a key from one is unknown to the other.
| Prefix | Kind | Where it goes |
|---|---|---|
myela_sk_test_ |
Secret, test | Your server, against the sandbox. Signing is optional unless the key was issued to require it. |
myela_sk_live_ |
Secret, live | Your server, against production. Every request must be signed. |
myela_pk_test_ / myela_pk_live_ |
Publishable | The browser. It can create a checkout session from an allowed origin and nothing else. |
myela_sign_… |
Signing secret | Your server. The HMAC key for request signing. |
A secret key is shown once, when it’s issued. Myela stores only a hash, so a lost key can’t be recovered: revoke it and issue another. Revoking takes effect immediately. The publishable key stays visible in your account under Settings, then API keys. You can rotate it on its own, but every page that embeds the old one stops working.
Send the key
Section titled “Send the key”Put the key in the Authorization header as a Bearer token. Any problem with the key, whether it’s missing, malformed, revoked, or sent to the wrong environment, returns 401 authentication_failed with the same message, Missing or invalid API key., so the response never reveals which part was wrong.
curl https://payments-api-sandbox.merchantservicedepot.com/v1/capabilities \
-H "Authorization: Bearer myela_sk_test_…"Publishable keys in the browser
Section titled “Publishable keys in the browser”A publishable key can call one endpoint, POST /v1/checkout_sessions, the call Myela Elements makes from your page. Myela accepts it only when the browser’s Origin header matches the key’s allow-list. See Myela Elements for the browser side.
| Rule | Value |
|---|---|
max origins |
20 per key. |
wildcards |
Refused. List each origin. |
scheme |
https only. http is allowed for localhost, 127.0.0.1, and [::1], and only on test keys. |
matching |
Exact match on the origin: scheme, host, and port. No path, no trailing slash, no default port. |
empty list |
Matches nothing, so every request is refused. |
rejection |
401, including a request with no Origin header. |
Sign a request
Section titled “Sign a request”Live keys must sign every request. A test key needs a signature only if it was issued to require one. The test keys you issue in your account don’t require it, so to rehearse signing in the sandbox, ask Myela for a test key that does. A signature is an HMAC-SHA256 of a canonical string, keyed with your signing secret and sent in one header:
Myela-Signature: t=<unix seconds>,n=<nonce>,v1=<hex hmac>The canonical string is six lines joined by \n, with no trailing newline. v1 is the HMAC of that string as 64 lowercase hex characters.
| Line | Value |
|---|---|
1. Scheme |
The literal MYELA-HMAC-SHA256-V1. |
2. Method |
Uppercased, for example POST. |
3. Target |
The path and query exactly as you send them. Myela doesn’t reorder or re-encode anything. |
4. Timestamp |
The t value: unix seconds, the same number as in the header. |
5. Nonce |
The n value: up to 128 characters from A-Z, a-z, 0-9, and _ . : - |
6. Body hash |
Lowercase hex SHA-256 of the raw body bytes. An empty body hashes to e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. |
- The timestamp must be within 300 seconds of Myela’s clock, in either direction.
- Each nonce works once per key. Myela records it after the signature checks out, and a second use is refused.
- Hash the raw bytes you send. Parsing JSON and serializing it again doesn’t give you the same bytes, so serialize the body once, then sign and send that exact string.
- If anything between you and Myela rewrites the path or query, the signature won’t match.
import { createHash, createHmac, randomUUID } from 'node:crypto';
function signHeaders(secret: string, method: string, target: string, body: string) {
const t = Math.floor(Date.now() / 1000);
const n = randomUUID();
const canonical = ['MYELA-HMAC-SHA256-V1', method.toUpperCase(), target, String(t), n,
createHash('sha256').update(body, 'utf8').digest('hex')].join('\n');
const v1 = createHmac('sha256', secret).update(canonical, 'utf8').digest('hex');
return { 'Myela-Signature': `t=${t},n=${n},v1=${v1}` };
}
// Serialize the body ONCE; sign and send that exact string. target = path + query as sent.Test vector
Section titled “Test vector”Check your signer against these inputs. It should produce exactly this body hash and signature.
secret myela_sign_vector_secret
method POST
target /v1/payments?limit=10
timestamp 1785200000
nonce 01J8Z5N9Q7KDXV
body {"amount":4999,"currency":"USD"}
body sha256 e0f4cae0d29a27bfcbdfabd0530bfc8f2d45822ffc4f95aae24ab5e5f0bc80df
signature 6854e2b5980d5598cda2035e3cebb5a8b08dec3f1be81fb9450e1c9ad69bcb68Let the SDK sign
Section titled “Let the SDK sign”@myela/payments signs requests when you pass signingSecret to the client. Keys that require signing need it, and keys that don’t ignore it, so pass it everywhere and the code you test is the code you ship.
import { Myela } from '@myela/payments';
const myela = new Myela({
apiKey: process.env.MYELA_API_KEY!,
baseUrl: process.env.MYELA_API_BASE_URL!,
// Required by keys that enforce signing, ignored by keys that don't.
signingSecret: process.env.MYELA_SIGNING_SECRET,
});MYELA_API_KEY=myela_sk_test_…
MYELA_API_BASE_URL=https://payments-api-sandbox.merchantservicedepot.com
MYELA_SIGNING_SECRET=myela_sign_…A key that doesn’t require signing never checks the signature. A wrong signingSecret goes unnoticed on an ordinary test key and fails on the first live request. Test with a signing-required test key before you switch. See Go live.
When a signature fails
Section titled “When a signature fails”Every signing failure returns 401 authentication_failed. The message names the cause, but branch on the code, not the message.
| Cause | What happened |
|---|---|
Missing |
The key requires signing and the request had no Myela-Signature header. |
Malformed |
The header couldn’t be parsed. Each of t, n, and v1 must appear exactly once. |
Stale |
The timestamp is more than 300 seconds from Myela’s clock. Check your server’s clock. |
Mismatch |
The signature didn’t cover the exact method, path and query, timestamp, nonce, and body that arrived. |
Replayed |
The nonce was already used with this key. Generate a new nonce and timestamp per request. |
More on the error shape in Errors.