{
  "info": {
    "_postman_id": "b6a3f1d2-6c0e-4e8a-9a51-5b0a1b0a0001",
    "name": "BALBOA market-maker API",
    "description": "Every request is signed for you by the collection's pre-request script: the canonical string of the [integration guide](https://app.balboacorp.xyz/docs/market-maker-api#authentication) and Ed25519 — the same code the API verifies with. Your private key never leaves Postman: it signs here.\n\n**Set up**\n\n1. Set these, in an environment of your own (best) or the collection's Variables:\n   - `baseUrl` — the API host: filled in with the one the site you downloaded this from serves. BALBOA tells you if it changes.\n   - `keyId` — your key id: `bk_live_…`, or `bk_test_…` in the sandbox.\n   - `privateKey` — your private key: the whole PEM file `openssl genpkey -algorithm ed25519` wrote, pasted as one value, or its 32 bytes in base64 or hex. Make it a **secret**, and keep it in the **current value** only: current values stay on your machine and are never synced or shared.\n2. Send **Clock › Server time** first. It needs no signature, says whether your clock is right, and shows the address you call from — which must be in your key's allowlist.\n\n**What the script does**\n\n- Signs the method, path, query, timestamp, a new nonce, your key id, the `Idempotency-Key`, the `Content-Type` and the body's SHA-256.\n- Gives every `POST` an `Idempotency-Key`: the one you set on the request (enable the header), or a new one for each send. To retry a mint or a redemption safely, set your own and send it again.\n- Sends `Content-Type: application/json` with a body.\n- Resolves your variables once and sends exactly what it signed.\n\nRedirects are not followed: a signed request is never sent anywhere else. Each send is a new request with a new nonce.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Clock",
      "item": [
        {
          "name": "Server time",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/time",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "time"
              ]
            },
            "description": "Unsigned. The server's clock and the address it sees you call from (`your_address`, which must be in your key's allowlist). [Clock sync](https://app.balboacorp.xyz/docs/market-maker-api#clock-sync)"
          }
        }
      ]
    },
    {
      "name": "Account",
      "item": [
        {
          "name": "Account",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/account",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "account"
              ]
            },
            "description": "Scope `read`. The key you signed with, your account, its limits and today's use. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1account)"
          }
        },
        {
          "name": "Balances",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/balances",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "balances"
              ]
            },
            "description": "Scope `read`. The settlement wallet's BALBOA1. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1balances)"
          }
        },
        {
          "name": "Settlement",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/settlement",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "settlement"
              ]
            },
            "description": "Scope `read`. Where money goes in and out — your redemption destinations, with their ids — and the terms. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1settlement)"
          }
        }
      ]
    },
    {
      "name": "Transactions",
      "item": [
        {
          "name": "Transactions",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/transactions?limit=25",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "transactions"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "25",
                  "description": "1–100, default 25."
                },
                {
                  "key": "cursor",
                  "value": "",
                  "description": "`next_cursor` from the previous page.",
                  "disabled": true
                },
                {
                  "key": "kind",
                  "value": "deposit,mint_order,redemption,payment",
                  "description": "Comma-separated; default all.",
                  "disabled": true
                },
                {
                  "key": "updated_since",
                  "value": "2026-01-01T00:00:00.000Z",
                  "description": "Only those whose `updated_at` is at or after this ISO 8601 UTC time.",
                  "disabled": true
                }
              ]
            },
            "description": "Scope `read`. Everything, newest first, a page at a time. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1transactions)"
          }
        },
        {
          "name": "Transaction",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/transactions/:ref",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "transactions",
                ":ref"
              ],
              "variable": [
                {
                  "key": "ref",
                  "value": "deposit:12",
                  "description": "A `ref` from the list: `deposit:12`, `mint_order:42`, `redemption:7`."
                }
              ]
            },
            "description": "Scope `read`. One transaction by its `ref`. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1transactionsref)"
          }
        }
      ]
    },
    {
      "name": "Mint orders",
      "item": [
        {
          "name": "Make a mint order",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "",
                "description": "Set your own to retry a request safely: each send otherwise gets a new one.",
                "disabled": true
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": \"50000.00\",\n  \"wallet\": \"settlement\",\n  \"chain\": \"ethereum\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/mint-orders",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "mint-orders"
              ]
            },
            "description": "Scope `mint`. An instruction, not a mint: send exactly `deposit.amount` USDT from one of `deposit.source_addresses` to `deposit.address` before `deposit.send_by`. `amount` is a decimal string; `wallet` is `\"settlement\"` or one of your clients' ids; `chain` is `\"ethereum\"` (the default) or `\"solana\"`. [Minting](https://app.balboacorp.xyz/docs/market-maker-api#minting)"
          }
        },
        {
          "name": "Mint orders",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/mint-orders?limit=25",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "mint-orders"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "25",
                  "description": "1–100, default 25."
                },
                {
                  "key": "cursor",
                  "value": "",
                  "description": "`next_cursor` from the previous page.",
                  "disabled": true
                },
                {
                  "key": "status",
                  "value": "awaiting_transfer,confirming",
                  "description": "Comma-separated statuses.",
                  "disabled": true
                },
                {
                  "key": "key_id",
                  "value": "",
                  "description": "Only those made with this key of yours.",
                  "disabled": true
                },
                {
                  "key": "updated_since",
                  "value": "2026-01-01T00:00:00.000Z",
                  "description": "Only those whose `updated_at` is at or after this ISO 8601 UTC time.",
                  "disabled": true
                }
              ]
            },
            "description": "Scope `read`. Your mint orders, newest first. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1mint-orders)"
          }
        },
        {
          "name": "Mint order",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/mint-orders/:id",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "mint-orders",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "42",
                  "description": "The order's `id`."
                }
              ]
            },
            "description": "Scope `read`. One of your orders, as it stands. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1mint-ordersid)"
          }
        },
        {
          "name": "Cancel a mint order",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "",
                "description": "Set your own to retry a request safely: each send otherwise gets a new one.",
                "disabled": true
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/mint-orders/:id/cancel",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "mint-orders",
                ":id",
                "cancel"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "42",
                  "description": "The order's `id`."
                }
              ]
            },
            "description": "Scope `mint`. Cancels an order still waiting for its transfer. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#post-apimmv1mint-ordersidcancel)"
          }
        }
      ]
    },
    {
      "name": "Redemptions",
      "item": [
        {
          "name": "Redeem",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "",
                "description": "Set your own to retry a request safely: each send otherwise gets a new one.",
                "disabled": true
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": \"25000.00\",\n  \"destination\": 4\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/redemptions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "redemptions"
              ]
            },
            "description": "Scope `redeem`. BALBOA1 back to USDT, paid to one of your destinations: its `id` from Settlement, or its exact address — on its own chain, the destination's. `amount` is a decimal string. [Redeeming](https://app.balboacorp.xyz/docs/market-maker-api#redeeming)"
          }
        },
        {
          "name": "Redemptions",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/redemptions?limit=25",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "redemptions"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "25",
                  "description": "1–100, default 25."
                },
                {
                  "key": "cursor",
                  "value": "",
                  "description": "`next_cursor` from the previous page.",
                  "disabled": true
                },
                {
                  "key": "status",
                  "value": "in_review,queued",
                  "description": "Comma-separated statuses.",
                  "disabled": true
                },
                {
                  "key": "key_id",
                  "value": "",
                  "description": "Only those made with this key of yours.",
                  "disabled": true
                },
                {
                  "key": "updated_since",
                  "value": "2026-01-01T00:00:00.000Z",
                  "description": "Only those whose `updated_at` is at or after this ISO 8601 UTC time.",
                  "disabled": true
                }
              ]
            },
            "description": "Scope `read`. Your redemptions, newest first. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1redemptionsid-get-apimmv1redemptions)"
          }
        },
        {
          "name": "Redemption",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/redemptions/:id",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "redemptions",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "7",
                  "description": "The redemption's `id`."
                }
              ]
            },
            "description": "Scope `read`. One of your redemptions, as it stands. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#get-apimmv1redemptionsid-get-apimmv1redemptions)"
          }
        },
        {
          "name": "Cancel a redemption",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "",
                "description": "Set your own to retry a request safely: each send otherwise gets a new one.",
                "disabled": true
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/mm/v1/redemptions/:id/cancel",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "mm",
                "v1",
                "redemptions",
                ":id",
                "cancel"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "7",
                  "description": "The redemption's `id`."
                }
              ]
            },
            "description": "Scope `redeem`. Cancels a redemption before its BALBOA1 is settled. [Guide](https://app.balboacorp.xyz/docs/market-maker-api#post-apimmv1redemptionsidcancel)"
          }
        }
      ]
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Signs every request for the BALBOA market-maker API (the collection's description says how to set it up).",
          "// BALBOA_SIGN is the API's own canonical string and Ed25519 (@noble/curves), bundled: Postman has no Ed25519.",
          "\"use strict\";var BALBOA_SIGN=(()=>{var qt=Object.defineProperty;var dn=Object.getOwnPropertyDescriptor;var mn=Object.getOwnPropertyNames;var hn=Object.prototype.hasOwnProperty;var pn=(t,e)=>{for(var n in e)qt(t,n,{get:e[n],enumerable:!0})},yn=(t,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of mn(e))!hn.call(t,r)&&r!==n&&qt(t,r,{get:()=>e[r],enumerable:!(o=dn(e,r))||o.enumerable});return t};var gn=t=>yn(qt({},\"__esModule\",{value:!0}),t);var lo={};pn(lo,{fromBase64:()=>ln,seedOf:()=>un,signRequest:()=>co,toBase64:()=>fn,utf8:()=>de});var it=typeof globalThis==\"object\"&&\"crypto\"in globalThis?globalThis.crypto:void 0;function at(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name===\"Uint8Array\"}function Ht(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(\"positive integer expected, got \"+t)}function D(t,...e){if(!at(t))throw new Error(\"Uint8Array expected\");if(e.length>0&&!e.includes(t.length))throw new Error(\"Uint8Array expected of length \"+e+\", got length=\"+t.length)}function Dt(t,e=!0){if(t.destroyed)throw new Error(\"Hash instance has been destroyed\");if(e&&t.finished)throw new Error(\"Hash#digest() has already been called\")}function pe(t,e){D(t);let n=e.outputLen;if(t.length<n)throw new Error(\"digestInto() expects output buffer of length at least \"+n)}function ct(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function St(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function $(t,e){return t<<32-e|t>>>e}var ye=typeof Uint8Array.from([]).toHex==\"function\"&&typeof Uint8Array.fromHex==\"function\",xn=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,\"0\"));function P(t){if(D(t),ye)return t.toHex();let e=\"\";for(let n=0;n<t.length;n++)e+=xn[t[n]];return e}var Y={_0:48,_9:57,A:65,F:70,a:97,f:102};function he(t){if(t>=Y._0&&t<=Y._9)return t-Y._0;if(t>=Y.A&&t<=Y.F)return t-(Y.A-10);if(t>=Y.a&&t<=Y.f)return t-(Y.a-10)}function dt(t){if(typeof t!=\"string\")throw new Error(\"hex string expected, got \"+typeof t);if(ye)return Uint8Array.fromHex(t);let e=t.length,n=e/2;if(e%2)throw new Error(\"hex string expected, got unpadded hex of length \"+e);let o=new Uint8Array(n);for(let r=0,s=0;r<n;r++,s+=2){let a=he(t.charCodeAt(s)),c=he(t.charCodeAt(s+1));if(a===void 0||c===void 0){let i=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character \"'+i+'\" at index '+s)}o[r]=a*16+c}return o}function $t(t){if(typeof t!=\"string\")throw new Error(\"string expected\");return new Uint8Array(new TextEncoder().encode(t))}function Kt(t){return typeof t==\"string\"&&(t=$t(t)),D(t),t}function mt(...t){let e=0;for(let o=0;o<t.length;o++){let r=t[o];D(r),e+=r.length}let n=new Uint8Array(e);for(let o=0,r=0;o<t.length;o++){let s=t[o];n.set(s,r),r+=s.length}return n}var vt=class{};function Pt(t){let e=o=>t().update(Kt(o)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Gt(t=32){if(it&&typeof it.getRandomValues==\"function\")return it.getRandomValues(new Uint8Array(t));if(it&&typeof it.randomBytes==\"function\")return Uint8Array.from(it.randomBytes(t));throw new Error(\"crypto.getRandomValues must be defined\")}function _n(t,e,n,o){if(typeof t.setBigUint64==\"function\")return t.setBigUint64(e,n,o);let r=BigInt(32),s=BigInt(4294967295),a=Number(n>>r&s),c=Number(n&s),i=o?4:0,u=o?0:4;t.setUint32(e+i,a,o),t.setUint32(e+u,c,o)}function ge(t,e,n){return t&e^~t&n}function xe(t,e,n){return t&e^t&n^e&n}var yt=class extends vt{constructor(e,n,o,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=o,this.isLE=r,this.buffer=new Uint8Array(e),this.view=St(this.buffer)}update(e){Dt(this),e=Kt(e),D(e);let{view:n,buffer:o,blockLen:r}=this,s=e.length;for(let a=0;a<s;){let c=Math.min(r-this.pos,s-a);if(c===r){let i=St(e);for(;r<=s-a;a+=r)this.process(i,a);continue}o.set(e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===r&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Dt(this),pe(e,this),this.finished=!0;let{buffer:n,view:o,blockLen:r,isLE:s}=this,{pos:a}=this;n[a++]=128,ct(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(o,0),a=0);for(let f=a;f<r;f++)n[f]=0;_n(o,r-8,BigInt(this.length*8),s),this.process(o,0);let c=St(e),i=this.outputLen;if(i%4)throw new Error(\"_sha2: outputLen should be aligned to 32bit\");let u=i/4,h=this.get();if(u>h.length)throw new Error(\"_sha2: outputLen bigger than state\");for(let f=0;f<u;f++)c.setUint32(4*f,h[f],s)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let o=e.slice(0,n);return this.destroy(),o}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:o,length:r,finished:s,destroyed:a,pos:c}=this;return e.destroyed=a,e.finished=s,e.length=r,e.pos=c,r%n&&e.buffer.set(o),e}clone(){return this._cloneInto()}},V=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var C=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Tt=BigInt(4294967295),_e=BigInt(32);function bn(t,e=!1){return e?{h:Number(t&Tt),l:Number(t>>_e&Tt)}:{h:Number(t>>_e&Tt)|0,l:Number(t&Tt)|0}}function be(t,e=!1){let n=t.length,o=new Uint32Array(n),r=new Uint32Array(n);for(let s=0;s<n;s++){let{h:a,l:c}=bn(t[s],e);[o[s],r[s]]=[a,c]}return[o,r]}var Zt=(t,e,n)=>t>>>n,Yt=(t,e,n)=>t<<32-n|e>>>n,lt=(t,e,n)=>t>>>n|e<<32-n,ft=(t,e,n)=>t<<32-n|e>>>n,gt=(t,e,n)=>t<<64-n|e>>>n-32,xt=(t,e,n)=>t>>>n-32|e<<64-n;function G(t,e,n,o){let r=(e>>>0)+(o>>>0);return{h:t+n+(r/2**32|0)|0,l:r|0}}var we=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Be=(t,e,n,o)=>e+n+o+(t/2**32|0)|0,Ae=(t,e,n,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ee=(t,e,n,o,r)=>e+n+o+r+(t/2**32|0)|0,ke=(t,e,n,o,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0)+(r>>>0),ve=(t,e,n,o,r,s)=>e+n+o+r+s+(t/2**32|0)|0;var Bn=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),J=new Uint32Array(64),It=class extends yt{constructor(e=32){super(64,e,8,!1),this.A=V[0]|0,this.B=V[1]|0,this.C=V[2]|0,this.D=V[3]|0,this.E=V[4]|0,this.F=V[5]|0,this.G=V[6]|0,this.H=V[7]|0}get(){let{A:e,B:n,C:o,D:r,E:s,F:a,G:c,H:i}=this;return[e,n,o,r,s,a,c,i]}set(e,n,o,r,s,a,c,i){this.A=e|0,this.B=n|0,this.C=o|0,this.D=r|0,this.E=s|0,this.F=a|0,this.G=c|0,this.H=i|0}process(e,n){for(let f=0;f<16;f++,n+=4)J[f]=e.getUint32(n,!1);for(let f=16;f<64;f++){let l=J[f-15],p=J[f-2],m=$(l,7)^$(l,18)^l>>>3,x=$(p,17)^$(p,19)^p>>>10;J[f]=x+J[f-7]+m+J[f-16]|0}let{A:o,B:r,C:s,D:a,E:c,F:i,G:u,H:h}=this;for(let f=0;f<64;f++){let l=$(c,6)^$(c,11)^$(c,25),p=h+l+ge(c,i,u)+Bn[f]+J[f]|0,x=($(o,2)^$(o,13)^$(o,22))+xe(o,r,s)|0;h=u,u=i,i=c,c=a+p|0,a=s,s=r,r=o,o=p+x|0}o=o+this.A|0,r=r+this.B|0,s=s+this.C|0,a=a+this.D|0,c=c+this.E|0,i=i+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(o,r,s,a,c,i,u,h)}roundClean(){ct(J)}destroy(){this.set(0,0,0,0,0,0,0,0),ct(this.buffer)}};var Se=be([\"0x428a2f98d728ae22\",\"0x7137449123ef65cd\",\"0xb5c0fbcfec4d3b2f\",\"0xe9b5dba58189dbbc\",\"0x3956c25bf348b538\",\"0x59f111f1b605d019\",\"0x923f82a4af194f9b\",\"0xab1c5ed5da6d8118\",\"0xd807aa98a3030242\",\"0x12835b0145706fbe\",\"0x243185be4ee4b28c\",\"0x550c7dc3d5ffb4e2\",\"0x72be5d74f27b896f\",\"0x80deb1fe3b1696b1\",\"0x9bdc06a725c71235\",\"0xc19bf174cf692694\",\"0xe49b69c19ef14ad2\",\"0xefbe4786384f25e3\",\"0x0fc19dc68b8cd5b5\",\"0x240ca1cc77ac9c65\",\"0x2de92c6f592b0275\",\"0x4a7484aa6ea6e483\",\"0x5cb0a9dcbd41fbd4\",\"0x76f988da831153b5\",\"0x983e5152ee66dfab\",\"0xa831c66d2db43210\",\"0xb00327c898fb213f\",\"0xbf597fc7beef0ee4\",\"0xc6e00bf33da88fc2\",\"0xd5a79147930aa725\",\"0x06ca6351e003826f\",\"0x142929670a0e6e70\",\"0x27b70a8546d22ffc\",\"0x2e1b21385c26c926\",\"0x4d2c6dfc5ac42aed\",\"0x53380d139d95b3df\",\"0x650a73548baf63de\",\"0x766a0abb3c77b2a8\",\"0x81c2c92e47edaee6\",\"0x92722c851482353b\",\"0xa2bfe8a14cf10364\",\"0xa81a664bbc423001\",\"0xc24b8b70d0f89791\",\"0xc76c51a30654be30\",\"0xd192e819d6ef5218\",\"0xd69906245565a910\",\"0xf40e35855771202a\",\"0x106aa07032bbd1b8\",\"0x19a4c116b8d2d0c8\",\"0x1e376c085141ab53\",\"0x2748774cdf8eeb99\",\"0x34b0bcb5e19b48a8\",\"0x391c0cb3c5c95a63\",\"0x4ed8aa4ae3418acb\",\"0x5b9cca4f7763e373\",\"0x682e6ff3d6b2b8a3\",\"0x748f82ee5defb2fc\",\"0x78a5636f43172f60\",\"0x84c87814a1f0ab72\",\"0x8cc702081a6439ec\",\"0x90befffa23631e28\",\"0xa4506cebde82bde9\",\"0xbef9a3f7b2c67915\",\"0xc67178f2e372532b\",\"0xca273eceea26619c\",\"0xd186b8c721c0c207\",\"0xeada7dd6cde0eb1e\",\"0xf57d4f7fee6ed178\",\"0x06f067aa72176fba\",\"0x0a637dc5a2c898a6\",\"0x113f9804bef90dae\",\"0x1b710b35131c471b\",\"0x28db77f523047d84\",\"0x32caab7b40c72493\",\"0x3c9ebe0a15c9bebc\",\"0x431d67c49c100d4c\",\"0x4cc5d4becb3e42b6\",\"0x597f299cfc657e2a\",\"0x5fcb6fab3ad6faec\",\"0x6c44198c4a475817\"].map(t=>BigInt(t))),An=Se[0],En=Se[1],tt=new Uint32Array(80),et=new Uint32Array(80),Vt=class extends yt{constructor(e=64){super(128,e,16,!1),this.Ah=C[0]|0,this.Al=C[1]|0,this.Bh=C[2]|0,this.Bl=C[3]|0,this.Ch=C[4]|0,this.Cl=C[5]|0,this.Dh=C[6]|0,this.Dl=C[7]|0,this.Eh=C[8]|0,this.El=C[9]|0,this.Fh=C[10]|0,this.Fl=C[11]|0,this.Gh=C[12]|0,this.Gl=C[13]|0,this.Hh=C[14]|0,this.Hl=C[15]|0}get(){let{Ah:e,Al:n,Bh:o,Bl:r,Ch:s,Cl:a,Dh:c,Dl:i,Eh:u,El:h,Fh:f,Fl:l,Gh:p,Gl:m,Hh:x,Hl:w}=this;return[e,n,o,r,s,a,c,i,u,h,f,l,p,m,x,w]}set(e,n,o,r,s,a,c,i,u,h,f,l,p,m,x,w){this.Ah=e|0,this.Al=n|0,this.Bh=o|0,this.Bl=r|0,this.Ch=s|0,this.Cl=a|0,this.Dh=c|0,this.Dl=i|0,this.Eh=u|0,this.El=h|0,this.Fh=f|0,this.Fl=l|0,this.Gh=p|0,this.Gl=m|0,this.Hh=x|0,this.Hl=w|0}process(e,n){for(let y=0;y<16;y++,n+=4)tt[y]=e.getUint32(n),et[y]=e.getUint32(n+=4);for(let y=16;y<80;y++){let A=tt[y-15]|0,k=et[y-15]|0,I=lt(A,k,1)^lt(A,k,8)^Zt(A,k,7),M=ft(A,k,1)^ft(A,k,8)^Yt(A,k,7),E=tt[y-2]|0,g=et[y-2]|0,_=lt(E,g,19)^gt(E,g,61)^Zt(E,g,6),B=ft(E,g,19)^xt(E,g,61)^Yt(E,g,6),v=Ae(M,B,et[y-7],et[y-16]),T=Ee(v,I,_,tt[y-7],tt[y-16]);tt[y]=T|0,et[y]=v|0}let{Ah:o,Al:r,Bh:s,Bl:a,Ch:c,Cl:i,Dh:u,Dl:h,Eh:f,El:l,Fh:p,Fl:m,Gh:x,Gl:w,Hh:d,Hl:b}=this;for(let y=0;y<80;y++){let A=lt(f,l,14)^lt(f,l,18)^gt(f,l,41),k=ft(f,l,14)^ft(f,l,18)^xt(f,l,41),I=f&p^~f&x,M=l&m^~l&w,E=ke(b,k,M,En[y],et[y]),g=ve(E,d,A,I,An[y],tt[y]),_=E|0,B=lt(o,r,28)^gt(o,r,34)^gt(o,r,39),v=ft(o,r,28)^xt(o,r,34)^xt(o,r,39),T=o&s^o&c^s&c,S=r&a^r&i^a&i;d=x|0,b=w|0,x=p|0,w=m|0,p=f|0,m=l|0,{h:f,l}=G(u|0,h|0,g|0,_|0),u=c|0,h=i|0,c=s|0,i=a|0,s=o|0,a=r|0;let L=we(_,v,S);o=Be(L,g,B,T),r=L|0}({h:o,l:r}=G(this.Ah|0,this.Al|0,o|0,r|0)),{h:s,l:a}=G(this.Bh|0,this.Bl|0,s|0,a|0),{h:c,l:i}=G(this.Ch|0,this.Cl|0,c|0,i|0),{h:u,l:h}=G(this.Dh|0,this.Dl|0,u|0,h|0),{h:f,l}=G(this.Eh|0,this.El|0,f|0,l|0),{h:p,l:m}=G(this.Fh|0,this.Fl|0,p|0,m|0),{h:x,l:w}=G(this.Gh|0,this.Gl|0,x|0,w|0),{h:d,l:b}=G(this.Hh|0,this.Hl|0,d|0,b|0),this.set(o,r,s,a,c,i,u,h,f,l,p,m,x,w,d,b)}roundClean(){ct(tt,et)}destroy(){ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Te=Pt(()=>new It);var Ie=Pt(()=>new Vt);var Wt=BigInt(0),Xt=BigInt(1);function Mt(t,e=\"\"){if(typeof t!=\"boolean\"){let n=e&&`\"${e}\"`;throw new Error(n+\"expected boolean, got type=\"+typeof t)}return t}function _t(t,e,n=\"\"){let o=at(t),r=t?.length,s=e!==void 0;if(!o||s&&r!==e){let a=n&&`\"${n}\" `,c=s?` of length ${e}`:\"\",i=o?`length=${r}`:`type=${typeof t}`;throw new Error(a+\"expected Uint8Array\"+c+\", got \"+i)}return t}function Me(t){if(typeof t!=\"string\")throw new Error(\"hex string expected, got \"+typeof t);return t===\"\"?Wt:BigInt(\"0x\"+t)}function Oe(t){return Me(P(t))}function nt(t){return D(t),Me(P(Uint8Array.from(t).reverse()))}function Ft(t,e){return dt(t.toString(16).padStart(e*2,\"0\"))}function Le(t,e){return Ft(t,e).reverse()}function H(t,e,n){let o;if(typeof e==\"string\")try{o=dt(e)}catch(s){throw new Error(t+\" must be hex string or Uint8Array, cause: \"+s)}else if(at(e))o=Uint8Array.from(e);else throw new Error(t+\" must be hex string or Uint8Array\");let r=o.length;if(typeof n==\"number\"&&r!==n)throw new Error(t+\" of length \"+n+\" expected, got \"+r);return o}function Ne(t,e){if(t.length!==e.length)return!1;let n=0;for(let o=0;o<t.length;o++)n|=t[o]^e[o];return n===0}function zt(t){return Uint8Array.from(t)}var jt=t=>typeof t==\"bigint\"&&Wt<=t;function kn(t,e,n){return jt(t)&&jt(e)&&jt(n)&&e<=t&&t<n}function Qt(t,e,n,o){if(!kn(e,n,o))throw new Error(\"expected valid \"+t+\": \"+n+\" <= n < \"+o+\", got \"+e)}function Ce(t){let e;for(e=0;t>Wt;t>>=Xt,e+=1);return e}var bt=t=>(Xt<<BigInt(t))-Xt;function wt(t,e,n={}){if(!t||typeof t!=\"object\")throw new Error(\"expected valid options object\");function o(r,s,a){let c=t[r];if(a&&c===void 0)return;let i=typeof c;if(i!==s||c===null)throw new Error(`param \"${r}\" is invalid: expected ${s}, got ${i}`)}Object.entries(e).forEach(([r,s])=>o(r,s,!1)),Object.entries(n).forEach(([r,s])=>o(r,s,!0))}var Jt=()=>{throw new Error(\"not implemented\")};function te(t){let e=new WeakMap;return(n,...o)=>{let r=e.get(n);if(r!==void 0)return r;let s=t(n,...o);return e.set(n,s),s}}var U=BigInt(0),R=BigInt(1),ut=BigInt(2),qe=BigInt(3),He=BigInt(4),De=BigInt(5),vn=BigInt(7),$e=BigInt(8),Sn=BigInt(9),Ke=BigInt(16);function O(t,e){let n=t%e;return n>=U?n:e+n}function K(t,e,n){let o=t;for(;e-- >U;)o*=o,o%=n;return o}function Re(t,e){if(t===U)throw new Error(\"invert: expected non-zero number\");if(e<=U)throw new Error(\"invert: expected positive modulus, got \"+e);let n=O(t,e),o=e,r=U,s=R,a=R,c=U;for(;n!==U;){let u=o/n,h=o%n,f=r-a*u,l=s-c*u;o=n,n=h,r=a,s=c,a=f,c=l}if(o!==R)throw new Error(\"invert: does not exist\");return O(r,e)}function ee(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error(\"Cannot find square root\")}function Pe(t,e){let n=(t.ORDER+R)/He,o=t.pow(e,n);return ee(t,o,e),o}function Tn(t,e){let n=(t.ORDER-De)/$e,o=t.mul(e,ut),r=t.pow(o,n),s=t.mul(e,r),a=t.mul(t.mul(s,ut),r),c=t.mul(s,t.sub(a,t.ONE));return ee(t,c,e),c}function In(t){let e=X(t),n=Ge(t),o=n(e,e.neg(e.ONE)),r=n(e,o),s=n(e,e.neg(o)),a=(t+vn)/Ke;return(c,i)=>{let u=c.pow(i,a),h=c.mul(u,o),f=c.mul(u,r),l=c.mul(u,s),p=c.eql(c.sqr(h),i),m=c.eql(c.sqr(f),i);u=c.cmov(u,h,p),h=c.cmov(l,f,m);let x=c.eql(c.sqr(h),i),w=c.cmov(u,h,x);return ee(c,w,i),w}}function Ge(t){if(t<qe)throw new Error(\"sqrt is not defined for small field\");let e=t-R,n=0;for(;e%ut===U;)e/=ut,n++;let o=ut,r=X(t);for(;Ue(r,o)===1;)if(o++>1e3)throw new Error(\"Cannot find square root: probably non-prime P\");if(n===1)return Pe;let s=r.pow(o,e),a=(e+R)/ut;return function(i,u){if(i.is0(u))return u;if(Ue(i,u)!==1)throw new Error(\"Cannot find square root\");let h=n,f=i.mul(i.ONE,s),l=i.pow(u,e),p=i.pow(u,a);for(;!i.eql(l,i.ONE);){if(i.is0(l))return i.ZERO;let m=1,x=i.sqr(l);for(;!i.eql(x,i.ONE);)if(m++,x=i.sqr(x),m===h)throw new Error(\"Cannot find square root\");let w=R<<BigInt(h-m-1),d=i.pow(f,w);h=m,f=i.sqr(d),l=i.mul(l,f),p=i.mul(p,d)}return p}}function Mn(t){return t%He===qe?Pe:t%$e===De?Tn:t%Ke===Sn?In(t):Ge(t)}var j=(t,e)=>(O(t,e)&R)===R,On=[\"create\",\"isValid\",\"is0\",\"neg\",\"inv\",\"sqrt\",\"sqr\",\"eql\",\"add\",\"sub\",\"mul\",\"pow\",\"div\",\"addN\",\"subN\",\"mulN\",\"sqrN\"];function Ze(t){let e={ORDER:\"bigint\",MASK:\"bigint\",BYTES:\"number\",BITS:\"number\"},n=On.reduce((o,r)=>(o[r]=\"function\",o),e);return wt(t,n),t}function Ln(t,e,n){if(n<U)throw new Error(\"invalid exponent, negatives unsupported\");if(n===U)return t.ONE;if(n===R)return e;let o=t.ONE,r=e;for(;n>U;)n&R&&(o=t.mul(o,r)),r=t.sqr(r),n>>=R;return o}function Ot(t,e,n=!1){let o=new Array(e.length).fill(n?t.ZERO:void 0),r=e.reduce((a,c,i)=>t.is0(c)?a:(o[i]=a,t.mul(a,c)),t.ONE),s=t.inv(r);return e.reduceRight((a,c,i)=>t.is0(c)?a:(o[i]=t.mul(a,o[i]),t.mul(a,c)),s),o}function Ue(t,e){let n=(t.ORDER-R)/ut,o=t.pow(e,n),r=t.eql(o,t.ONE),s=t.eql(o,t.ZERO),a=t.eql(o,t.neg(t.ONE));if(!r&&!s&&!a)throw new Error(\"invalid Legendre symbol result\");return r?1:s?0:-1}function Ye(t,e){e!==void 0&&Ht(e);let n=e!==void 0?e:t.toString(2).length,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}function X(t,e,n=!1,o={}){if(t<=U)throw new Error(\"invalid field: expected ORDER > 0, got \"+t);let r,s,a=!1,c;if(typeof e==\"object\"&&e!=null){if(o.sqrt||n)throw new Error(\"cannot specify opts in two arguments\");let l=e;l.BITS&&(r=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE==\"boolean\"&&(n=l.isLE),typeof l.modFromBytes==\"boolean\"&&(a=l.modFromBytes),c=l.allowedLengths}else typeof e==\"number\"&&(r=e),o.sqrt&&(s=o.sqrt);let{nBitLength:i,nByteLength:u}=Ye(t,r);if(u>2048)throw new Error(\"invalid field: expected ORDER of <= 2048 bytes\");let h,f=Object.freeze({ORDER:t,isLE:n,BITS:i,BYTES:u,MASK:bt(i),ZERO:U,ONE:R,allowedLengths:c,create:l=>O(l,t),isValid:l=>{if(typeof l!=\"bigint\")throw new Error(\"invalid field element: expected bigint, got \"+typeof l);return U<=l&&l<t},is0:l=>l===U,isValidNot0:l=>!f.is0(l)&&f.isValid(l),isOdd:l=>(l&R)===R,neg:l=>O(-l,t),eql:(l,p)=>l===p,sqr:l=>O(l*l,t),add:(l,p)=>O(l+p,t),sub:(l,p)=>O(l-p,t),mul:(l,p)=>O(l*p,t),pow:(l,p)=>Ln(f,l,p),div:(l,p)=>O(l*Re(p,t),t),sqrN:l=>l*l,addN:(l,p)=>l+p,subN:(l,p)=>l-p,mulN:(l,p)=>l*p,inv:l=>Re(l,t),sqrt:s||(l=>(h||(h=Mn(t)),h(f,l))),toBytes:l=>n?Le(l,u):Ft(l,u),fromBytes:(l,p=!0)=>{if(c){if(!c.includes(l.length)||l.length>u)throw new Error(\"Field.fromBytes: expected \"+c+\" bytes, got \"+l.length);let x=new Uint8Array(u);x.set(l,n?0:x.length-l.length),l=x}if(l.length!==u)throw new Error(\"Field.fromBytes: expected \"+u+\" bytes, got \"+l.length);let m=n?nt(l):Oe(l);if(a&&(m=O(m,t)),!p&&!f.isValid(m))throw new Error(\"invalid field element: outside of range 0..ORDER\");return m},invertBatch:l=>Ot(f,l),cmov:(l,p,m)=>m?p:l});return Object.freeze(f)}var Lt=BigInt(0),se=BigInt(1);function Ve(t,e){let n=e.negate();return t?n:e}function Bt(t,e){let n=Ot(t.Fp,e.map(o=>o.Z));return e.map((o,r)=>t.fromAffine(o.toAffine(n[r])))}function Fe(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error(\"invalid window size, expected [1..\"+e+\"], got W=\"+t)}function ne(t,e){Fe(t,e);let n=Math.ceil(e/t)+1,o=2**(t-1),r=2**t,s=bt(t),a=BigInt(t);return{windows:n,windowSize:o,mask:s,maxNumber:r,shiftBy:a}}function je(t,e,n){let{windowSize:o,mask:r,maxNumber:s,shiftBy:a}=n,c=Number(t&r),i=t>>a;c>o&&(c-=s,i+=se);let u=e*o,h=u+Math.abs(c)-1,f=c===0,l=c<0,p=e%2!==0;return{nextN:i,offset:h,isZero:f,isNeg:l,isNegF:p,offsetF:u}}function Nn(t,e){if(!Array.isArray(t))throw new Error(\"array expected\");t.forEach((n,o)=>{if(!(n instanceof e))throw new Error(\"invalid point at index \"+o)})}function Cn(t,e){if(!Array.isArray(t))throw new Error(\"array of scalars expected\");t.forEach((n,o)=>{if(!e.isValid(n))throw new Error(\"invalid scalar at index \"+o)})}var oe=new WeakMap,ze=new WeakMap;function re(t){return ze.get(t)||1}function Xe(t){if(t!==Lt)throw new Error(\"invalid wNAF\")}var Nt=class{constructor(e,n){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,o=this.ZERO){let r=e;for(;n>Lt;)n&se&&(o=o.add(r)),r=r.double(),n>>=se;return o}precomputeWindow(e,n){let{windows:o,windowSize:r}=ne(n,this.bits),s=[],a=e,c=a;for(let i=0;i<o;i++){c=a,s.push(c);for(let u=1;u<r;u++)c=c.add(a),s.push(c);a=c.double()}return s}wNAF(e,n,o){if(!this.Fn.isValid(o))throw new Error(\"invalid scalar\");let r=this.ZERO,s=this.BASE,a=ne(e,this.bits);for(let c=0;c<a.windows;c++){let{nextN:i,offset:u,isZero:h,isNeg:f,isNegF:l,offsetF:p}=je(o,c,a);o=i,h?s=s.add(Ve(l,n[p])):r=r.add(Ve(f,n[u]))}return Xe(o),{p:r,f:s}}wNAFUnsafe(e,n,o,r=this.ZERO){let s=ne(e,this.bits);for(let a=0;a<s.windows&&o!==Lt;a++){let{nextN:c,offset:i,isZero:u,isNeg:h}=je(o,a,s);if(o=c,!u){let f=n[i];r=r.add(h?f.negate():f)}}return Xe(o),r}getPrecomputes(e,n,o){let r=oe.get(n);return r||(r=this.precomputeWindow(n,e),e!==1&&(typeof o==\"function\"&&(r=o(r)),oe.set(n,r))),r}cached(e,n,o){let r=re(e);return this.wNAF(r,this.getPrecomputes(r,e,o),n)}unsafe(e,n,o,r){let s=re(e);return s===1?this._unsafeLadder(e,n,r):this.wNAFUnsafe(s,this.getPrecomputes(s,e,o),n,r)}createCache(e,n){Fe(n,this.bits),ze.set(e,n),oe.delete(e)}hasCache(e){return re(e)!==1}};function Ct(t,e,n,o){Nn(n,t),Cn(o,e);let r=n.length,s=o.length;if(r!==s)throw new Error(\"arrays of points and scalars must have equal length\");let a=t.ZERO,c=Ce(BigInt(r)),i=1;c>12?i=c-3:c>4?i=c-2:c>0&&(i=2);let u=bt(i),h=new Array(Number(u)+1).fill(a),f=Math.floor((e.BITS-1)/i)*i,l=a;for(let p=f;p>=0;p-=i){h.fill(a);for(let x=0;x<s;x++){let w=o[x],d=Number(w>>BigInt(p)&u);h[d]=h[d].add(n[x])}let m=a;for(let x=h.length-1,w=a;x>0;x--)w=w.add(h[x]),m=m.add(w);if(l=l.add(m),p!==0)for(let x=0;x<i;x++)l=l.double()}return l}function We(t,e,n){if(e){if(e.ORDER!==t)throw new Error(\"Field.ORDER must match order: Fp == p, Fn == n\");return Ze(e),e}else return X(t,{isLE:n})}function Qe(t,e,n={},o){if(o===void 0&&(o=t===\"edwards\"),!e||typeof e!=\"object\")throw new Error(`expected valid ${t} CURVE object`);for(let i of[\"p\",\"n\",\"h\"]){let u=e[i];if(!(typeof u==\"bigint\"&&u>Lt))throw new Error(`CURVE.${i} must be positive bigint`)}let r=We(e.p,n.Fp,o),s=We(e.n,n.Fn,o),c=[\"Gx\",\"Gy\",\"a\",t===\"weierstrass\"?\"b\":\"d\"];for(let i of c)if(!r.isValid(e[i]))throw new Error(`CURVE.${i} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:r,Fn:s}}var ot=BigInt(0),N=BigInt(1),ie=BigInt(2),Rn=BigInt(8);function Un(t,e,n,o){let r=t.sqr(n),s=t.sqr(o),a=t.add(t.mul(e.a,r),s),c=t.add(t.ONE,t.mul(e.d,t.mul(r,s)));return t.eql(a,c)}function qn(t,e={}){let n=Qe(\"edwards\",t,e,e.FpFnLE),{Fp:o,Fn:r}=n,s=n.CURVE,{h:a}=s;wt(e,{},{uvRatio:\"function\"});let c=ie<<BigInt(r.BYTES*8)-N,i=w=>o.create(w),u=e.uvRatio||((w,d)=>{try{return{isValid:!0,value:o.sqrt(o.div(w,d))}}catch{return{isValid:!1,value:ot}}});if(!Un(o,s,s.Gx,s.Gy))throw new Error(\"bad curve params: generator point\");function h(w,d,b=!1){let y=b?N:ot;return Qt(\"coordinate \"+w,d,y,c),d}function f(w){if(!(w instanceof m))throw new Error(\"ExtendedPoint expected\")}let l=te((w,d)=>{let{X:b,Y:y,Z:A}=w,k=w.is0();d==null&&(d=k?Rn:o.inv(A));let I=i(b*d),M=i(y*d),E=o.mul(A,d);if(k)return{x:ot,y:N};if(E!==N)throw new Error(\"invZ was invalid\");return{x:I,y:M}}),p=te(w=>{let{a:d,d:b}=s;if(w.is0())throw new Error(\"bad point: ZERO\");let{X:y,Y:A,Z:k,T:I}=w,M=i(y*y),E=i(A*A),g=i(k*k),_=i(g*g),B=i(M*d),v=i(g*i(B+E)),T=i(_+i(b*i(M*E)));if(v!==T)throw new Error(\"bad point: equation left != right (1)\");let S=i(y*A),L=i(k*I);if(S!==L)throw new Error(\"bad point: equation left != right (2)\");return!0});class m{constructor(d,b,y,A){this.X=h(\"x\",d),this.Y=h(\"y\",b),this.Z=h(\"z\",y,!0),this.T=h(\"t\",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){if(d instanceof m)throw new Error(\"extended point not allowed\");let{x:b,y}=d||{};return h(\"x\",b),h(\"y\",y),new m(b,y,N,i(b*y))}static fromBytes(d,b=!1){let y=o.BYTES,{a:A,d:k}=s;d=zt(_t(d,y,\"point\")),Mt(b,\"zip215\");let I=zt(d),M=d[y-1];I[y-1]=M&-129;let E=nt(I),g=b?c:o.ORDER;Qt(\"point.y\",E,ot,g);let _=i(E*E),B=i(_-N),v=i(k*_-A),{isValid:T,value:S}=u(B,v);if(!T)throw new Error(\"bad point: invalid y coordinate\");let L=(S&N)===N,q=(M&128)!==0;if(!b&&S===ot&&q)throw new Error(\"bad point: x=0 and x_0=1\");return q!==L&&(S=i(-S)),m.fromAffine({x:S,y:E})}static fromHex(d,b=!1){return m.fromBytes(H(\"point\",d),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,b=!0){return x.createCache(this,d),b||this.multiply(ie),this}assertValidity(){p(this)}equals(d){f(d);let{X:b,Y:y,Z:A}=this,{X:k,Y:I,Z:M}=d,E=i(b*M),g=i(k*A),_=i(y*M),B=i(I*A);return E===g&&_===B}is0(){return this.equals(m.ZERO)}negate(){return new m(i(-this.X),this.Y,this.Z,i(-this.T))}double(){let{a:d}=s,{X:b,Y:y,Z:A}=this,k=i(b*b),I=i(y*y),M=i(ie*i(A*A)),E=i(d*k),g=b+y,_=i(i(g*g)-k-I),B=E+I,v=B-M,T=E-I,S=i(_*v),L=i(B*T),q=i(_*T),Q=i(v*B);return new m(S,L,Q,q)}add(d){f(d);let{a:b,d:y}=s,{X:A,Y:k,Z:I,T:M}=this,{X:E,Y:g,Z:_,T:B}=d,v=i(A*E),T=i(k*g),S=i(M*y*B),L=i(I*_),q=i((A+k)*(E+g)-v-T),Q=L-S,st=L+S,Z=i(T-b*v),pt=i(q*Q),kt=i(st*Z),Ut=i(q*Z),me=i(Q*st);return new m(pt,kt,me,Ut)}subtract(d){return this.add(d.negate())}multiply(d){if(!r.isValidNot0(d))throw new Error(\"invalid scalar: expected 1 <= sc < curve.n\");let{p:b,f:y}=x.cached(this,d,A=>Bt(m,A));return Bt(m,[b,y])[0]}multiplyUnsafe(d,b=m.ZERO){if(!r.isValid(d))throw new Error(\"invalid scalar: expected 0 <= sc < curve.n\");return d===ot?m.ZERO:this.is0()||d===N?this:x.unsafe(this,d,y=>Bt(m,y),b)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return x.unsafe(this,s.n).is0()}toAffine(d){return l(this,d)}clearCofactor(){return a===N?this:this.multiplyUnsafe(a)}toBytes(){let{x:d,y:b}=this.toAffine(),y=o.toBytes(b);return y[y.length-1]|=d&N?128:0,y}toHex(){return P(this.toBytes())}toString(){return`<Point ${this.is0()?\"ZERO\":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(d){return Bt(m,d)}static msm(d,b){return Ct(m,r,d,b)}_setWindowSize(d){this.precompute(d)}toRawBytes(){return this.toBytes()}}m.BASE=new m(s.Gx,s.Gy,N,i(s.Gx*s.Gy)),m.ZERO=new m(ot,N,N,ot),m.Fp=o,m.Fn=r;let x=new Nt(m,r.BITS);return m.BASE.precompute(8),m}var Rt=class{constructor(e){this.ep=e}static fromBytes(e){Jt()}static fromHex(e){Jt()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return P(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,n){return this.init(this.ep.precompute(e,n))}toRawBytes(){return this.toBytes()}};function Hn(t,e,n={}){if(typeof e!=\"function\")throw new Error('\"hash\" function param is required');wt(n,{},{adjustScalarBytes:\"function\",randomBytes:\"function\",domain:\"function\",prehash:\"function\",mapToCurve:\"function\"});let{prehash:o}=n,{BASE:r,Fp:s,Fn:a}=t,c=n.randomBytes||Gt,i=n.adjustScalarBytes||(g=>g),u=n.domain||((g,_,B)=>{if(Mt(B,\"phflag\"),_.length||B)throw new Error(\"Contexts/pre-hash are not supported\");return g});function h(g){return a.create(nt(g))}function f(g){let _=y.secretKey;g=H(\"private key\",g,_);let B=H(\"hashed private key\",e(g),2*_),v=i(B.slice(0,_)),T=B.slice(_,2*_),S=h(v);return{head:v,prefix:T,scalar:S}}function l(g){let{head:_,prefix:B,scalar:v}=f(g),T=r.multiply(v),S=T.toBytes();return{head:_,prefix:B,scalar:v,point:T,pointBytes:S}}function p(g){return l(g).pointBytes}function m(g=Uint8Array.of(),..._){let B=mt(..._);return h(e(u(B,H(\"context\",g),!!o)))}function x(g,_,B={}){g=H(\"message\",g),o&&(g=o(g));let{prefix:v,scalar:T,pointBytes:S}=l(_),L=m(B.context,v,g),q=r.multiply(L).toBytes(),Q=m(B.context,q,S,g),st=a.create(L+Q*T);if(!a.isValid(st))throw new Error(\"sign failed: invalid s\");let Z=mt(q,a.toBytes(st));return _t(Z,y.signature,\"result\")}let w={zip215:!0};function d(g,_,B,v=w){let{context:T,zip215:S}=v,L=y.signature;g=H(\"signature\",g,L),_=H(\"message\",_),B=H(\"publicKey\",B,y.publicKey),S!==void 0&&Mt(S,\"zip215\"),o&&(_=o(_));let q=L/2,Q=g.subarray(0,q),st=nt(g.subarray(q,L)),Z,pt,kt;try{Z=t.fromBytes(B,S),pt=t.fromBytes(Q,S),kt=r.multiplyUnsafe(st)}catch{return!1}if(!S&&Z.isSmallOrder())return!1;let Ut=m(T,pt.toBytes(),Z.toBytes(),_);return pt.add(Z.multiplyUnsafe(Ut)).subtract(kt).clearCofactor().is0()}let b=s.BYTES,y={secretKey:b,publicKey:b,signature:2*b,seed:b};function A(g=c(y.seed)){return _t(g,y.seed,\"seed\")}function k(g){let _=E.randomSecretKey(g);return{secretKey:_,publicKey:p(_)}}function I(g){return at(g)&&g.length===a.BYTES}function M(g,_){try{return!!t.fromBytes(g,_)}catch{return!1}}let E={getExtendedPublicKey:l,randomSecretKey:A,isValidSecretKey:I,isValidPublicKey:M,toMontgomery(g){let{y:_}=t.fromBytes(g),B=y.publicKey,v=B===32;if(!v&&B!==57)throw new Error(\"only defined for 25519 and 448\");let T=v?s.div(N+_,N-_):s.div(_-N,_+N);return s.toBytes(T)},toMontgomerySecret(g){let _=y.secretKey;_t(g,_);let B=e(g.subarray(0,_));return i(B).subarray(0,_)},randomPrivateKey:A,precompute(g=8,_=t.BASE){return _.precompute(g,!1)}};return Object.freeze({keygen:k,getPublicKey:p,sign:x,verify:d,utils:E,Point:t,lengths:y})}function Dn(t){let e={a:t.a,d:t.d,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp,o=X(e.n,t.nBitLength,!0),r={Fp:n,Fn:o,uvRatio:t.uvRatio},s={randomBytes:t.randomBytes,adjustScalarBytes:t.adjustScalarBytes,domain:t.domain,prehash:t.prehash,mapToCurve:t.mapToCurve};return{CURVE:e,curveOpts:r,hash:t.hash,eddsaOpts:s}}function $n(t,e){let n=e.Point;return Object.assign({},e,{ExtendedPoint:n,CURVE:t,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function Je(t){let{CURVE:e,curveOpts:n,hash:o,eddsaOpts:r}=Dn(t),s=qn(e,n),a=Hn(s,o,r);return $n(t,a)}var Kn=BigInt(0),W=BigInt(1),tn=BigInt(2),Zo=BigInt(3),Pn=BigInt(5),Gn=BigInt(8),ht=BigInt(\"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed\"),At={p:ht,n:BigInt(\"0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed\"),h:Gn,a:BigInt(\"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec\"),d:BigInt(\"0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3\"),Gx:BigInt(\"0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a\"),Gy:BigInt(\"0x6666666666666666666666666666666666666666666666666666666666666658\")};function Zn(t){let e=BigInt(10),n=BigInt(20),o=BigInt(40),r=BigInt(80),s=ht,c=t*t%s*t%s,i=K(c,tn,s)*c%s,u=K(i,W,s)*t%s,h=K(u,Pn,s)*u%s,f=K(h,e,s)*h%s,l=K(f,n,s)*f%s,p=K(l,o,s)*l%s,m=K(p,r,s)*p%s,x=K(m,r,s)*p%s,w=K(x,e,s)*h%s;return{pow_p_5_8:K(w,tn,s)*t%s,b2:c}}function Yn(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var ae=BigInt(\"19681161376707505956807079304988542015446066515923890162744021073123829784752\");function fe(t,e){let n=ht,o=O(e*e*e,n),r=O(o*o*e,n),s=Zn(t*r).pow_p_5_8,a=O(t*o*s,n),c=O(e*a*a,n),i=a,u=O(a*ae,n),h=c===t,f=c===O(-t,n),l=c===O(-t*ae,n);return h&&(a=i),(f||l)&&(a=u),j(a,n)&&(a=O(-a,n)),{isValid:h||f,value:a}}var rt=X(At.p,{isLE:!0}),Vn=X(At.n,{isLE:!0}),jn={...At,Fp:rt,hash:Ie,adjustScalarBytes:Yn,uvRatio:fe},F=Je(jn);var ce=ae,Xn=BigInt(\"25063068953384623474111414158702152701244531502492656460079210482610430750235\"),Wn=BigInt(\"54469307008909316920995813868745141605393597292927456921205312896311721017578\"),Fn=BigInt(\"1159843021668779879193775521855586647937357759715417654439879720876111806838\"),zn=BigInt(\"40440834346308536858101042469323190826248399146238708352240133220865137265952\"),en=t=>fe(W,t),Qn=BigInt(\"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"),le=t=>F.Point.Fp.create(nt(t)&Qn);function nn(t){let{d:e}=At,n=ht,o=d=>rt.create(d),r=o(ce*t*t),s=o((r+W)*Fn),a=BigInt(-1),c=o((a-e*r)*o(r+e)),{isValid:i,value:u}=fe(s,c),h=o(u*t);j(h,n)||(h=o(-h)),i||(u=h),i||(a=r);let f=o(a*(r-W)*zn-c),l=u*u,p=o((u+u)*c),m=o(f*Xn),x=o(W-l),w=o(W+l);return new F.Point(o(p*w),o(x*m),o(m*w),o(p*x))}function Jn(t){D(t,64);let e=le(t.subarray(0,32)),n=nn(e),o=le(t.subarray(32,64)),r=nn(o);return new z(n.add(r))}var z=class t extends Rt{constructor(e){super(e)}static fromAffine(e){return new t(F.Point.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error(\"RistrettoPoint expected\")}init(e){return new t(e)}static hashToCurve(e){return Jn(H(\"ristrettoHash\",e,64))}static fromBytes(e){D(e,32);let{a:n,d:o}=At,r=ht,s=A=>rt.create(A),a=le(e);if(!Ne(rt.toBytes(a),e)||j(a,r))throw new Error(\"invalid ristretto255 encoding 1\");let c=s(a*a),i=s(W+n*c),u=s(W-n*c),h=s(i*i),f=s(u*u),l=s(n*o*h-f),{isValid:p,value:m}=en(s(l*f)),x=s(m*u),w=s(m*x*l),d=s((a+a)*x);j(d,r)&&(d=s(-d));let b=s(i*w),y=s(d*b);if(!p||j(y,r)||b===Kn)throw new Error(\"invalid ristretto255 encoding 2\");return new t(new F.Point(d,b,W,y))}static fromHex(e){return t.fromBytes(H(\"ristrettoHex\",e,32))}static msm(e,n){return Ct(t,F.Point.Fn,e,n)}toBytes(){let{X:e,Y:n,Z:o,T:r}=this.ep,s=ht,a=w=>rt.create(w),c=a(a(o+n)*a(o-n)),i=a(e*n),u=a(i*i),{value:h}=en(a(c*u)),f=a(h*c),l=a(h*i),p=a(f*l*r),m;if(j(r*p,s)){let w=a(n*ce),d=a(e*ce);e=w,n=d,m=a(f*Wn)}else m=l;j(e*p,s)&&(n=a(-n));let x=a((o-n)*m);return j(x,s)&&(x=a(-x)),rt.toBytes(x)}equals(e){this.assertSame(e);let{X:n,Y:o}=this.ep,{X:r,Y:s}=e.ep,a=u=>rt.create(u),c=a(n*s)===a(o*r),i=a(o*s)===a(n*r);return c||i}is0(){return this.equals(t.ZERO)}};z.BASE=new z(F.Point.BASE);z.ZERO=new z(F.Point.ZERO);z.Fp=rt;z.Fn=Vn;var on=Te;var to=10n**BigInt(8),Fo=10n**38n-1n;var zo=to/100n;var eo=\"v1\";var no=16*1024;function ue(t){return encodeURIComponent(t).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)}function rn(t){let e=[];for(let n of t.split(\"/\"))if(n!==\"\")try{e.push(ue(decodeURIComponent(n)))}catch{return null}return`/${e.join(\"/\")}`}function sn(t){let e=(n,o)=>n<o?-1:n>o?1:0;return[...t].map(([n,o])=>[ue(n),ue(o)]).sort(([n,o],[r,s])=>e(n,r)||e(o,s)).map(([n,o])=>`${n}=${o}`).join(\"&\")}function an(t){return[eo,t.method,t.path,t.query,t.timestamp,t.nonce,t.keyId,t.idempotencyKey,t.contentType,t.bodySha256].join(`\n`)}var oo=[\"missing_header\",\"malformed_key_id\",\"malformed_timestamp\",\"malformed_nonce\",\"malformed_signature\",\"wrong_environment\",\"environment_unconfigured\",\"timestamp_expired\",\"timestamp_in_future\",\"unknown_key\",\"bad_signature\",\"bad_signature_unlisted\",\"ip_not_allowed\",\"replay_outside_allowlist\",\"key_pending\",\"key_suspended\",\"key_revoked\",\"key_expired\",\"not_market_maker\",\"replayed_nonce\"],ro=[\"key_limit_per_transaction\",\"key_limit_daily\",\"account_limit_daily\",\"below_minimum\",\"above_maximum\"],so=[\"ip_rate_limited\",\"ip_throttled\",\"rate_limited\",\"body_too_large\",\"account_inactive\",\"insufficient_scope\",\"method_not_allowed\",\"not_found\",\"invalid_request\",\"not_ready\",\"unavailable\",\"internal_error\",\"idempotency_key_required\",\"idempotency_key_invalid\",\"idempotency_key_reused\",\"idempotency_in_progress\",...ro,\"platform_limit\",\"verification_required\",\"minting_disabled\",\"redemptions_disabled\",\"too_many_open\",\"amount_below_fee\",\"amount_matches_open_order\",\"wallet_not_found\",\"wallet_not_ready\",\"destination_not_allowed\",\"destination_cooling\",\"destination_unavailable\",\"insufficient_funds\",\"not_cancellable\",\"transfer_on_its_way\",\"busy\"],or=[...oo,...so];var rr={unauthorized:{status:401,message:\"Authentication failed. Check the key, the signature and your clock, then sign a new request.\"},wrong_host:{status:421,message:\"The market-maker API is not served on this host.\"},insufficient_scope:{status:403,message:\"This key is not allowed to do this.\"},account_inactive:{status:403,message:\"This market-maker account is not active. Contact BALBOA.\"},not_found:{status:404,message:\"Not found.\"},not_ready:{status:409,message:\"This account is not set up for that yet. Contact BALBOA.\"},method_not_allowed:{status:405,message:\"This method is not allowed here.\"},body_too_large:{status:413,message:`The request body is larger than ${no} bytes.`},invalid_request:{status:400,message:\"The request is not valid.\"},rate_limited:{status:429,message:\"Too many requests. Wait for the time in Retry-After, then sign a new request.\"},unavailable:{status:503,message:\"This is not available right now. Try again shortly.\"},internal_error:{status:500,message:\"Something went wrong on our side. Try again; if it persists, contact BALBOA with the request id.\"},idempotency_key_required:{status:400,message:\"This request needs an Idempotency-Key header: a new one for each thing you mean to do, and the same one when you retry it.\"},idempotency_key_invalid:{status:400,message:\"Idempotency-Key must be 1 to 255 visible ASCII characters.\"},idempotency_key_reused:{status:422,message:\"This Idempotency-Key was already used for a different request. Use a new key for a new request.\"},idempotency_in_progress:{status:409,message:\"A request with this Idempotency-Key is still being processed. Wait, then read the result or retry with the same key \\u2014 never a new key for the same thing.\"},key_limit_per_transaction:{status:422,message:\"This is over this key\\u2019s own limit for one transaction.\"},key_limit_daily:{status:422,message:\"This is over this key\\u2019s own daily limit (UTC day).\"},account_limit_daily:{status:422,message:\"This is over your account\\u2019s daily limit (UTC day).\"},below_minimum:{status:422,message:\"This is below the smallest amount.\"},above_maximum:{status:422,message:\"This is above the largest amount.\"},platform_limit:{status:422,message:\"We cannot take this right now. Nothing was made. Try again later, or contact BALBOA.\"},verification_required:{status:403,message:\"The account owner\\u2019s verification needs renewing before money can move. Contact BALBOA.\"},minting_disabled:{status:503,message:\"Minting is paused right now. Nothing was made; try again later.\"},redemptions_disabled:{status:503,message:\"Redemptions are paused right now. Nothing was made; try again later.\"},too_many_open:{status:422,message:\"You have as many open as you may have at once. Wait for one to finish, or cancel one.\"},amount_below_fee:{status:422,message:\"The fee would take the whole amount.\"},amount_matches_open_order:{status:409,message:\"Another open mint order of yours is for this amount: vary it, even by a cent, so the transfers can be told apart.\"},wallet_not_found:{status:422,message:'That is not one of your wallets: use \"settlement\", one of your desks (\"desk:<id>\"), or the id of one of your clients.'},wallet_not_ready:{status:409,message:\"That wallet cannot be minted to or redeemed from right now.\"},destination_not_allowed:{status:422,message:\"That is not one of your redemption destinations.\"},destination_cooling:{status:409,message:\"That destination is still in its waiting period.\"},destination_unavailable:{status:409,message:\"We cannot send USDT to that destination right now. Contact BALBOA.\"},insufficient_funds:{status:422,message:\"Your settlement wallet does not hold enough BALBOA1 free for this.\"},not_cancellable:{status:409,message:\"This can no longer be cancelled.\"},transfer_on_its_way:{status:409,message:\"A transfer is on its way to this order, so it cannot be cancelled now.\"},busy:{status:503,message:\"Your account is busy with another request. Nothing was made; retry shortly with the same Idempotency-Key.\"}},io={mm_rate_per_minute:{default:\"120\",min:1,max:1e4,label:\"Requests a minute, per key\"},mm_ip_rate_per_minute:{default:\"300\",min:1,max:1e5,label:\"Requests a minute, per address, before a key is checked\"},mm_suspend_window_minutes:{default:\"10\",min:1,max:1440,label:\"Suspension window (minutes)\"},mm_suspend_after_signature_failures:{default:\"5\",min:1,max:1e3,label:\"Suspend a key after this many bad signatures\"},mm_suspend_after_replays:{default:\"3\",min:1,max:1e3,label:\"Suspend a key after this many replayed nonces\"},mm_suspend_after_ip_violations:{default:\"3\",min:1,max:1e3,label:\"Suspend a key after this many calls from outside its allowlist\"},mm_ip_bad_signature_limit:{default:\"20\",min:1,max:1e4,label:\"Refuse an address after this many bad signatures in the window\"},mm_key_rotation_overlap_hours:{default:\"72\",min:0,max:720,label:\"A rotated key expires after (hours)\"},mm_api_log_retention_days:{default:\"180\",min:30,max:3650,label:\"Keep refused calls in the request log for (days)\"},mm_api_log_ok_retention_days:{default:\"30\",min:7,max:3650,label:\"Keep answered calls in the request log for (days)\"},mm_refusal_alert_percent:{default:\"20\",min:1,max:100,label:\"Flag a market maker with more than this share of calls refused in the last hour (%)\"},mm_suspend_after_destination_violations:{default:\"3\",min:1,max:1e3,label:\"Suspend a key after this many redemptions to an address it may not use\"},mm_limit_breach_alert_after:{default:\"10\",min:1,max:1e4,label:\"Alert the admins after this many limit refusals of one key\"},mm_limit_breach_window_minutes:{default:\"60\",min:1,max:1440,label:\"Limit refusals counted over (minutes)\"},mm_platform_daily_mint_cap_usd:{default:\"500000\",min:0,max:0,label:\"Mint orders a UTC day, all market makers (USDT)\",kind:\"usd\"},mm_platform_daily_redeem_cap_usd:{default:\"250000\",min:0,max:0,label:\"Redemptions and payments a UTC day, all market makers (BALBOA1)\",kind:\"usd\"}},sr=Object.keys(io);function de(t){let e=[];for(let n of t){let o=n.codePointAt(0);o>=55296&&o<=57343&&(o=65533),o<128?e.push(o):o<2048?e.push(192|o>>6,128|o&63):o<65536?e.push(224|o>>12,128|o>>6&63,128|o&63):e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}return Uint8Array.from(e)}var Et=\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";function ln(t){let e=t.replace(/[\\s=]/g,\"\"),n=[],o=0,r=0;for(let s of e){let a=Et.indexOf(s);if(a<0)throw new Error(\"not base64\");r=r<<6|a,o+=6,o>=8&&(o-=8,n.push(r>>o&255))}return Uint8Array.from(n)}function fn(t){let e=\"\";for(let n=0;n<t.length;n+=3){let o=t[n]<<16|(t[n+1]??0)<<8|(t[n+2]??0);e+=Et[o>>18&63]+Et[o>>12&63],e+=n+1<t.length?Et[o>>6&63]:\"=\",e+=n+2<t.length?Et[o&63]:\"=\"}return e}var ao=\"302e020100300506032b657004220420\";function un(t){let e=t.trim();if(/^[0-9a-f]{64}$/i.test(e))return dt(e);let n;try{n=ln(e.replace(/-----(BEGIN|END) [A-Z ]+-----/g,\"\"))}catch{n=new Uint8Array}if(n.length===32)return n;if(n.length===48&&P(n.subarray(0,16))===ao)return n.subarray(16);throw new Error(\"privateKey is not an Ed25519 private key: give the PEM `openssl genpkey -algorithm ed25519` wrote (-----BEGIN PRIVATE KEY-----), or its 32 bytes in base64 or hex.\")}var cn=t=>{let e=t.replace(/\\+/g,\" \");try{return decodeURIComponent(e)}catch{return e}};function co(t){let e=rn(t.path);if(e===null)throw new Error(`The path ${t.path} is not UTF-8 once decoded: no route of the API has such a path.`);let n=an({method:t.method.toUpperCase(),path:e,query:sn(t.query.map(([o,r])=>[cn(o),cn(r)])),timestamp:t.timestamp,nonce:t.nonce,keyId:t.keyId,idempotencyKey:t.idempotencyKey,contentType:t.contentType,bodySha256:P(on(de(t.body)))});return{canonical:n,headers:{\"BALBOA-Key\":t.keyId,\"BALBOA-Timestamp\":t.timestamp,\"BALBOA-Nonce\":t.nonce,\"BALBOA-Signature\":fn(F.sign(de(n),un(t.privateKey)))}}}return gn(lo);})();",
          ";(function () {",
          "  var request = pm.request",
          "  var path = pm.variables.replaceIn(request.url.getPath())",
          "  // The clock needs no signature: call it first, to check your clock and your address.",
          "  if (path.replace(/\\/+$/, '') === '/api/mm/v1/time') return",
          "  var keyId = pm.variables.get('keyId')",
          "  var privateKey = pm.variables.get('privateKey')",
          "  if (!keyId || !privateKey) throw new Error('Set keyId and privateKey (an environment, or the collection\\'s variables): see the collection\\'s description.')",
          "  var method = request.method.toUpperCase()",
          "",
          "  // What is signed is what is sent: variables are resolved here once, and written back.",
          "  var query = []",
          "  request.url.query.each(function (q) {",
          "    if (q.disabled || !q.key) return",
          "    q.key = pm.variables.replaceIn(q.key)",
          "    q.value = pm.variables.replaceIn(q.value == null ? '' : String(q.value))",
          "    query.push([q.key, q.value])",
          "  })",
          "  var body = ''",
          "  if (request.body && request.body.mode === 'raw' && request.body.raw) {",
          "    body = pm.variables.replaceIn(request.body.raw)",
          "    if (body !== request.body.raw) request.body.update(body)",
          "  }",
          "",
          "  // Every POST carries an Idempotency-Key: the one set on the request, or a new one for this send.",
          "  var idempotencyKey = ''",
          "  if (method === 'POST') {",
          "    var given = request.headers.find(function (h) { return !h.disabled && String(h.key).toLowerCase() === 'idempotency-key' && h.value })",
          "    idempotencyKey = given ? pm.variables.replaceIn(given.value) : 'postman-' + pm.variables.replaceIn('{{$guid}}')",
          "  }",
          "  var contentType = body ? 'application/json' : ''",
          "",
          "  var signed = BALBOA_SIGN.signRequest({",
          "    method: method, path: path, query: query, body: body, keyId: keyId, privateKey: privateKey,",
          "    idempotencyKey: idempotencyKey, contentType: contentType,",
          "    timestamp: String(Math.floor(Date.now() / 1000)),",
          "    nonce: pm.variables.replaceIn('{{$guid}}').replace(/-/g, ''),",
          "  })",
          "  var headers = signed.headers",
          "  if (idempotencyKey) headers['Idempotency-Key'] = idempotencyKey",
          "  if (contentType) headers['Content-Type'] = contentType",
          "  Object.keys(headers).forEach(function (k) {",
          "    request.headers.remove(k)",
          "    request.headers.add({ key: k, value: headers[k] })",
          "  })",
          "})()"
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://app.balboacorp.xyz",
      "type": "string",
      "description": "The API host, as BALBOA serves it: https://api.<domain>, or the application's own host."
    },
    {
      "key": "keyId",
      "value": "",
      "type": "string",
      "description": "bk_live_… or bk_test_…"
    },
    {
      "key": "privateKey",
      "value": "",
      "type": "secret",
      "description": "Your Ed25519 private key (PEM, or 32 bytes in base64 or hex). Current value only."
    }
  ],
  "protocolProfileBehavior": {
    "followRedirects": false
  }
}
