@opendatalabs/vana-sdk 3.23.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +57 -0
  2. package/dist/auth/errors.cjs +1 -1
  3. package/dist/auth/web3-signed.cjs +1 -1
  4. package/dist/crypto/envelope/job-stream.test.d.ts +1 -0
  5. package/dist/crypto/envelope/job.cjs +593 -38
  6. package/dist/crypto/envelope/job.cjs.map +1 -1
  7. package/dist/crypto/envelope/job.d.ts +44 -27
  8. package/dist/crypto/envelope/job.js +589 -37
  9. package/dist/crypto/envelope/job.js.map +1 -1
  10. package/dist/direct/access-request-client.cjs +1 -1
  11. package/dist/direct/connect-flow.cjs +43 -1
  12. package/dist/direct/connect-flow.cjs.map +1 -1
  13. package/dist/direct/connect-flow.d.ts +12 -0
  14. package/dist/direct/connect-flow.js +43 -1
  15. package/dist/direct/connect-flow.js.map +1 -1
  16. package/dist/direct/controller.cjs +1 -1
  17. package/dist/direct/errors.cjs +1 -1
  18. package/dist/direct/escrow-payment.cjs.map +1 -1
  19. package/dist/direct/escrow-payment.d.ts +2 -2
  20. package/dist/direct/escrow-payment.js.map +1 -1
  21. package/dist/direct/personal-server-read.cjs +2 -2
  22. package/dist/direct/use-direct-vana-connect.cjs +2 -1
  23. package/dist/direct/use-direct-vana-connect.cjs.map +1 -1
  24. package/dist/direct/use-direct-vana-connect.d.ts +3 -1
  25. package/dist/direct/use-direct-vana-connect.js +2 -1
  26. package/dist/direct/use-direct-vana-connect.js.map +1 -1
  27. package/dist/error-entry-points.test.d.ts +1 -0
  28. package/dist/errors.cjs +7 -0
  29. package/dist/errors.cjs.map +1 -1
  30. package/dist/errors.d.ts +10 -0
  31. package/dist/errors.js +6 -0
  32. package/dist/errors.js.map +1 -1
  33. package/dist/index.browser.d.ts +4 -4
  34. package/dist/index.browser.js +882 -518
  35. package/dist/index.browser.js.map +4 -4
  36. package/dist/index.node.cjs +1035 -705
  37. package/dist/index.node.cjs.map +4 -4
  38. package/dist/index.node.d.ts +4 -4
  39. package/dist/index.node.js +989 -567
  40. package/dist/index.node.js.map +4 -4
  41. package/dist/protocol/data-point-deletion.cjs +1 -1
  42. package/dist/protocol/derivative-questions.cjs +1 -1
  43. package/dist/protocol/derivative-status.cjs +1 -1
  44. package/dist/protocol/eip712.cjs +28 -2
  45. package/dist/protocol/eip712.cjs.map +1 -1
  46. package/dist/protocol/eip712.d.ts +70 -0
  47. package/dist/protocol/eip712.js +24 -1
  48. package/dist/protocol/eip712.js.map +1 -1
  49. package/dist/protocol/escrow.cjs +154 -2
  50. package/dist/protocol/escrow.cjs.map +1 -1
  51. package/dist/protocol/escrow.d.ts +145 -2
  52. package/dist/protocol/escrow.js +152 -1
  53. package/dist/protocol/escrow.js.map +1 -1
  54. package/dist/protocol/fixtures/moksha-identity.json +20 -0
  55. package/dist/protocol/gateway.cjs +1 -1
  56. package/dist/protocol/gateway.cjs.map +1 -1
  57. package/dist/protocol/gateway.d.ts +8 -38
  58. package/dist/protocol/gateway.js.map +1 -1
  59. package/dist/protocol/identity.cjs +7 -2
  60. package/dist/protocol/identity.cjs.map +1 -1
  61. package/dist/protocol/identity.js +7 -2
  62. package/dist/protocol/identity.js.map +1 -1
  63. package/dist/protocol/jobs-client.cjs +73 -21
  64. package/dist/protocol/jobs-client.cjs.map +1 -1
  65. package/dist/protocol/jobs-client.d.ts +7 -5
  66. package/dist/protocol/jobs-client.js +74 -21
  67. package/dist/protocol/jobs-client.js.map +1 -1
  68. package/dist/protocol/jobs.cjs +0 -3
  69. package/dist/protocol/jobs.cjs.map +1 -1
  70. package/dist/protocol/jobs.d.ts +21 -13
  71. package/dist/protocol/jobs.js +0 -2
  72. package/dist/protocol/jobs.js.map +1 -1
  73. package/dist/protocol/lineage.cjs +1 -1
  74. package/dist/protocol/personal-server-data.cjs +1 -1
  75. package/dist/protocol/personal-server-write.cjs +1 -1
  76. package/dist/protocol/write-request.cjs +1 -1
  77. package/dist/protocol/write-signer.cjs +1 -1
  78. package/dist/react.cjs.map +1 -1
  79. package/dist/react.d.ts +1 -1
  80. package/dist/react.js.map +1 -1
  81. package/dist/session-relay/client.cjs +1 -1
  82. package/dist/session-relay/errors.cjs +1 -1
  83. package/dist/session-relay/index.cjs +1 -1
  84. package/package.json +1 -1
@@ -0,0 +1,20 @@
1
+ {
2
+ "v": 1,
3
+ "userPsId": "0x99c9f5264868c19aaf3b0c31a975bbf12f782ff216d0288976304511989c315f",
4
+ "chainId": 14800,
5
+ "ownerAddress": "0xF35b0b806DE33F2efcB8A3EbC84bDCe58Eb1DB03",
6
+ "epoch": 1,
7
+ "address": "0x874514D6b357922A498a3ebf1d6b06AA5D6655e1",
8
+ "publicKey": "0x04acfd2e2ea6299846240ddf2c7b5edb8f98e89fb77c1c3e9e4a048a539aab7a242173f3c1cf96504e1ce4647ffb3c4c0667891efa92e7381ea0236fc373bd1818",
9
+ "appId": "0xec9a39de98c760e1ded9f1e97016dc5f0e357cf2",
10
+ "composeHash": "0x743eb1715dbf1d193cc9447cd9a4a225789fc66537a7c0d40ff7fedf020c6baa",
11
+ "osImageHash": "0xbd369a8c2f9edb2b52dad48ac8e0b32dde5f1337c423a506b48d07403a7d8033",
12
+ "purpose": "vana.ps-enclave.wallet.v1",
13
+ "signatureChain": [
14
+ "0x2803d33c48168713bb3f99dc9cd57af9f771d5c1388e8bc8be915d441cfd83a654ea289cff9c1829b3abef49bcededacf8721435240e7fce7a98be2aa45ebf9c00",
15
+ "0x3caaffa5391c4e9645aa3df299a97b999f8a86b29fe5abdcd9d084099243bde256071b0905cb7b3c785f5199102b55a141b41d5a760d5f0c75e81458aa7070eb01"
16
+ ],
17
+ "quote": "0x040002008100000000000000939a7233f79c4ca9940a0db3957f0607228b1b2533416561505b6d6ef4236c79000000000b0105000000000000000000000000007bf063280e94fb051f5dd7b1fc59ce9aac42bb961df8d44b709c9b0ff87a7b4df648657ba6d1189589feab1d5a3c9a9d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000702000000000000f06dfda6dce1cf904d4e2bab1dc370634cf95cefa2ceb2de2eee127c9382698090d7a4a13e14c536ec6c9c3c8fa8707701743eb1715dbf1d193cc9447cd9a4a225789fc66537a7c0d40ff7fedf020c6baa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000068102e7b524af310f7b7d426ce75481e36c40f5d513a9009c046e9d37e31551f0134d954b496a3357fd61d03f07ffe9607e6f51aa763abfe75c3ddfbf4f425fe3f0ceff66d807a75e049303dce9addf68e7218729bd419638af63a370f65878cdf67e467e60edc1737bcf8e682d48131bfb427f523226aa7f197a7608e9b3784783fa759ef5b28191fa12f9ddb36b858ed4ee6ff9ed11ca72034ce84fb4d371c3021625df1ebca9ac9ffb345d047984d949114c44b5ce70135ad85b6db6e2e324361fe957bb3a351853b87bdfcc57ffcb7a9429d79b01682bd680a3419a0daa70000000000000000000000000000000000000000000000000000000000000000d0100000dd9fc20421247a8447772f6b8d23838de783a884696d35db105984ead98fba4636ab97cac5fc5c84d2465ab017a2323255de1a28f42cfada7440d27e92358c71d4aea0ab2a5cfdc479e2b02599d8e30d7dcbcc11bc550681a15d0777d298867465adda0877a31bf4a80dd227d0b1c53f263afe5136081698ff89101622c5616f06004a10000005050a0a05ff00020000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000700000000000000e5a3a7b5d830c2953b98534c6c59a3a34fdc34e933f7f5898f0a85cf08846bca0000000000000000000000000000000000000000000000000000000000000000dc9e2a7c6f948f17474e34a7fc43ed030f7c1563f1babddf6340c82e0e54a8c500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000bbf5f2fdd1fd1fc2e16e13810b22d19ded102d47dcde36beb537b37730625faa0000000000000000000000000000000000000000000000000000000000000000421a04e18565ac12b6818fdc39c06e718e17cfc9fc1516fd45ad7f6c5d293f9ecf535cbfe6f26e81058f485d0865b3e23e5eb6d2da95b3306452d091663867802000000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f0500620e00002d2d2d2d2d424547494e2043455254494649434154452d2d2d2d2d0a4d494945386a4343424a69674177494241674956414e5a424d42727175543357555555623435426c4f637a33633669424d416f4743437147534d343942414d430a4d484178496a416742674e5642414d4d47556c756447567349464e4857434251513073675547786864475a76636d306751304578476a415942674e5642416f4d0a45556c756447567349454e76636e4276636d4630615739754d5251774567594456515148444174545957353059534244624746795954454c4d416b47413155450a4341774351304578437a414a42674e5642415954416c56544d423458445449324d4445794f5441314d7a49774e6c6f5844544d7a4d4445794f5441314d7a49770a4e6c6f77634445694d434147413155454177775a535735305a5777675530645949464244537942445a584a3061575a70593246305a5445614d426747413155450a43677752535735305a577767513239796347397959585270623234784644415342674e564241634d43314e68626e526849454e7359584a684d517377435159440a5651514944414a445154454c4d416b474131554542684d4356564d775754415442676371686b6a4f5051494242676771686b6a4f50514d4242774e43414152390a463045517555582b43746677516a61726a6b4270436f4e646361746642503168444e2f776677397042797851584b42464c74696e6e6c58637a7856616948544c0a724f2f6352764f7437556375764d793231772f586f3449444454434341776b77487759445652306a42426777466f41556c5739647a62306234656c4153636e550a3944504f4156634c336c5177617759445652306642475177596a42676f46366758495a616148523063484d364c79396863476b7564484a316333526c5a484e6c0a636e5a705932567a4c6d6c75644756734c6d4e766253397a5a3367765932567964476c6d61574e6864476c76626939324e4339775932746a636d772f593245390a6347786864475a76636d306d5a57356a62325270626d63395a4756794d4230474131556444675157424252547a744d5341354376394c675467314c37433136540a4b5079553044414f42674e56485138424166384542414d434273417744415944565230544151482f4241497741444343416a6f4743537147534962345451454e0a41515343416973776767496e4d42344743697147534962345451454e415145454544347762684d376639716e75336e32646a544c556777776767466b42676f710a686b69472b453042445145434d4949425644415142677371686b69472b45304244514543415149424254415142677371686b69472b45304244514543416749420a4254415142677371686b69472b4530424451454341774942416a415142677371686b69472b4530424451454342414942416a415142677371686b69472b4530420a44514543425149424254415242677371686b69472b4530424451454342674943415038774541594c4b6f5a496876684e4151304241676343415141774541594c0a4b6f5a496876684e4151304241676743415149774541594c4b6f5a496876684e4151304241676b43415141774541594c4b6f5a496876684e4151304241676f430a415141774541594c4b6f5a496876684e4151304241677343415141774541594c4b6f5a496876684e4151304241677743415141774541594c4b6f5a496876684e0a4151304241673043415141774541594c4b6f5a496876684e4151304241673443415141774541594c4b6f5a496876684e4151304241673843415141774541594c0a4b6f5a496876684e4151304241684143415141774541594c4b6f5a496876684e4151304241684543415130774877594c4b6f5a496876684e41513042416849450a45415546416749462f7741434141414141414141414141774541594b4b6f5a496876684e4151304241775143414141774641594b4b6f5a496876684e415130420a42415147494b4276414141414d41384743697147534962345451454e4151554b415145774867594b4b6f5a496876684e4151304242675151704548632f65354d0a784b43445636306651747932666a424542676f71686b69472b453042445145484d4459774541594c4b6f5a496876684e4151304242774542416638774541594c0a4b6f5a496876684e4151304242774942416638774541594c4b6f5a496876684e4151304242774d4241663877436759494b6f5a497a6a304541774944534141770a52514967515147314e57757a55647566317a4b516561562f56616d2f43587657506752544f7a7362326941366c4767434951445235314670636f7572547a4e570a78572b62566f34382b7a6b7a3132655739532b4b2f5147644d54765233513d3d0a2d2d2d2d2d454e442043455254494649434154452d2d2d2d2d0a2d2d2d2d2d424547494e2043455254494649434154452d2d2d2d2d0a4d4949436c6a4343416a32674177494241674956414a567658633239472b487051456e4a3150517a7a674658433935554d416f4743437147534d343942414d430a4d476778476a415942674e5642414d4d45556c756447567349464e48574342536232393049454e424d526f77474159445651514b4442464a626e526c624342440a62334a7762334a6864476c76626a45554d424947413155454277774c553246756447456751327868636d4578437a414a42674e564241674d416b4e424d5173770a435159445651514745774a56557a4165467730784f4441314d6a45784d4455774d5442614677307a4d7a41314d6a45784d4455774d5442614d484178496a41670a42674e5642414d4d47556c756447567349464e4857434251513073675547786864475a76636d306751304578476a415942674e5642416f4d45556c75644756730a49454e76636e4276636d4630615739754d5251774567594456515148444174545957353059534244624746795954454c4d416b474131554543417743513045780a437a414a42674e5642415954416c56544d466b77457759484b6f5a497a6a3043415159494b6f5a497a6a304441516344516741454e53422f377432316c58534f0a3243757a7078773734654a423732457944476757357258437478327456544c7136684b6b367a2b5569525a436e71523770734f766771466553786c6d546c4a6c0a65546d693257597a33714f42757a43427544416642674e5648534d4547444157674251695a517a575770303069664f44744a5653763141624f536347724442530a42674e5648523845537a424a4d45656752614244686b466f64485277637a6f764c324e6c636e52705a6d6c6a5958526c63793530636e567a6447566b633256790a646d6c6a5a584d75615735305a577775593239744c306c756447567355306459556d397664454e424c6d526c636a416442674e5648513445466751556c5739640a7a62306234656c4153636e553944504f4156634c336c517744675944565230504151482f42415144416745474d42494741315564457745422f7751494d4159420a4166384341514177436759494b6f5a497a6a30454177494452774177524149675873566b6930772b6936565947573355462f32327561586530594a446a3155650a6e412b546a44316169356343494359623153416d4435786b66545670766f34556f79695359787244574c6d5552344349394e4b7966504e2b0a2d2d2d2d2d454e442043455254494649434154452d2d2d2d2d0a2d2d2d2d2d424547494e2043455254494649434154452d2d2d2d2d0a4d4949436a7a4343416a53674177494241674955496d554d316c71644e496e7a6737535655723951477a6b6e42717777436759494b6f5a497a6a3045417749770a614445614d4267474131554541777752535735305a5777675530645949464a766233516751304578476a415942674e5642416f4d45556c756447567349454e760a636e4276636d4630615739754d5251774567594456515148444174545957353059534244624746795954454c4d416b47413155454341774351304578437a414a0a42674e5642415954416c56544d423458445445344d4455794d5445774e4455784d466f58445451354d54497a4d54497a4e546b314f566f77614445614d4267470a4131554541777752535735305a5777675530645949464a766233516751304578476a415942674e5642416f4d45556c756447567349454e76636e4276636d46300a615739754d5251774567594456515148444174545957353059534244624746795954454c4d416b47413155454341774351304578437a414a42674e56424159540a416c56544d466b77457759484b6f5a497a6a3043415159494b6f5a497a6a3044415163445167414543366e45774d4449595a4f6a2f69505773437a61454b69370a314f694f534c52466857476a626e42564a66566e6b59347533496a6b4459594c304d784f346d717379596a6c42616c54565978465032734a424b357a6c4b4f420a757a43427544416642674e5648534d4547444157674251695a517a575770303069664f44744a5653763141624f5363477244425342674e5648523845537a424a0a4d45656752614244686b466f64485277637a6f764c324e6c636e52705a6d6c6a5958526c63793530636e567a6447566b63325679646d6c6a5a584d75615735300a5a577775593239744c306c756447567355306459556d397664454e424c6d526c636a416442674e564851344546675155496d554d316c71644e496e7a673753560a55723951477a6b6e4271777744675944565230504151482f42415144416745474d42494741315564457745422f7751494d4159424166384341514577436759490a4b6f5a497a6a3045417749445351417752674968414f572f35516b522b533943695344634e6f6f774c7550524c735747662f59693747535839344267775477670a41694541344a306c72486f4d732b586f356f2f7358364f39515778485241765a55474f6452513763767152586171493d0a2d2d2d2d2d454e442043455254494649434154452d2d2d2d2d0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
18
+ "eventLog": "[{\"imr\":0,\"event_type\":2147483659,\"digest\":\"0b8772e5b0b41b83e6044a68397e02f49fb47066b4fbe4917ea2c45c64f323fdacbb37948f821ebaf8bc9c938ba8a749\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483658,\"digest\":\"344bc51c980ba621aaa00da3ed7436f7d6e549197dfe699515dfa2c6583d95e6412af21c097d473155875ffd561d6790\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483649,\"digest\":\"9dc3a1f80bcec915391dcda5ffbb15e7419f77eab462bbf72b42166fb70d50325e37b36f93537a863769bcf9bedae6fb\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483649,\"digest\":\"6f2e3cbc14f9def86980f5f66fd85e99d63e69a73014ed8a5633ce56eca5b64b692108c56110e22acadcef58c3250f1b\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483649,\"digest\":\"d607c0efb41c0d757d69bca0615c3a9ac0b1db06c557d992e906c6b7dee40e0e031640c7bfd7bcd35844ef9edeadc6f9\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483649,\"digest\":\"08a74f8963b337acb6c93682f934496373679dd26af1089cb4eaf0c30cf260a12e814856385ab8843e56a9acea19e127\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483649,\"digest\":\"18cc6e01f0c6ea99aa23f8a280423e94ad81d96d0aeb5180504fc0f7a40cb3619dd39bd6a95ec1680a86ed6ab0f9828d\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":4,\"digest\":\"394341b7182cd227c5c6b07ef8000cdfd86136c4292b8e576573ad7ed9ae41019f5818b4b971c9effc60e1ad9f1289f0\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":10,\"digest\":\"39740da2ea1e7e6c69e5e6569755b2ad6d622a8a9983a2c5b32d5574659dbdc4ca8b95b1c766bd610bc5c26dcde842f8\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":10,\"digest\":\"6385b89d2decb3de678d51faba0ff3506835915818fd3ee53a739aa678cd9c76bdd755adfa0aa714cf35a1abe062b253\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":10,\"digest\":\"05705c3ca9d71e908d5ce70d4331b6aadce5331b9a6a546f222f017fb0e1797b951a3dac72f59cb197a0c897a201ca07\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":1,\"event_type\":2147483651,\"digest\":\"90e278aa4d688f4f05bf76f1786fea174abcea0d6b44e81cea5b3327f3f211e5c465a9c34b513283bed2512bca6d4a19\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483650,\"digest\":\"1dd6f7b457ad880d840d41c961283bab688e94e4b59359ea45686581e90feccea3c624b1226113f824f315eb60ae0a7c\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":0,\"event_type\":2147483650,\"digest\":\"23ada07f5261f12f34a0bd8e46760962d6b4d576a416f1fea1c64bc656b1d28eacf7047ae6e967c58fd2a98bfa74c298\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":1,\"event_type\":2147483655,\"digest\":\"77a0dab2312b4e1e57a84d865a21e5b2ee8d677a21012ada819d0a98988078d3d740f6346bfe0abaa938ca20439a8d71\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":1,\"event_type\":4,\"digest\":\"394341b7182cd227c5c6b07ef8000cdfd86136c4292b8e576573ad7ed9ae41019f5818b4b971c9effc60e1ad9f1289f0\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":2,\"event_type\":6,\"digest\":\"9c824b958dbbef07ec732fd79727e995d5eca309dbc6d62e4fd2840f267c5e87108b5fe25c7997c67801ff391fb67ffc\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":2,\"event_type\":6,\"digest\":\"5eb4f34f2ec49071551c5562ebaab9f86408f4a0eadaa3d7f05157e37ab04a1f040a82eaae94015d628a7ea4aa482cd2\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":1,\"event_type\":2147483655,\"digest\":\"214b0bef1379756011344877743fdc2a5382bac6e70362d624ccf3f654407c1b4badf7d8f9295dd3dabdef65b27677e0\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":1,\"event_type\":2147483655,\"digest\":\"0a2e01c85deae718a530ad8c6d20a84009babe6c8989269e950d8cf440c6e997695e64d455c4174a652cd080f6230b74\",\"event\":\"\",\"event_payload\":\"\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"system-preparing\",\"event_payload\":\"\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"app-id\",\"event_payload\":\"ec9a39de98c760e1ded9f1e97016dc5f0e357cf2\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"compose-hash\",\"event_payload\":\"743eb1715dbf1d193cc9447cd9a4a225789fc66537a7c0d40ff7fedf020c6baa\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"instance-id\",\"event_payload\":\"1ac22335a2da1ca6a024396c4a557907279403ab\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"boot-mr-done\",\"event_payload\":\"\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"mr-kms\",\"event_payload\":\"692afc6d7a86a32cfc1ebd9cad1a576aab012bab46986ba609bc8d6407270572\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"os-image-hash\",\"event_payload\":\"bd369a8c2f9edb2b52dad48ac8e0b32dde5f1337c423a506b48d07403a7d8033\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"key-provider\",\"event_payload\":\"7b226e616d65223a226b6d73222c226964223a223330353933303133303630373261383634386365336430323031303630383261383634386365336430333031303730333432303030343838343465623432636364663863353266643466313734663336326663623962626431396334356664343866316564656332643866316361323335333665633161373430323162346365653631306330373466383239346434333162326237666565326333396535333333666461663061343532326434336662313539643966227d\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"storage-fs\",\"event_payload\":\"7a6673\"},{\"imr\":3,\"event_type\":134217729,\"digest\":\"\",\"event\":\"system-ready\",\"event_payload\":\"\"}]",
19
+ "kmsRootFingerprint": "0xd530f657676361f3f67c4ea762468e67a8054e8797c571c38412d7ad70870cdb"
20
+ }
@@ -22,7 +22,7 @@ __export(gateway_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(gateway_exports);
24
24
  var import_scope_actions = require("./scope-actions");
25
- var import_errors = require("../errors");
25
+ var import_errors = require("../errors.cjs");
26
26
  var import_data_point_deletion = require("./data-point-deletion");
27
27
  var import_lineage = require("./lineage");
28
28
  var import_response_body = require("../utils/response-body");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/protocol/gateway.ts"],"sourcesContent":["import { tryGrantPermissions, type GrantPermission } from \"./scope-actions\";\nimport {\n DataPointDeletedError,\n DataPointNotFoundError,\n DataPointVersionConflictError,\n} from \"../errors\";\nimport {\n isDataPointTombstone,\n tombstoneDeletedAt,\n} from \"./data-point-deletion\";\nimport { deriveDataPointId } from \"./lineage\";\nimport {\n isPlainObject,\n readJsonObject,\n readJsonValue,\n} from \"../utils/response-body\";\n\nexport interface GatewayEnvelope<T> {\n data: T;\n proof: GatewayProof;\n /**\n * Cursor-based pagination metadata, present on list endpoints (e.g.\n * `GET /v1/data`). A sibling of `data`, not nested inside it — so callers\n * that need it must read the full envelope rather than going through\n * `unwrapEnvelope`, which intentionally returns only `data`.\n */\n pagination?: GatewayPagination;\n}\n\nexport interface GatewayPagination {\n limit: number;\n hasMore: boolean;\n /**\n * Opaque cursor for the NEXT page; pass back as the `cursor` query param.\n * Null when there are no further pages.\n */\n nextCursor: string | null;\n}\n\nexport interface GatewayProof {\n signature: string;\n timestamp: string;\n gatewayAddress: string;\n requestHash: string;\n responseHash: string;\n userSignature: string;\n status: string;\n chainBlockHeight: number;\n}\n\nexport interface Builder {\n id: string;\n ownerAddress: string;\n granteeAddress: string;\n publicKey: string;\n appUrl: string;\n addedAt: string;\n}\n\nexport interface Schema {\n id: string;\n ownerAddress: string;\n name: string;\n definitionUrl: string;\n scope: string;\n addedAt: string;\n}\n\n// Row shape returned by `GET /v1/servers?owner=…`. A discovery-only list —\n// the endpoint carries no per-item gateway attestation (use\n// `getServer(serverAddress)` if you need a verifiable single-server proof).\n// `status` is the gateway's chain-sync state ('pending' | 'confirmed' |\n// 'finalized' | 'reorged'); kept as an open string since the gateway may add\n// states without a SDK bump.\nexport interface OwnerServerRecord {\n id: string;\n ownerAddress: string;\n serverAddress: string;\n publicKey: string;\n serverUrl: string;\n status: string;\n chainBlockHeight: string | null;\n // ISO timestamp of the gateway-side upsert.\n addedAt: string;\n // ISO timestamp when the grantor deregistered this server. Always null for\n // entries in the `active` list, always non-null for `revoked`.\n revokedAt: string | null;\n}\n\n// Response from `GET /v1/servers?owner=…`. Split into two arrays; each is\n// ordered newest-first (`addedAt DESC`, `id ASC` tiebreaker) so `active[0]`\n// is unambiguously the newest active server — the sensible default when the\n// caller just needs one URL. The gateway caps the total across both arrays\n// at 200 — per-owner counts are tiny in practice, so no cursor.\nexport interface OwnerServersResult {\n active: OwnerServerRecord[];\n revoked: OwnerServerRecord[];\n count: number;\n}\n\nexport interface ServerInfo {\n id: string;\n ownerAddress: string;\n serverAddress: string;\n publicKey: string;\n serverUrl: string;\n addedAt: string;\n // ISO timestamp when the grantor deregistered this server, null while\n // active. The gateway returns this on /v1/servers/:address GETs since\n // covering revocation in the response keeps the attestation hash\n // authoritative for both states.\n revokedAt: string | null;\n}\n\n// Fee annotation surfaced on every GET grant response. Amounts are decimal\n// uint256 strings to match `/v1/escrow/pay`'s wire format. totalDue is a\n// snapshot — the gateway re-resolves fees at pay time, so clients shouldn't\n// cache this across requests.\nexport interface GatewayGrantFee {\n asset: string;\n registrationFee: string;\n dataAccessFee: string;\n totalDue: string;\n}\n\n// Lifecycle of a grant's on-chain settlement, tracked separately from the\n// fee-payment lifecycle (paymentStatus). Driven by POST /v1/settle:\n// pending — nothing on-chain yet\n// submitting — settle tx broadcast but receipt not yet observed\n// confirmed — settle tx mined successfully\n// finalized — finalized tip past the settle block, reorg-safe\n// reorged — finalized observation reverted; back to 'pending' on next settle\nexport type GatewayGrantStatus =\n | \"pending\"\n | \"submitting\"\n | \"confirmed\"\n | \"finalized\"\n | \"reorged\";\n\nexport interface GatewayGrantResponse {\n id: string;\n grantorAddress: string;\n granteeId: string;\n // The signed scope entries, verbatim (`[operation:]scope`, bare = read).\n // This is the wire form: it is what the grantor signed and what the\n // gateway stores. Render `permissions` instead of parsing these.\n scopes: string[];\n // Derived by the SDK at read time from `scopes` via grantPermissions():\n // one `{ scope, actions }` row per scope pattern, canonically ordered.\n // Never sent to the gateway and never part of the signed payload. Absent\n // when `scopes` carries an entry this SDK version cannot interpret (an\n // operation introduced after this release) - fall back to `scopes` and\n // do not assume such a grant is read-only.\n permissions?: GrantPermission[];\n status: GatewayGrantStatus;\n addedAt: string;\n // Grantor-signed deadline. null = perpetual grant (signed value was 0).\n expiresAt: string | null;\n // Derived at read time from expiresAt vs the gateway's clock — a snapshot,\n // not a cached truth. Re-check against expiresAt locally if you care.\n expired: boolean;\n revokedAt: string | null;\n revocationSignature: string | null;\n // 'pending' until the grant registration fee is settled via /v1/escrow/pay.\n paymentStatus: \"pending\" | \"paid\";\n paidAt: string | null;\n paidBy: string | null;\n // Decimal-string uint256 monotonic nonce; advances on every state change.\n grantVersion: string;\n // Settle metadata — populated as the grant progresses through the chain\n // lifecycle. Null while `status === 'pending'`.\n settleTxHash: string | null;\n settleSubmittedAt: string | null;\n // Revocation metadata — populated independently when the grantor signs\n // and the gateway pushes a deregister tx.\n revocationTxHash: string | null;\n revocationSubmittedAt: string | null;\n fee: GatewayGrantFee;\n}\n\nexport type GrantListItem = GatewayGrantResponse;\n\n// Mirror of a DataRegistryV2 row as the gateway exposes it. `id` is the\n// deterministic `keccak256(abi.encode(owner, scope))` dataPointId — the same\n// value the contract uses as its primary key. `expectedVersion` is the latest\n// version the gateway has accepted; the on-chain row may be one version behind\n// while a settle is still pending. The gateway response intentionally drops\n// `status` from the body — read it from the on-chain contract when you need\n// the canonical lifecycle state.\nexport interface DataPointRecord {\n id: string;\n ownerAddress: string;\n scope: string;\n dataHash: string;\n metadataHash: string;\n // Decimal-string uint256.\n expectedVersion: string;\n // ISO 8601 timestamp of the most recent gateway-side upsert.\n addedAt: string;\n // ISO 8601 timestamp of the deletion tombstone, null/absent while live.\n // Only present on reads that opted in via `includeDeleted`; a plain\n // `getDataPoint` of a deleted row throws `DataPointDeletedError` instead.\n deletedAt?: string | null;\n}\n\nexport interface GetDataPointOptions {\n /**\n * Return the row even after it was deleted (with `deletedAt` set and the\n * tombstone hash pair) instead of throwing `DataPointDeletedError`.\n */\n includeDeleted?: boolean;\n}\n\nexport interface DataPointListResult {\n dataPoints: DataPointRecord[];\n cursor: string | null;\n}\n\nexport interface ListDataPointsOptions {\n /**\n * Only return rows added at or after this ISO 8601 timestamp. Used by sync\n * loops that want incremental tails — pass the last seen `addedAt`.\n */\n since?: string;\n /** Page size. Capped at 1000 by the gateway. */\n limit?: number;\n /**\n * Include deleted (tombstoned) rows, each carrying `deletedAt`. Off by\n * default; without it the SDK also drops any tombstone the gateway leaks.\n */\n includeDeleted?: boolean;\n}\n\n// grantVersion and expiresAt are decimal-string uint256s — same wire format\n// the gateway expects. The caller is responsible for converting their bigint\n// to a decimal string and for signing GRANT_REGISTRATION_TYPES with matching\n// bigint values.\nexport interface CreateGrantParams {\n grantorAddress: string;\n granteeId: string;\n scopes: string[];\n grantVersion: string;\n expiresAt: string;\n signature: string;\n}\n\nexport interface RevokeGrantParams {\n grantId: string;\n grantorAddress: string;\n grantVersion: string;\n signature: string;\n}\n\nexport interface RegisterServerParams {\n ownerAddress: string;\n serverAddress: string;\n publicKey: string;\n serverUrl: string;\n signature: string;\n}\n\nexport interface RegisterServerResult {\n serverId?: string;\n alreadyRegistered: boolean;\n}\n\nexport interface RegisterBuilderParams {\n ownerAddress: string;\n // Wallet the builder authenticates to the Personal Server with. The\n // builderId is deterministically derived from (owner, grantee, publicKey,\n // appUrl) so this triple pins the on-chain identity.\n granteeAddress: string;\n publicKey: string;\n appUrl: string;\n signature: string;\n}\n\nexport interface RegisterBuilderResult {\n builderId?: string;\n alreadyRegistered: boolean;\n}\n\n// AddData on DataRegistryV2. dataHash + metadataHash are bytes32 commitments\n// to the off-chain payload + its metadata. expectedVersion is a CAS knob —\n// the gateway/contract rejects on 409 if a higher version is already stored,\n// and the error body surfaces `currentExpectedVersion` so callers can re-sign.\nexport interface RegisterDataPointParams {\n ownerAddress: string;\n scope: string;\n dataHash: string;\n metadataHash: string;\n expectedVersion: string;\n signature: string;\n}\n\nexport interface RegisterDataPointResult {\n dataPointId?: string;\n expectedVersion?: string;\n}\n\n// Deletion = an owner-signed AddData for version current+1 carrying the\n// tombstone hash pair (see protocol/data-point-deletion.ts). The gateway\n// reconstructs the AddData from the body plus the tombstone constants and\n// recovers the signer, so the hashes are NOT on the wire. Used at\n// DELETE /v1/data/:dataPointId. expectedVersion is the tombstone's version\n// as a decimal uint256 string; the signature is the raw EIP-712 hex.\nexport interface DeleteDataPointParams {\n ownerAddress: string;\n scope: string;\n expectedVersion: string;\n signature: string;\n}\n\n// The tombstone version record the gateway returns on 200. Fields are\n// optional because, like RegisterDataPointResult, the SDK tolerates either\n// a bare body or an enveloped `{data}`; `deletedAt` is the durable marker.\nexport interface DeleteDataPointResult {\n dataPointId?: string;\n ownerAddress?: string;\n scope?: string;\n dataHash?: string;\n metadataHash?: string;\n expectedVersion?: string;\n deletedAt?: string | null;\n}\n\n// ── Escrow / data-access payment path ───────────────────────────────────────\n// /v1/escrow/pay debits the payer's escrow balance for a payable op. For a\n// Legacy grants use opType='grant' and opId=grantId. Standalone receipt-bound\n// reads use opType='data_access' and opId=accessRecord.recordId. amount and\n// paymentNonce are decimal uint256 strings on the wire. The signature is the\n// raw EIP-712 hex of GENERIC_PAYMENT_TYPES against escrowPaymentDomain.\n\n// A server-signed delivery receipt attached to a data-access payment. The\n// signature is over RECORD_DATA_ACCESS_TYPES against dataRegistryDomain; the\n// signer must be a personal server the data point's owner has registered as\n// trusted. Shape validation in clients does not verify this signature; the\n// gateway verifies it before re-using it on-chain in the next /v1/settle pass\n// via DataRegistryV2.recordDataAccess, where `recordId` dedupes via\n// `_usedRecordIds`.\nexport interface AccessRecord {\n dataPointId: string;\n // Decimal-string uint256 — the data point version being attested to.\n version: string;\n // Must equal the enclosing payment's payerAddress (the gateway enforces).\n accessor: string;\n recordId: string;\n signature: string;\n}\n\nexport interface PayForOperationParams {\n payerAddress: string;\n opType: string;\n opId: string;\n asset: string;\n amount: string;\n // Per-payer monotonic; (payer, nonce, kind) must be unique. The gateway\n // returns 409 if reused — bump and re-sign.\n paymentNonce: string;\n signature: string;\n // Optional: attach a server-signed access record so the next /v1/settle\n // pass submits a recordDataAccess tx alongside the payment settlement.\n // Required for data-access payments (the second-and-onward payments per\n // grant) that want their on-chain `totalAccesses` counter to advance.\n accessRecord?: AccessRecord;\n}\n\nexport interface PayForOperationResult {\n opType: string;\n opId: string;\n payerAddress: string;\n asset: string;\n amount: string;\n // Echoes how the gateway split this payment. `registrationPaid` is true on\n // the first payment for a grant (which bundles both fees) and false on\n // subsequent data-access-only payments. Off-chain ledger state only — the\n // on-chain settlement of the registration is tracked by the grant's\n // `status` field, not this flag.\n breakdown: {\n registrationFee: string;\n dataAccessFee: string;\n registrationPaid: boolean;\n };\n paymentNonce: string;\n paidAt: string;\n}\n\n// ── Settle / reconcile ──────────────────────────────────────────────────────\n// POST /v1/settle drains pending-on-chain rows (grants, servers, builders,\n// data points, data-point statuses, access records) to the relayer, then\n// promotes 'submitting' → 'confirmed' and 'confirmed' → 'finalized' for\n// previously-submitted rows. One call does all three; the response surfaces\n// each phase's outcomes.\n\n// The op-types the settle endpoint emits in `items[]`. Kept as a union so\n// callers can narrow inside the discriminated SettleItem shape. Mirrors the\n// gateway's drain phases (drainGrants/drainServers/drainBuilders/\n// drainDataPoints/drainDataPointStatuses/drainAccessRecords) — keep in sync\n// when the gateway adds a drain.\nexport type SettleOpType =\n | \"grant\"\n | \"server\"\n | \"data\"\n | \"access\"\n | \"builder\"\n | \"data-status\";\n\nexport type SettleItem =\n | {\n opType: SettleOpType;\n opId: string;\n // 'confirmed' when the submit function waited for the receipt and it\n // mined (registerAndSettle path); 'submitting' when only the tx was\n // sent (no receipt wait).\n status: \"submitting\" | \"confirmed\";\n settleTxHash: string | null;\n settleSubmittedAt: string | null;\n // Block height the tx mined in; only set when status === 'confirmed'.\n chainBlockHeight: string | null;\n revocationTxHash: string | null;\n revocationSubmittedAt: string | null;\n // True while lib/settle.ts is in placeholder mode for this row's pass.\n placeholder: boolean;\n }\n | {\n opType: SettleOpType;\n opId: string;\n status: \"skipped\";\n reason: string;\n }\n | {\n opType: SettleOpType;\n opId: string;\n status: \"failed\";\n error: string;\n };\n\n// Outcome of the housekeeping pass that retries earlier `submitting` rows\n// whose receipt arrived after the prior /v1/settle's wait budget elapsed.\nexport interface SettlePromoteResult {\n opType: SettleOpType;\n opId: string;\n status: \"confirmed\" | \"failed\" | \"pending\" | \"skipped\";\n txHash: string;\n chainBlockHeight: string | null;\n reason?: string;\n}\n\n// Outcome of the reconcile pass that advances 'confirmed' → 'finalized' once\n// the chain's finalized tip catches up past the tx's block (or reverts to\n// 'pending' on reorg detection).\nexport interface SettleReconcileItem {\n opId: string;\n status: \"finalized\" | \"reorged\" | \"unchanged\";\n chainBlockHeight: string | null;\n settleTxHash: string | null;\n reason?: string;\n}\n\nexport interface SettleParams {\n // Per-phase cap. Bounded by MAX_LIMIT on the gateway side; omit to use\n // the gateway's default BATCH_LIMIT.\n limit?: number;\n}\n\nexport interface SettleResult {\n scanned: number;\n submitted: number;\n confirmed: number;\n skipped: number;\n failed: number;\n items: SettleItem[];\n promoted: { count: number; items: SettlePromoteResult[] };\n reconciled: {\n scanned: number;\n finalized: number;\n reorged: number;\n unchanged: number;\n items: SettleReconcileItem[];\n };\n // Present only when the gateway is configured for paced submission —\n // spreads work across several blocks within one /v1/settle invocation.\n paced?: { iterations: number };\n}\n\n// /v1/escrow/balance?account=... — pure read. Returns finalized balances by\n// asset, plus the lifecycle breakdown of deposits.\nexport interface EscrowBalanceEntry {\n asset: string;\n // Gross credited deposits for (account, asset). Decremented only when the\n // reconcile pass marks a payment finalized — NOT on /v1/escrow/pay.\n balance: string;\n // Sum of claimedAmount for deposits still in 'submitted' status — surfaced\n // separately so clients don't conflate \"credited\" with \"deposit announced\n // but not yet confirmed.\"\n pendingAmount: string;\n // Sum of payments.amount for (account, asset) regardless of settled status —\n // mirrors the /v1/escrow/pay handler's soft-lock counter. Subtract from\n // `balance` to see how much the payer can still authorise.\n authorizedAmount: string;\n // `max(balance − authorizedAmount, 0)`. The headroom a payer has against\n // the soft-lock before /v1/escrow/pay starts returning 402.\n availableAmount: string;\n updatedAt: string | null;\n}\n\nexport interface EscrowDepositSubmitted {\n txHash: string;\n submittedAt: string;\n claimedAsset: string;\n claimedAmount: string;\n}\n\nexport interface EscrowDepositFinalized {\n txHash: string;\n finalizedAt: string | null;\n blockNumber: string | null;\n claimedAsset: string;\n claimedAmount: string;\n}\n\nexport interface EscrowDepositFailed {\n txHash: string;\n submittedAt: string;\n claimedAsset: string;\n claimedAmount: string;\n lastError: string | null;\n}\n\nexport interface EscrowBalance {\n account: string;\n balances: EscrowBalanceEntry[];\n deposits: {\n submitted: EscrowDepositSubmitted[];\n finalized: EscrowDepositFinalized[];\n failed: EscrowDepositFailed[];\n };\n}\n\n// /v1/escrow/deposit announces an on-chain deposit tx so the gateway can\n// reconcile it into the payer's balance. The gateway extracts the credited\n// account from calldata — no off-chain claim about who paid.\nexport interface SubmitDepositParams {\n txHash: string;\n}\n\nexport interface DepositState {\n txHash: string;\n account: string;\n // 'submitted' | 'finalized' | 'failed' — kept open since the gateway adds\n // states (e.g. 'orphaned') as the deposit flow evolves.\n status: string;\n blockNumber: string | null;\n submittedAt: string;\n finalizedAt: string | null;\n lastError: string | null;\n}\n\nexport interface GatewayClient {\n isRegisteredBuilder(address: string): Promise<boolean>;\n getBuilder(address: string): Promise<Builder | null>;\n getGrant(grantId: string): Promise<GatewayGrantResponse | null>;\n listGrantsByUser(userAddress: string): Promise<GrantListItem[]>;\n getSchemaForScope(scope: string): Promise<Schema | null>;\n getServer(address: string): Promise<ServerInfo | null>;\n /**\n * List every personal server an owner has registered — split into `active`\n * (currently trusted) and `revoked` (deregistered). Each list is ordered\n * newest-first; `active[0]` is the sensible default when the caller just\n * needs one URL for the owner. Empty owner returns `{active: [], revoked: [], count: 0}`.\n * Discovery-only endpoint — no per-server attestation; use `getServer` for that.\n */\n listServersByOwner(owner: string): Promise<OwnerServersResult>;\n /**\n * Fetch a single data point by its deterministic id (keccak256 of (owner, scope)).\n * Returns null on 404. Throws `DataPointDeletedError` on 410, or when the row is a\n * tombstone, unless `options.includeDeleted` is set. The gateway omits `status` from\n * the response body -- read it from the on-chain DataRegistryV2 contract when you need\n * the canonical lifecycle state.\n */\n getDataPoint(\n dataPointId: string,\n options?: GetDataPointOptions,\n ): Promise<DataPointRecord | null>;\n /**\n * Page through an owner's data points. Cursor is opaque; pass `null` for the first\n * page and feed back `result.cursor` until it returns null.\n * Deleted rows are excluded unless `options.includeDeleted` is set.\n */\n listDataPointsByOwner(\n owner: string,\n cursor: string | null,\n options?: ListDataPointsOptions,\n ): Promise<DataPointListResult>;\n getSchema(schemaId: string): Promise<Schema | null>;\n registerServer(params: RegisterServerParams): Promise<RegisterServerResult>;\n registerBuilder(\n params: RegisterBuilderParams,\n ): Promise<RegisterBuilderResult>;\n registerDataPoint(\n params: RegisterDataPointParams,\n ): Promise<RegisterDataPointResult>;\n /**\n * Tombstone a data point: `DELETE /v1/data/:dataPointId` with the owner's\n * AddData signature for version `current + 1`. The dataPointId is derived\n * from (ownerAddress, scope). Throws `DataPointVersionConflictError` on\n * 409, `DataPointDeletedError` on 410 (already deleted),\n * `DataPointNotFoundError` on 404.\n */\n deleteDataPoint(\n params: DeleteDataPointParams,\n ): Promise<DeleteDataPointResult>;\n createGrant(params: CreateGrantParams): Promise<{ grantId?: string }>;\n revokeGrant(params: RevokeGrantParams): Promise<void>;\n getEscrowBalance(account: string): Promise<EscrowBalance>;\n submitEscrowDeposit(params: SubmitDepositParams): Promise<DepositState>;\n payForOperation(\n params: PayForOperationParams,\n ): Promise<PayForOperationResult>;\n settle(params?: SettleParams): Promise<SettleResult>;\n}\n\n// Attach the derived `permissions` view to a grant record read back from the\n// gateway. The wire `scopes` are left untouched.\nfunction withGrantPermissions<T extends GatewayGrantResponse>(grant: T): T {\n // Gateway responses are untrusted runtime data despite their type. The\n // `permissions` view is SDK-owned: drop whatever the body carried under\n // that name, then derive only from a well-formed string[] and leave the\n // field absent otherwise, so a spoofed or stale value can never be\n // rendered as this grant's authority.\n const stripped = { ...grant };\n delete stripped.permissions;\n const scopes: unknown = stripped.scopes;\n if (!Array.isArray(scopes)) {\n return stripped;\n }\n const permissions = tryGrantPermissions(scopes as string[]);\n return permissions === undefined ? stripped : { ...stripped, permissions };\n}\n\nexport function createGatewayClient(baseUrl: string): GatewayClient {\n const base = baseUrl.replace(/\\/+$/, \"\");\n\n function malformedBody(res: Response): Error {\n return new Error(\n `Gateway error: ${res.status} malformed response body (expected a JSON envelope)`,\n );\n }\n\n // GET responses are `{ data, proof, pagination? }`. A 200 whose body is\n // empty, not JSON, or not an object with `data` is a gateway bug, not a\n // record: fail with a clear error instead of returning undefined.\n async function readEnvelope<T>(\n res: Response,\n ): Promise<Record<string, unknown> & { data: T }> {\n const envelope = await readJsonValue(res);\n if (!isPlainObject(envelope) || !(\"data\" in envelope)) {\n throw malformedBody(res);\n }\n return envelope as Record<string, unknown> & { data: T };\n }\n\n async function unwrapEnvelope<T>(res: Response): Promise<T> {\n return (await readEnvelope<T>(res)).data;\n }\n\n function getMutationId(body: unknown, key: string): string | undefined {\n if (!isPlainObject(body)) return undefined;\n const value = body[key] ?? body[\"id\"];\n return typeof value === \"string\" ? value : undefined;\n }\n\n // Mutation responses are bare JSON; GET responses are enveloped. Accept\n // either so a gateway that wraps the tombstone record still round-trips.\n // Any body that is not a plain object (empty 204, `null`, an array, an\n // HTML error page) reads as `{}` so the status-code mapping still wins.\n async function readBody(res: Response): Promise<Record<string, unknown>> {\n const raw = await readJsonObject(res);\n const data = raw[\"data\"];\n if (isPlainObject(data) && \"proof\" in raw) {\n return data;\n }\n return raw;\n }\n\n function stringOrUndefined(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n }\n\n async function deletedError(\n res: Response,\n details: { dataPointId?: string; scope?: string; ownerAddress?: string },\n ): Promise<DataPointDeletedError> {\n const body = await readBody(res);\n return new DataPointDeletedError(\n `Data point ${details.dataPointId ?? details.scope ?? \"\"} has been deleted`,\n { ...details, deletedAt: tombstoneDeletedAt(body) },\n );\n }\n\n return {\n async isRegisteredBuilder(address: string): Promise<boolean> {\n const builder = await this.getBuilder(address);\n return builder !== null;\n },\n\n async getBuilder(address: string): Promise<Builder | null> {\n const res = await fetch(`${base}/v1/builders/${address}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<Builder>(res);\n },\n\n async getGrant(grantId: string): Promise<GatewayGrantResponse | null> {\n const res = await fetch(`${base}/v1/grants/${grantId}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return withGrantPermissions(\n await unwrapEnvelope<GatewayGrantResponse>(res),\n );\n },\n\n async listGrantsByUser(userAddress: string): Promise<GrantListItem[]> {\n const res = await fetch(`${base}/v1/grants?user=${userAddress}`);\n if (res.status === 404) return [];\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const grants = await unwrapEnvelope<GrantListItem[]>(res);\n return grants.map(withGrantPermissions);\n },\n\n async getSchemaForScope(scope: string): Promise<Schema | null> {\n const res = await fetch(`${base}/v1/schemas?scope=${scope}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<Schema>(res);\n },\n\n async getServer(address: string): Promise<ServerInfo | null> {\n const res = await fetch(`${base}/v1/servers/${address}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<ServerInfo>(res);\n },\n\n async listServersByOwner(owner: string): Promise<OwnerServersResult> {\n // URLSearchParams encodes the owner so a malformed value (e.g.\n // \"0xabc&foo=bar\") can't inject extra query params. Same pattern as\n // listDataPointsByOwner.\n const params = new URLSearchParams({ owner });\n const res = await fetch(`${base}/v1/servers?${params.toString()}`);\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n // Unlike /v1/servers/:address, the list endpoint returns the body\n // directly — no GatewayEnvelope, no attestation (discovery-only).\n return (await res.json()) as OwnerServersResult;\n },\n\n async getDataPoint(\n dataPointId: string,\n options?: GetDataPointOptions,\n ): Promise<DataPointRecord | null> {\n const query = options?.includeDeleted ? \"?includeDeleted=true\" : \"\";\n const res = await fetch(`${base}/v1/data/${dataPointId}${query}`);\n if (res.status === 404) return null;\n if (res.status === 410) {\n throw await deletedError(res, { dataPointId });\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const record = await unwrapEnvelope<DataPointRecord>(res);\n // Never hand a tombstone back as data unless the caller opted in --\n // guards against a gateway that returns 200 + deletedAt on plain reads.\n if (!options?.includeDeleted && isDataPointTombstone(record)) {\n throw new DataPointDeletedError(\n `Data point ${dataPointId} has been deleted`,\n {\n dataPointId,\n scope: record.scope,\n ownerAddress: record.ownerAddress,\n deletedAt: tombstoneDeletedAt(record),\n },\n );\n }\n return record;\n },\n\n async listDataPointsByOwner(\n owner: string,\n cursor: string | null,\n options?: ListDataPointsOptions,\n ): Promise<DataPointListResult> {\n const params = new URLSearchParams({ user: owner });\n if (cursor !== null) {\n params.set(\"cursor\", cursor);\n }\n if (options?.since) {\n params.set(\"since\", options.since);\n }\n if (options?.limit !== undefined) {\n params.set(\"limit\", String(options.limit));\n }\n if (options?.includeDeleted) {\n params.set(\"includeDeleted\", \"true\");\n }\n const res = await fetch(`${base}/v1/data?${params.toString()}`);\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n // Next-page cursor lives in the envelope's `pagination.nextCursor`\n // (a sibling of `data`), so read the full envelope rather than going\n // through `unwrapEnvelope`, which returns only `data`.\n const envelope = await readEnvelope<unknown>(res);\n if (\n !isPlainObject(envelope.data) ||\n !Array.isArray(envelope.data[\"dataPoints\"])\n ) {\n throw malformedBody(res);\n }\n const rows = envelope.data[\"dataPoints\"] as DataPointRecord[];\n const pagination = isPlainObject(envelope[\"pagination\"])\n ? envelope[\"pagination\"]\n : undefined;\n const rawCursor = pagination?.[\"nextCursor\"];\n const nextCursor =\n pagination?.[\"hasMore\"] === false || typeof rawCursor !== \"string\"\n ? null\n : rawCursor;\n // Tombstones only surface when asked for; drop any the gateway leaks\n // on a plain list so sync loops never ingest one as data.\n const dataPoints = options?.includeDeleted\n ? rows\n : rows.filter((row) => !isDataPointTombstone(row));\n return {\n dataPoints,\n cursor: nextCursor,\n };\n },\n\n async getSchema(schemaId: string): Promise<Schema | null> {\n const res = await fetch(`${base}/v1/schemas/${schemaId}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<Schema>(res);\n },\n\n async registerServer(\n params: RegisterServerParams,\n ): Promise<RegisterServerResult> {\n const res = await fetch(`${base}/v1/servers`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n serverAddress: params.serverAddress,\n publicKey: params.publicKey,\n serverUrl: params.serverUrl,\n }),\n });\n if (res.status === 409) {\n const body = await readJsonObject(res);\n return {\n serverId: getMutationId(body, \"serverId\"),\n alreadyRegistered: true,\n };\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const body = await readJsonObject(res);\n return {\n serverId: getMutationId(body, \"serverId\"),\n alreadyRegistered: false,\n };\n },\n\n async registerBuilder(\n params: RegisterBuilderParams,\n ): Promise<RegisterBuilderResult> {\n const res = await fetch(`${base}/v1/builders`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n granteeAddress: params.granteeAddress,\n publicKey: params.publicKey,\n appUrl: params.appUrl,\n }),\n });\n // 409 is idempotent — the gateway's current 409 body doesn't include\n // the builderId, but we tolerate it in case that changes (mirrors the\n // registerServer / createGrant shape).\n if (res.status === 409) {\n const body = await readJsonObject(res);\n return {\n builderId: getMutationId(body, \"builderId\"),\n alreadyRegistered: true,\n };\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const body = await readJsonObject(res);\n return {\n builderId: getMutationId(body, \"builderId\"),\n alreadyRegistered: false,\n };\n },\n\n async registerDataPoint(\n params: RegisterDataPointParams,\n ): Promise<RegisterDataPointResult> {\n const res = await fetch(`${base}/v1/data`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n scope: params.scope,\n dataHash: params.dataHash,\n metadataHash: params.metadataHash,\n expectedVersion: params.expectedVersion,\n }),\n });\n // 409 is a real failure here (stale CAS), not an idempotent replay —\n // surface the gateway's error message verbatim so the caller knows\n // what `currentExpectedVersion` to re-sign against.\n if (!res.ok) {\n const body = await readJsonObject(res);\n const detail = stringOrUndefined(body[\"error\"]) ?? res.statusText;\n throw new Error(`Gateway error: ${res.status} ${detail}`);\n }\n const body = await readJsonObject(res);\n return {\n dataPointId: getMutationId(body, \"dataPointId\"),\n expectedVersion: stringOrUndefined(body[\"expectedVersion\"]),\n };\n },\n\n async deleteDataPoint(\n params: DeleteDataPointParams,\n ): Promise<DeleteDataPointResult> {\n // The gateway keys the row on keccak256(abi.encode(owner, scope)) --\n // derive it locally rather than asking the caller for it, so the path\n // can never disagree with the signed (owner, scope).\n const dataPointId = deriveDataPointId(\n params.ownerAddress as `0x${string}`,\n params.scope,\n );\n const details = {\n dataPointId,\n scope: params.scope,\n ownerAddress: params.ownerAddress,\n };\n // Signature rides both in the body (the DELETE contract) and as the\n // Web3Signed Authorization header every other /v1 mutation uses.\n const res = await fetch(`${base}/v1/data/${dataPointId}`, {\n method: \"DELETE\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n scope: params.scope,\n expectedVersion: params.expectedVersion,\n signature: params.signature,\n }),\n });\n if (res.status === 404) {\n throw new DataPointNotFoundError(\n `Data point ${dataPointId} (scope '${params.scope}') is not registered`,\n details,\n );\n }\n if (res.status === 409) {\n const body = await readBody(res);\n const currentExpectedVersion = stringOrUndefined(\n body[\"currentExpectedVersion\"],\n );\n const detail = stringOrUndefined(body[\"error\"]) ?? res.statusText;\n throw new DataPointVersionConflictError(\n `Gateway error: 409 ${detail}`,\n {\n ...details,\n expectedVersion: params.expectedVersion,\n currentExpectedVersion,\n },\n );\n }\n if (res.status === 410) {\n throw await deletedError(res, details);\n }\n if (!res.ok) {\n // 400 = the recovered signer/hashes do not match the tombstone\n // AddData. Surface the gateway's message verbatim, like\n // registerDataPoint does.\n const body = await readBody(res);\n const detail = stringOrUndefined(body[\"error\"]) ?? res.statusText;\n throw new Error(`Gateway error: ${res.status} ${detail}`);\n }\n const body = await readBody(res);\n return {\n dataPointId: getMutationId(body, \"dataPointId\") ?? dataPointId,\n ownerAddress: stringOrUndefined(body[\"ownerAddress\"]),\n scope: stringOrUndefined(body[\"scope\"]),\n dataHash: stringOrUndefined(body[\"dataHash\"]),\n metadataHash: stringOrUndefined(body[\"metadataHash\"]),\n expectedVersion: stringOrUndefined(body[\"expectedVersion\"]),\n deletedAt: tombstoneDeletedAt(body),\n };\n },\n\n async createGrant(\n params: CreateGrantParams,\n ): Promise<{ grantId?: string }> {\n const res = await fetch(`${base}/v1/grants`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n grantorAddress: params.grantorAddress,\n granteeId: params.granteeId,\n scopes: params.scopes,\n grantVersion: params.grantVersion,\n expiresAt: params.expiresAt,\n }),\n });\n if (res.status === 409) {\n const body = await readJsonObject(res);\n return { grantId: getMutationId(body, \"grantId\") };\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const body = await readJsonObject(res);\n return { grantId: getMutationId(body, \"grantId\") };\n },\n\n async revokeGrant(params: RevokeGrantParams): Promise<void> {\n const res = await fetch(`${base}/v1/grants/${params.grantId}`, {\n method: \"DELETE\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n grantorAddress: params.grantorAddress,\n grantVersion: params.grantVersion,\n }),\n });\n if (res.status === 409) return;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n },\n\n async getEscrowBalance(account: string): Promise<EscrowBalance> {\n const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n // Unlike the rest of /v1, the balance endpoint returns the body\n // directly (no GatewayEnvelope wrap) — it's a pure read with no\n // gateway-signed attestation. See data-gateway api/v1/escrow/balance.ts.\n return (await res.json()) as EscrowBalance;\n },\n\n async submitEscrowDeposit(\n params: SubmitDepositParams,\n ): Promise<DepositState> {\n const res = await fetch(`${base}/v1/escrow/deposit`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ txHash: params.txHash }),\n });\n // The gateway returns 202 for \"accepted (still confirming)\" and 200 for\n // duplicate idempotent replays. Both carry the deposit's current state.\n if (res.status !== 200 && res.status !== 202) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as DepositState;\n },\n\n async payForOperation(\n params: PayForOperationParams,\n ): Promise<PayForOperationResult> {\n // Build the body without the accessRecord key when absent so the\n // gateway's \"missing optional\" branch matches the no-receipt case\n // exactly (an explicit `accessRecord: undefined` would JSON-serialize\n // to nothing — same result — but keeping it conditional makes wire\n // traces easier to read).\n const body: Record<string, unknown> = {\n payerAddress: params.payerAddress,\n opType: params.opType,\n opId: params.opId,\n asset: params.asset,\n amount: params.amount,\n paymentNonce: params.paymentNonce,\n };\n if (params.accessRecord) {\n body[\"accessRecord\"] = params.accessRecord;\n }\n const res = await fetch(`${base}/v1/escrow/pay`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as PayForOperationResult;\n },\n\n async settle(params?: SettleParams): Promise<SettleResult> {\n const res = await fetch(`${base}/v1/settle`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n // The gateway accepts an empty body; only `limit` is recognised.\n // Always send a JSON body so the gateway's req.body shape parse\n // doesn't have to deal with an undefined.\n body: JSON.stringify(params ?? {}),\n });\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as SettleResult;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA0D;AAC1D,oBAIO;AACP,iCAGO;AACP,qBAAkC;AAClC,2BAIO;AAimBP,SAAS,qBAAqD,OAAa;AAMzE,QAAM,WAAW,EAAE,GAAG,MAAM;AAC5B,SAAO,SAAS;AAChB,QAAM,SAAkB,SAAS;AACjC,MAAI,CAAC,MAAM,QAAQ,MAAM,GAAG;AAC1B,WAAO;AAAA,EACT;AACA,QAAM,kBAAc,0CAAoB,MAAkB;AAC1D,SAAO,gBAAgB,SAAY,WAAW,EAAE,GAAG,UAAU,YAAY;AAC3E;AAEO,SAAS,oBAAoB,SAAgC;AAClE,QAAM,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AAEvC,WAAS,cAAc,KAAsB;AAC3C,WAAO,IAAI;AAAA,MACT,kBAAkB,IAAI,MAAM;AAAA,IAC9B;AAAA,EACF;AAKA,iBAAe,aACb,KACgD;AAChD,UAAM,WAAW,UAAM,oCAAc,GAAG;AACxC,QAAI,KAAC,oCAAc,QAAQ,KAAK,EAAE,UAAU,WAAW;AACrD,YAAM,cAAc,GAAG;AAAA,IACzB;AACA,WAAO;AAAA,EACT;AAEA,iBAAe,eAAkB,KA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,QAI9C,MAAM,KAAK,UAAU,UAAU,CAAC,CAAC;AAAA,MACnC,CAAC;AACD,UAAI,CAAC,IAAI,IAAI;AACX,cAAM,IAAI,MAAM,kBAAkB,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,MAClE;AACA,aAAQ,MAAM,IAAI,KAAK;AAAA,IACzB;AAAA,EACF;AACF;","names":["body"]}
1
+ {"version":3,"sources":["../../src/protocol/gateway.ts"],"sourcesContent":["import { tryGrantPermissions, type GrantPermission } from \"./scope-actions\";\nimport {\n DataPointDeletedError,\n DataPointNotFoundError,\n DataPointVersionConflictError,\n} from \"../errors\";\nimport {\n isDataPointTombstone,\n tombstoneDeletedAt,\n} from \"./data-point-deletion\";\nimport { deriveDataPointId } from \"./lineage\";\nimport {\n isPlainObject,\n readJsonObject,\n readJsonValue,\n} from \"../utils/response-body\";\nimport type { EscrowBalanceResult } from \"./escrow\";\n\nexport type {\n EscrowBalanceEntry,\n EscrowBalanceResult,\n FailedDepositEntry as EscrowDepositFailed,\n FinalizedDepositEntry as EscrowDepositFinalized,\n SubmittedDepositEntry as EscrowDepositSubmitted,\n} from \"./escrow\";\n\nexport interface GatewayEnvelope<T> {\n data: T;\n proof: GatewayProof;\n /**\n * Cursor-based pagination metadata, present on list endpoints (e.g.\n * `GET /v1/data`). A sibling of `data`, not nested inside it — so callers\n * that need it must read the full envelope rather than going through\n * `unwrapEnvelope`, which intentionally returns only `data`.\n */\n pagination?: GatewayPagination;\n}\n\nexport interface GatewayPagination {\n limit: number;\n hasMore: boolean;\n /**\n * Opaque cursor for the NEXT page; pass back as the `cursor` query param.\n * Null when there are no further pages.\n */\n nextCursor: string | null;\n}\n\nexport interface GatewayProof {\n signature: string;\n timestamp: string;\n gatewayAddress: string;\n requestHash: string;\n responseHash: string;\n userSignature: string;\n status: string;\n chainBlockHeight: number;\n}\n\nexport interface Builder {\n id: string;\n ownerAddress: string;\n granteeAddress: string;\n publicKey: string;\n appUrl: string;\n addedAt: string;\n}\n\nexport interface Schema {\n id: string;\n ownerAddress: string;\n name: string;\n definitionUrl: string;\n scope: string;\n addedAt: string;\n}\n\n// Row shape returned by `GET /v1/servers?owner=…`. A discovery-only list —\n// the endpoint carries no per-item gateway attestation (use\n// `getServer(serverAddress)` if you need a verifiable single-server proof).\n// `status` is the gateway's chain-sync state ('pending' | 'confirmed' |\n// 'finalized' | 'reorged'); kept as an open string since the gateway may add\n// states without a SDK bump.\nexport interface OwnerServerRecord {\n id: string;\n ownerAddress: string;\n serverAddress: string;\n publicKey: string;\n serverUrl: string;\n status: string;\n chainBlockHeight: string | null;\n // ISO timestamp of the gateway-side upsert.\n addedAt: string;\n // ISO timestamp when the grantor deregistered this server. Always null for\n // entries in the `active` list, always non-null for `revoked`.\n revokedAt: string | null;\n}\n\n// Response from `GET /v1/servers?owner=…`. Split into two arrays; each is\n// ordered newest-first (`addedAt DESC`, `id ASC` tiebreaker) so `active[0]`\n// is unambiguously the newest active server — the sensible default when the\n// caller just needs one URL. The gateway caps the total across both arrays\n// at 200 — per-owner counts are tiny in practice, so no cursor.\nexport interface OwnerServersResult {\n active: OwnerServerRecord[];\n revoked: OwnerServerRecord[];\n count: number;\n}\n\nexport interface ServerInfo {\n id: string;\n ownerAddress: string;\n serverAddress: string;\n publicKey: string;\n serverUrl: string;\n addedAt: string;\n // ISO timestamp when the grantor deregistered this server, null while\n // active. The gateway returns this on /v1/servers/:address GETs since\n // covering revocation in the response keeps the attestation hash\n // authoritative for both states.\n revokedAt: string | null;\n}\n\n// Fee annotation surfaced on every GET grant response. Amounts are decimal\n// uint256 strings to match `/v1/escrow/pay`'s wire format. totalDue is a\n// snapshot — the gateway re-resolves fees at pay time, so clients shouldn't\n// cache this across requests.\nexport interface GatewayGrantFee {\n asset: string;\n registrationFee: string;\n dataAccessFee: string;\n totalDue: string;\n}\n\n// Lifecycle of a grant's on-chain settlement, tracked separately from the\n// fee-payment lifecycle (paymentStatus). Driven by POST /v1/settle:\n// pending — nothing on-chain yet\n// submitting — settle tx broadcast but receipt not yet observed\n// confirmed — settle tx mined successfully\n// finalized — finalized tip past the settle block, reorg-safe\n// reorged — finalized observation reverted; back to 'pending' on next settle\nexport type GatewayGrantStatus =\n | \"pending\"\n | \"submitting\"\n | \"confirmed\"\n | \"finalized\"\n | \"reorged\";\n\nexport interface GatewayGrantResponse {\n id: string;\n grantorAddress: string;\n granteeId: string;\n // The signed scope entries, verbatim (`[operation:]scope`, bare = read).\n // This is the wire form: it is what the grantor signed and what the\n // gateway stores. Render `permissions` instead of parsing these.\n scopes: string[];\n // Derived by the SDK at read time from `scopes` via grantPermissions():\n // one `{ scope, actions }` row per scope pattern, canonically ordered.\n // Never sent to the gateway and never part of the signed payload. Absent\n // when `scopes` carries an entry this SDK version cannot interpret (an\n // operation introduced after this release) - fall back to `scopes` and\n // do not assume such a grant is read-only.\n permissions?: GrantPermission[];\n status: GatewayGrantStatus;\n addedAt: string;\n // Grantor-signed deadline. null = perpetual grant (signed value was 0).\n expiresAt: string | null;\n // Derived at read time from expiresAt vs the gateway's clock — a snapshot,\n // not a cached truth. Re-check against expiresAt locally if you care.\n expired: boolean;\n revokedAt: string | null;\n revocationSignature: string | null;\n // 'pending' until the grant registration fee is settled via /v1/escrow/pay.\n paymentStatus: \"pending\" | \"paid\";\n paidAt: string | null;\n paidBy: string | null;\n // Decimal-string uint256 monotonic nonce; advances on every state change.\n grantVersion: string;\n // Settle metadata — populated as the grant progresses through the chain\n // lifecycle. Null while `status === 'pending'`.\n settleTxHash: string | null;\n settleSubmittedAt: string | null;\n // Revocation metadata — populated independently when the grantor signs\n // and the gateway pushes a deregister tx.\n revocationTxHash: string | null;\n revocationSubmittedAt: string | null;\n fee: GatewayGrantFee;\n}\n\nexport type GrantListItem = GatewayGrantResponse;\n\n// Mirror of a DataRegistryV2 row as the gateway exposes it. `id` is the\n// deterministic `keccak256(abi.encode(owner, scope))` dataPointId — the same\n// value the contract uses as its primary key. `expectedVersion` is the latest\n// version the gateway has accepted; the on-chain row may be one version behind\n// while a settle is still pending. The gateway response intentionally drops\n// `status` from the body — read it from the on-chain contract when you need\n// the canonical lifecycle state.\nexport interface DataPointRecord {\n id: string;\n ownerAddress: string;\n scope: string;\n dataHash: string;\n metadataHash: string;\n // Decimal-string uint256.\n expectedVersion: string;\n // ISO 8601 timestamp of the most recent gateway-side upsert.\n addedAt: string;\n // ISO 8601 timestamp of the deletion tombstone, null/absent while live.\n // Only present on reads that opted in via `includeDeleted`; a plain\n // `getDataPoint` of a deleted row throws `DataPointDeletedError` instead.\n deletedAt?: string | null;\n}\n\nexport interface GetDataPointOptions {\n /**\n * Return the row even after it was deleted (with `deletedAt` set and the\n * tombstone hash pair) instead of throwing `DataPointDeletedError`.\n */\n includeDeleted?: boolean;\n}\n\nexport interface DataPointListResult {\n dataPoints: DataPointRecord[];\n cursor: string | null;\n}\n\nexport interface ListDataPointsOptions {\n /**\n * Only return rows added at or after this ISO 8601 timestamp. Used by sync\n * loops that want incremental tails — pass the last seen `addedAt`.\n */\n since?: string;\n /** Page size. Capped at 1000 by the gateway. */\n limit?: number;\n /**\n * Include deleted (tombstoned) rows, each carrying `deletedAt`. Off by\n * default; without it the SDK also drops any tombstone the gateway leaks.\n */\n includeDeleted?: boolean;\n}\n\n// grantVersion and expiresAt are decimal-string uint256s — same wire format\n// the gateway expects. The caller is responsible for converting their bigint\n// to a decimal string and for signing GRANT_REGISTRATION_TYPES with matching\n// bigint values.\nexport interface CreateGrantParams {\n grantorAddress: string;\n granteeId: string;\n scopes: string[];\n grantVersion: string;\n expiresAt: string;\n signature: string;\n}\n\nexport interface RevokeGrantParams {\n grantId: string;\n grantorAddress: string;\n grantVersion: string;\n signature: string;\n}\n\nexport interface RegisterServerParams {\n ownerAddress: string;\n serverAddress: string;\n publicKey: string;\n serverUrl: string;\n signature: string;\n}\n\nexport interface RegisterServerResult {\n serverId?: string;\n alreadyRegistered: boolean;\n}\n\nexport interface RegisterBuilderParams {\n ownerAddress: string;\n // Wallet the builder authenticates to the Personal Server with. The\n // builderId is deterministically derived from (owner, grantee, publicKey,\n // appUrl) so this triple pins the on-chain identity.\n granteeAddress: string;\n publicKey: string;\n appUrl: string;\n signature: string;\n}\n\nexport interface RegisterBuilderResult {\n builderId?: string;\n alreadyRegistered: boolean;\n}\n\n// AddData on DataRegistryV2. dataHash + metadataHash are bytes32 commitments\n// to the off-chain payload + its metadata. expectedVersion is a CAS knob —\n// the gateway/contract rejects on 409 if a higher version is already stored,\n// and the error body surfaces `currentExpectedVersion` so callers can re-sign.\nexport interface RegisterDataPointParams {\n ownerAddress: string;\n scope: string;\n dataHash: string;\n metadataHash: string;\n expectedVersion: string;\n signature: string;\n}\n\nexport interface RegisterDataPointResult {\n dataPointId?: string;\n expectedVersion?: string;\n}\n\n// Deletion = an owner-signed AddData for version current+1 carrying the\n// tombstone hash pair (see protocol/data-point-deletion.ts). The gateway\n// reconstructs the AddData from the body plus the tombstone constants and\n// recovers the signer, so the hashes are NOT on the wire. Used at\n// DELETE /v1/data/:dataPointId. expectedVersion is the tombstone's version\n// as a decimal uint256 string; the signature is the raw EIP-712 hex.\nexport interface DeleteDataPointParams {\n ownerAddress: string;\n scope: string;\n expectedVersion: string;\n signature: string;\n}\n\n// The tombstone version record the gateway returns on 200. Fields are\n// optional because, like RegisterDataPointResult, the SDK tolerates either\n// a bare body or an enveloped `{data}`; `deletedAt` is the durable marker.\nexport interface DeleteDataPointResult {\n dataPointId?: string;\n ownerAddress?: string;\n scope?: string;\n dataHash?: string;\n metadataHash?: string;\n expectedVersion?: string;\n deletedAt?: string | null;\n}\n\n// ── Escrow / data-access payment path ───────────────────────────────────────\n// /v1/escrow/pay debits the payer's escrow balance for a payable op. For a\n// Legacy grants use opType='grant' and opId=grantId. Standalone receipt-bound\n// reads use opType='data_access' and opId=accessRecord.recordId. amount and\n// paymentNonce are decimal uint256 strings on the wire. The signature is the\n// raw EIP-712 hex of GENERIC_PAYMENT_TYPES against escrowPaymentDomain.\n\n// A server-signed delivery receipt attached to a data-access payment. The\n// signature is over RECORD_DATA_ACCESS_TYPES against dataRegistryDomain; the\n// signer must be a personal server the data point's owner has registered as\n// trusted. Shape validation in clients does not verify this signature; the\n// gateway verifies it before re-using it on-chain in the next /v1/settle pass\n// via DataRegistryV2.recordDataAccess, where `recordId` dedupes via\n// `_usedRecordIds`.\nexport interface AccessRecord {\n dataPointId: string;\n // Decimal-string uint256 — the data point version being attested to.\n version: string;\n // Must equal the enclosing payment's payerAddress (the gateway enforces).\n accessor: string;\n recordId: string;\n signature: string;\n}\n\nexport interface PayForOperationParams {\n payerAddress: string;\n opType: string;\n opId: string;\n asset: string;\n amount: string;\n // Per-payer monotonic; (payer, nonce, kind) must be unique. The gateway\n // returns 409 if reused — bump and re-sign.\n paymentNonce: string;\n signature: string;\n // Optional: attach a server-signed access record so the next /v1/settle\n // pass submits a recordDataAccess tx alongside the payment settlement.\n // Required for data-access payments (the second-and-onward payments per\n // grant) that want their on-chain `totalAccesses` counter to advance.\n accessRecord?: AccessRecord;\n}\n\nexport interface PayForOperationResult {\n opType: string;\n opId: string;\n payerAddress: string;\n asset: string;\n amount: string;\n // Echoes how the gateway split this payment. `registrationPaid` is true on\n // the first payment for a grant (which bundles both fees) and false on\n // subsequent data-access-only payments. Off-chain ledger state only — the\n // on-chain settlement of the registration is tracked by the grant's\n // `status` field, not this flag.\n breakdown: {\n registrationFee: string;\n dataAccessFee: string;\n registrationPaid: boolean;\n };\n paymentNonce: string;\n paidAt: string;\n}\n\n// ── Settle / reconcile ──────────────────────────────────────────────────────\n// POST /v1/settle drains pending-on-chain rows (grants, servers, builders,\n// data points, data-point statuses, access records) to the relayer, then\n// promotes 'submitting' → 'confirmed' and 'confirmed' → 'finalized' for\n// previously-submitted rows. One call does all three; the response surfaces\n// each phase's outcomes.\n\n// The op-types the settle endpoint emits in `items[]`. Kept as a union so\n// callers can narrow inside the discriminated SettleItem shape. Mirrors the\n// gateway's drain phases (drainGrants/drainServers/drainBuilders/\n// drainDataPoints/drainDataPointStatuses/drainAccessRecords) — keep in sync\n// when the gateway adds a drain.\nexport type SettleOpType =\n | \"grant\"\n | \"server\"\n | \"data\"\n | \"access\"\n | \"builder\"\n | \"data-status\";\n\nexport type SettleItem =\n | {\n opType: SettleOpType;\n opId: string;\n // 'confirmed' when the submit function waited for the receipt and it\n // mined (registerAndSettle path); 'submitting' when only the tx was\n // sent (no receipt wait).\n status: \"submitting\" | \"confirmed\";\n settleTxHash: string | null;\n settleSubmittedAt: string | null;\n // Block height the tx mined in; only set when status === 'confirmed'.\n chainBlockHeight: string | null;\n revocationTxHash: string | null;\n revocationSubmittedAt: string | null;\n // True while lib/settle.ts is in placeholder mode for this row's pass.\n placeholder: boolean;\n }\n | {\n opType: SettleOpType;\n opId: string;\n status: \"skipped\";\n reason: string;\n }\n | {\n opType: SettleOpType;\n opId: string;\n status: \"failed\";\n error: string;\n };\n\n// Outcome of the housekeeping pass that retries earlier `submitting` rows\n// whose receipt arrived after the prior /v1/settle's wait budget elapsed.\nexport interface SettlePromoteResult {\n opType: SettleOpType;\n opId: string;\n status: \"confirmed\" | \"failed\" | \"pending\" | \"skipped\";\n txHash: string;\n chainBlockHeight: string | null;\n reason?: string;\n}\n\n// Outcome of the reconcile pass that advances 'confirmed' → 'finalized' once\n// the chain's finalized tip catches up past the tx's block (or reverts to\n// 'pending' on reorg detection).\nexport interface SettleReconcileItem {\n opId: string;\n status: \"finalized\" | \"reorged\" | \"unchanged\";\n chainBlockHeight: string | null;\n settleTxHash: string | null;\n reason?: string;\n}\n\nexport interface SettleParams {\n // Per-phase cap. Bounded by MAX_LIMIT on the gateway side; omit to use\n // the gateway's default BATCH_LIMIT.\n limit?: number;\n}\n\nexport interface SettleResult {\n scanned: number;\n submitted: number;\n confirmed: number;\n skipped: number;\n failed: number;\n items: SettleItem[];\n promoted: { count: number; items: SettlePromoteResult[] };\n reconciled: {\n scanned: number;\n finalized: number;\n reorged: number;\n unchanged: number;\n items: SettleReconcileItem[];\n };\n // Present only when the gateway is configured for paced submission —\n // spreads work across several blocks within one /v1/settle invocation.\n paced?: { iterations: number };\n}\n\n/**\n * Legacy `GatewayClient` name for the canonical `/v1/escrow/balance` response.\n * `availableAmount` is `max(balance − authorizedAmount − withdrawingAmount, 0)`.\n */\nexport type EscrowBalance = EscrowBalanceResult;\n\n// /v1/escrow/deposit announces an on-chain deposit tx so the gateway can\n// reconcile it into the payer's balance. The gateway extracts the credited\n// account from calldata — no off-chain claim about who paid.\nexport interface SubmitDepositParams {\n txHash: string;\n}\n\nexport interface DepositState {\n txHash: string;\n account: string;\n // 'submitted' | 'finalized' | 'failed' — kept open since the gateway adds\n // states (e.g. 'orphaned') as the deposit flow evolves.\n status: string;\n blockNumber: string | null;\n submittedAt: string;\n finalizedAt: string | null;\n lastError: string | null;\n}\n\nexport interface GatewayClient {\n isRegisteredBuilder(address: string): Promise<boolean>;\n getBuilder(address: string): Promise<Builder | null>;\n getGrant(grantId: string): Promise<GatewayGrantResponse | null>;\n listGrantsByUser(userAddress: string): Promise<GrantListItem[]>;\n getSchemaForScope(scope: string): Promise<Schema | null>;\n getServer(address: string): Promise<ServerInfo | null>;\n /**\n * List every personal server an owner has registered — split into `active`\n * (currently trusted) and `revoked` (deregistered). Each list is ordered\n * newest-first; `active[0]` is the sensible default when the caller just\n * needs one URL for the owner. Empty owner returns `{active: [], revoked: [], count: 0}`.\n * Discovery-only endpoint — no per-server attestation; use `getServer` for that.\n */\n listServersByOwner(owner: string): Promise<OwnerServersResult>;\n /**\n * Fetch a single data point by its deterministic id (keccak256 of (owner, scope)).\n * Returns null on 404. Throws `DataPointDeletedError` on 410, or when the row is a\n * tombstone, unless `options.includeDeleted` is set. The gateway omits `status` from\n * the response body -- read it from the on-chain DataRegistryV2 contract when you need\n * the canonical lifecycle state.\n */\n getDataPoint(\n dataPointId: string,\n options?: GetDataPointOptions,\n ): Promise<DataPointRecord | null>;\n /**\n * Page through an owner's data points. Cursor is opaque; pass `null` for the first\n * page and feed back `result.cursor` until it returns null.\n * Deleted rows are excluded unless `options.includeDeleted` is set.\n */\n listDataPointsByOwner(\n owner: string,\n cursor: string | null,\n options?: ListDataPointsOptions,\n ): Promise<DataPointListResult>;\n getSchema(schemaId: string): Promise<Schema | null>;\n registerServer(params: RegisterServerParams): Promise<RegisterServerResult>;\n registerBuilder(\n params: RegisterBuilderParams,\n ): Promise<RegisterBuilderResult>;\n registerDataPoint(\n params: RegisterDataPointParams,\n ): Promise<RegisterDataPointResult>;\n /**\n * Tombstone a data point: `DELETE /v1/data/:dataPointId` with the owner's\n * AddData signature for version `current + 1`. The dataPointId is derived\n * from (ownerAddress, scope). Throws `DataPointVersionConflictError` on\n * 409, `DataPointDeletedError` on 410 (already deleted),\n * `DataPointNotFoundError` on 404.\n */\n deleteDataPoint(\n params: DeleteDataPointParams,\n ): Promise<DeleteDataPointResult>;\n createGrant(params: CreateGrantParams): Promise<{ grantId?: string }>;\n revokeGrant(params: RevokeGrantParams): Promise<void>;\n getEscrowBalance(account: string): Promise<EscrowBalanceResult>;\n submitEscrowDeposit(params: SubmitDepositParams): Promise<DepositState>;\n payForOperation(\n params: PayForOperationParams,\n ): Promise<PayForOperationResult>;\n settle(params?: SettleParams): Promise<SettleResult>;\n}\n\n// Attach the derived `permissions` view to a grant record read back from the\n// gateway. The wire `scopes` are left untouched.\nfunction withGrantPermissions<T extends GatewayGrantResponse>(grant: T): T {\n // Gateway responses are untrusted runtime data despite their type. The\n // `permissions` view is SDK-owned: drop whatever the body carried under\n // that name, then derive only from a well-formed string[] and leave the\n // field absent otherwise, so a spoofed or stale value can never be\n // rendered as this grant's authority.\n const stripped = { ...grant };\n delete stripped.permissions;\n const scopes: unknown = stripped.scopes;\n if (!Array.isArray(scopes)) {\n return stripped;\n }\n const permissions = tryGrantPermissions(scopes as string[]);\n return permissions === undefined ? stripped : { ...stripped, permissions };\n}\n\nexport function createGatewayClient(baseUrl: string): GatewayClient {\n const base = baseUrl.replace(/\\/+$/, \"\");\n\n function malformedBody(res: Response): Error {\n return new Error(\n `Gateway error: ${res.status} malformed response body (expected a JSON envelope)`,\n );\n }\n\n // GET responses are `{ data, proof, pagination? }`. A 200 whose body is\n // empty, not JSON, or not an object with `data` is a gateway bug, not a\n // record: fail with a clear error instead of returning undefined.\n async function readEnvelope<T>(\n res: Response,\n ): Promise<Record<string, unknown> & { data: T }> {\n const envelope = await readJsonValue(res);\n if (!isPlainObject(envelope) || !(\"data\" in envelope)) {\n throw malformedBody(res);\n }\n return envelope as Record<string, unknown> & { data: T };\n }\n\n async function unwrapEnvelope<T>(res: Response): Promise<T> {\n return (await readEnvelope<T>(res)).data;\n }\n\n function getMutationId(body: unknown, key: string): string | undefined {\n if (!isPlainObject(body)) return undefined;\n const value = body[key] ?? body[\"id\"];\n return typeof value === \"string\" ? value : undefined;\n }\n\n // Mutation responses are bare JSON; GET responses are enveloped. Accept\n // either so a gateway that wraps the tombstone record still round-trips.\n // Any body that is not a plain object (empty 204, `null`, an array, an\n // HTML error page) reads as `{}` so the status-code mapping still wins.\n async function readBody(res: Response): Promise<Record<string, unknown>> {\n const raw = await readJsonObject(res);\n const data = raw[\"data\"];\n if (isPlainObject(data) && \"proof\" in raw) {\n return data;\n }\n return raw;\n }\n\n function stringOrUndefined(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n }\n\n async function deletedError(\n res: Response,\n details: { dataPointId?: string; scope?: string; ownerAddress?: string },\n ): Promise<DataPointDeletedError> {\n const body = await readBody(res);\n return new DataPointDeletedError(\n `Data point ${details.dataPointId ?? details.scope ?? \"\"} has been deleted`,\n { ...details, deletedAt: tombstoneDeletedAt(body) },\n );\n }\n\n return {\n async isRegisteredBuilder(address: string): Promise<boolean> {\n const builder = await this.getBuilder(address);\n return builder !== null;\n },\n\n async getBuilder(address: string): Promise<Builder | null> {\n const res = await fetch(`${base}/v1/builders/${address}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<Builder>(res);\n },\n\n async getGrant(grantId: string): Promise<GatewayGrantResponse | null> {\n const res = await fetch(`${base}/v1/grants/${grantId}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return withGrantPermissions(\n await unwrapEnvelope<GatewayGrantResponse>(res),\n );\n },\n\n async listGrantsByUser(userAddress: string): Promise<GrantListItem[]> {\n const res = await fetch(`${base}/v1/grants?user=${userAddress}`);\n if (res.status === 404) return [];\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const grants = await unwrapEnvelope<GrantListItem[]>(res);\n return grants.map(withGrantPermissions);\n },\n\n async getSchemaForScope(scope: string): Promise<Schema | null> {\n const res = await fetch(`${base}/v1/schemas?scope=${scope}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<Schema>(res);\n },\n\n async getServer(address: string): Promise<ServerInfo | null> {\n const res = await fetch(`${base}/v1/servers/${address}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<ServerInfo>(res);\n },\n\n async listServersByOwner(owner: string): Promise<OwnerServersResult> {\n // URLSearchParams encodes the owner so a malformed value (e.g.\n // \"0xabc&foo=bar\") can't inject extra query params. Same pattern as\n // listDataPointsByOwner.\n const params = new URLSearchParams({ owner });\n const res = await fetch(`${base}/v1/servers?${params.toString()}`);\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n // Unlike /v1/servers/:address, the list endpoint returns the body\n // directly — no GatewayEnvelope, no attestation (discovery-only).\n return (await res.json()) as OwnerServersResult;\n },\n\n async getDataPoint(\n dataPointId: string,\n options?: GetDataPointOptions,\n ): Promise<DataPointRecord | null> {\n const query = options?.includeDeleted ? \"?includeDeleted=true\" : \"\";\n const res = await fetch(`${base}/v1/data/${dataPointId}${query}`);\n if (res.status === 404) return null;\n if (res.status === 410) {\n throw await deletedError(res, { dataPointId });\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const record = await unwrapEnvelope<DataPointRecord>(res);\n // Never hand a tombstone back as data unless the caller opted in --\n // guards against a gateway that returns 200 + deletedAt on plain reads.\n if (!options?.includeDeleted && isDataPointTombstone(record)) {\n throw new DataPointDeletedError(\n `Data point ${dataPointId} has been deleted`,\n {\n dataPointId,\n scope: record.scope,\n ownerAddress: record.ownerAddress,\n deletedAt: tombstoneDeletedAt(record),\n },\n );\n }\n return record;\n },\n\n async listDataPointsByOwner(\n owner: string,\n cursor: string | null,\n options?: ListDataPointsOptions,\n ): Promise<DataPointListResult> {\n const params = new URLSearchParams({ user: owner });\n if (cursor !== null) {\n params.set(\"cursor\", cursor);\n }\n if (options?.since) {\n params.set(\"since\", options.since);\n }\n if (options?.limit !== undefined) {\n params.set(\"limit\", String(options.limit));\n }\n if (options?.includeDeleted) {\n params.set(\"includeDeleted\", \"true\");\n }\n const res = await fetch(`${base}/v1/data?${params.toString()}`);\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n // Next-page cursor lives in the envelope's `pagination.nextCursor`\n // (a sibling of `data`), so read the full envelope rather than going\n // through `unwrapEnvelope`, which returns only `data`.\n const envelope = await readEnvelope<unknown>(res);\n if (\n !isPlainObject(envelope.data) ||\n !Array.isArray(envelope.data[\"dataPoints\"])\n ) {\n throw malformedBody(res);\n }\n const rows = envelope.data[\"dataPoints\"] as DataPointRecord[];\n const pagination = isPlainObject(envelope[\"pagination\"])\n ? envelope[\"pagination\"]\n : undefined;\n const rawCursor = pagination?.[\"nextCursor\"];\n const nextCursor =\n pagination?.[\"hasMore\"] === false || typeof rawCursor !== \"string\"\n ? null\n : rawCursor;\n // Tombstones only surface when asked for; drop any the gateway leaks\n // on a plain list so sync loops never ingest one as data.\n const dataPoints = options?.includeDeleted\n ? rows\n : rows.filter((row) => !isDataPointTombstone(row));\n return {\n dataPoints,\n cursor: nextCursor,\n };\n },\n\n async getSchema(schemaId: string): Promise<Schema | null> {\n const res = await fetch(`${base}/v1/schemas/${schemaId}`);\n if (res.status === 404) return null;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return unwrapEnvelope<Schema>(res);\n },\n\n async registerServer(\n params: RegisterServerParams,\n ): Promise<RegisterServerResult> {\n const res = await fetch(`${base}/v1/servers`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n serverAddress: params.serverAddress,\n publicKey: params.publicKey,\n serverUrl: params.serverUrl,\n }),\n });\n if (res.status === 409) {\n const body = await readJsonObject(res);\n return {\n serverId: getMutationId(body, \"serverId\"),\n alreadyRegistered: true,\n };\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const body = await readJsonObject(res);\n return {\n serverId: getMutationId(body, \"serverId\"),\n alreadyRegistered: false,\n };\n },\n\n async registerBuilder(\n params: RegisterBuilderParams,\n ): Promise<RegisterBuilderResult> {\n const res = await fetch(`${base}/v1/builders`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n granteeAddress: params.granteeAddress,\n publicKey: params.publicKey,\n appUrl: params.appUrl,\n }),\n });\n // 409 is idempotent — the gateway's current 409 body doesn't include\n // the builderId, but we tolerate it in case that changes (mirrors the\n // registerServer / createGrant shape).\n if (res.status === 409) {\n const body = await readJsonObject(res);\n return {\n builderId: getMutationId(body, \"builderId\"),\n alreadyRegistered: true,\n };\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const body = await readJsonObject(res);\n return {\n builderId: getMutationId(body, \"builderId\"),\n alreadyRegistered: false,\n };\n },\n\n async registerDataPoint(\n params: RegisterDataPointParams,\n ): Promise<RegisterDataPointResult> {\n const res = await fetch(`${base}/v1/data`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n scope: params.scope,\n dataHash: params.dataHash,\n metadataHash: params.metadataHash,\n expectedVersion: params.expectedVersion,\n }),\n });\n // 409 is a real failure here (stale CAS), not an idempotent replay —\n // surface the gateway's error message verbatim so the caller knows\n // what `currentExpectedVersion` to re-sign against.\n if (!res.ok) {\n const body = await readJsonObject(res);\n const detail = stringOrUndefined(body[\"error\"]) ?? res.statusText;\n throw new Error(`Gateway error: ${res.status} ${detail}`);\n }\n const body = await readJsonObject(res);\n return {\n dataPointId: getMutationId(body, \"dataPointId\"),\n expectedVersion: stringOrUndefined(body[\"expectedVersion\"]),\n };\n },\n\n async deleteDataPoint(\n params: DeleteDataPointParams,\n ): Promise<DeleteDataPointResult> {\n // The gateway keys the row on keccak256(abi.encode(owner, scope)) --\n // derive it locally rather than asking the caller for it, so the path\n // can never disagree with the signed (owner, scope).\n const dataPointId = deriveDataPointId(\n params.ownerAddress as `0x${string}`,\n params.scope,\n );\n const details = {\n dataPointId,\n scope: params.scope,\n ownerAddress: params.ownerAddress,\n };\n // Signature rides both in the body (the DELETE contract) and as the\n // Web3Signed Authorization header every other /v1 mutation uses.\n const res = await fetch(`${base}/v1/data/${dataPointId}`, {\n method: \"DELETE\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n ownerAddress: params.ownerAddress,\n scope: params.scope,\n expectedVersion: params.expectedVersion,\n signature: params.signature,\n }),\n });\n if (res.status === 404) {\n throw new DataPointNotFoundError(\n `Data point ${dataPointId} (scope '${params.scope}') is not registered`,\n details,\n );\n }\n if (res.status === 409) {\n const body = await readBody(res);\n const currentExpectedVersion = stringOrUndefined(\n body[\"currentExpectedVersion\"],\n );\n const detail = stringOrUndefined(body[\"error\"]) ?? res.statusText;\n throw new DataPointVersionConflictError(\n `Gateway error: 409 ${detail}`,\n {\n ...details,\n expectedVersion: params.expectedVersion,\n currentExpectedVersion,\n },\n );\n }\n if (res.status === 410) {\n throw await deletedError(res, details);\n }\n if (!res.ok) {\n // 400 = the recovered signer/hashes do not match the tombstone\n // AddData. Surface the gateway's message verbatim, like\n // registerDataPoint does.\n const body = await readBody(res);\n const detail = stringOrUndefined(body[\"error\"]) ?? res.statusText;\n throw new Error(`Gateway error: ${res.status} ${detail}`);\n }\n const body = await readBody(res);\n return {\n dataPointId: getMutationId(body, \"dataPointId\") ?? dataPointId,\n ownerAddress: stringOrUndefined(body[\"ownerAddress\"]),\n scope: stringOrUndefined(body[\"scope\"]),\n dataHash: stringOrUndefined(body[\"dataHash\"]),\n metadataHash: stringOrUndefined(body[\"metadataHash\"]),\n expectedVersion: stringOrUndefined(body[\"expectedVersion\"]),\n deletedAt: tombstoneDeletedAt(body),\n };\n },\n\n async createGrant(\n params: CreateGrantParams,\n ): Promise<{ grantId?: string }> {\n const res = await fetch(`${base}/v1/grants`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n grantorAddress: params.grantorAddress,\n granteeId: params.granteeId,\n scopes: params.scopes,\n grantVersion: params.grantVersion,\n expiresAt: params.expiresAt,\n }),\n });\n if (res.status === 409) {\n const body = await readJsonObject(res);\n return { grantId: getMutationId(body, \"grantId\") };\n }\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n const body = await readJsonObject(res);\n return { grantId: getMutationId(body, \"grantId\") };\n },\n\n async revokeGrant(params: RevokeGrantParams): Promise<void> {\n const res = await fetch(`${base}/v1/grants/${params.grantId}`, {\n method: \"DELETE\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify({\n grantorAddress: params.grantorAddress,\n grantVersion: params.grantVersion,\n }),\n });\n if (res.status === 409) return;\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n },\n\n async getEscrowBalance(account: string): Promise<EscrowBalanceResult> {\n const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n // Unlike the rest of /v1, the balance endpoint returns the body\n // directly (no GatewayEnvelope wrap) — it's a pure read with no\n // gateway-signed attestation. See data-gateway api/v1/escrow/balance.ts.\n return (await res.json()) as EscrowBalanceResult;\n },\n\n async submitEscrowDeposit(\n params: SubmitDepositParams,\n ): Promise<DepositState> {\n const res = await fetch(`${base}/v1/escrow/deposit`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ txHash: params.txHash }),\n });\n // The gateway returns 202 for \"accepted (still confirming)\" and 200 for\n // duplicate idempotent replays. Both carry the deposit's current state.\n if (res.status !== 200 && res.status !== 202) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as DepositState;\n },\n\n async payForOperation(\n params: PayForOperationParams,\n ): Promise<PayForOperationResult> {\n // Build the body without the accessRecord key when absent so the\n // gateway's \"missing optional\" branch matches the no-receipt case\n // exactly (an explicit `accessRecord: undefined` would JSON-serialize\n // to nothing — same result — but keeping it conditional makes wire\n // traces easier to read).\n const body: Record<string, unknown> = {\n payerAddress: params.payerAddress,\n opType: params.opType,\n opId: params.opId,\n asset: params.asset,\n amount: params.amount,\n paymentNonce: params.paymentNonce,\n };\n if (params.accessRecord) {\n body[\"accessRecord\"] = params.accessRecord;\n }\n const res = await fetch(`${base}/v1/escrow/pay`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${params.signature}`,\n },\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as PayForOperationResult;\n },\n\n async settle(params?: SettleParams): Promise<SettleResult> {\n const res = await fetch(`${base}/v1/settle`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n // The gateway accepts an empty body; only `limit` is recognised.\n // Always send a JSON body so the gateway's req.body shape parse\n // doesn't have to deal with an undefined.\n body: JSON.stringify(params ?? {}),\n });\n if (!res.ok) {\n throw new Error(`Gateway error: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as SettleResult;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA0D;AAC1D,oBAIO;AACP,iCAGO;AACP,qBAAkC;AAClC,2BAIO;AA0jBP,SAAS,qBAAqD,OAAa;AAMzE,QAAM,WAAW,EAAE,GAAG,MAAM;AAC5B,SAAO,SAAS;AAChB,QAAM,SAAkB,SAAS;AACjC,MAAI,CAAC,MAAM,QAAQ,MAAM,GAAG;AAC1B,WAAO;AAAA,EACT;AACA,QAAM,kBAAc,0CAAoB,MAAkB;AAC1D,SAAO,gBAAgB,SAAY,WAAW,EAAE,GAAG,UAAU,YAAY;AAC3E;AAEO,SAAS,oBAAoB,SAAgC;AAClE,QAAM,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AAEvC,WAAS,cAAc,KAAsB;AAC3C,WAAO,IAAI;AAAA,MACT,kBAAkB,IAAI,MAAM;AAAA,IAC9B;AAAA,EACF;AAKA,iBAAe,aACb,KACgD;AAChD,UAAM,WAAW,UAAM,oCAAc,GAAG;AACxC,QAAI,KAAC,oCAAc,QAAQ,KAAK,EAAE,UAAU,WAAW;AACrD,YAAM,cAAc,GAAG;AAAA,IACzB;AACA,WAAO;AAAA,EACT;AAEA,iBAAe,eAAkB,KAA2B;AAC1D,YAAQ,MAAM,aAAgB,GAAG,GAAG;AAAA,EACtC;AAEA,WAAS,cAAc,MAAe,KAAiC;AACrE,QAAI,KAAC,oCAAc,IAAI,EAAG,QAAO;AACjC,UAAM,QAA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AAU,EAAE;AAAA,MAClE;AACA,aAAQ,MAAM,IAAI,KAAK;AAAA,IACzB;AAAA,EACF;AACF;","names":["body"]}
@@ -1,4 +1,6 @@
1
1
  import { type GrantPermission } from "./scope-actions.js";
2
+ import type { EscrowBalanceResult } from "./escrow.js";
3
+ export type { EscrowBalanceEntry, EscrowBalanceResult, FailedDepositEntry as EscrowDepositFailed, FinalizedDepositEntry as EscrowDepositFinalized, SubmittedDepositEntry as EscrowDepositSubmitted, } from "./escrow.js";
2
4
  export interface GatewayEnvelope<T> {
3
5
  data: T;
4
6
  proof: GatewayProof;
@@ -291,43 +293,11 @@ export interface SettleResult {
291
293
  iterations: number;
292
294
  };
293
295
  }
294
- export interface EscrowBalanceEntry {
295
- asset: string;
296
- balance: string;
297
- pendingAmount: string;
298
- authorizedAmount: string;
299
- availableAmount: string;
300
- updatedAt: string | null;
301
- }
302
- export interface EscrowDepositSubmitted {
303
- txHash: string;
304
- submittedAt: string;
305
- claimedAsset: string;
306
- claimedAmount: string;
307
- }
308
- export interface EscrowDepositFinalized {
309
- txHash: string;
310
- finalizedAt: string | null;
311
- blockNumber: string | null;
312
- claimedAsset: string;
313
- claimedAmount: string;
314
- }
315
- export interface EscrowDepositFailed {
316
- txHash: string;
317
- submittedAt: string;
318
- claimedAsset: string;
319
- claimedAmount: string;
320
- lastError: string | null;
321
- }
322
- export interface EscrowBalance {
323
- account: string;
324
- balances: EscrowBalanceEntry[];
325
- deposits: {
326
- submitted: EscrowDepositSubmitted[];
327
- finalized: EscrowDepositFinalized[];
328
- failed: EscrowDepositFailed[];
329
- };
330
- }
296
+ /**
297
+ * Legacy `GatewayClient` name for the canonical `/v1/escrow/balance` response.
298
+ * `availableAmount` is `max(balance − authorizedAmount − withdrawingAmount, 0)`.
299
+ */
300
+ export type EscrowBalance = EscrowBalanceResult;
331
301
  export interface SubmitDepositParams {
332
302
  txHash: string;
333
303
  }
@@ -385,7 +355,7 @@ export interface GatewayClient {
385
355
  grantId?: string;
386
356
  }>;
387
357
  revokeGrant(params: RevokeGrantParams): Promise<void>;
388
- getEscrowBalance(account: string): Promise<EscrowBalance>;
358
+ getEscrowBalance(account: string): Promise<EscrowBalanceResult>;
389
359
  submitEscrowDeposit(params: SubmitDepositParams): Promise<DepositState>;
390
360
  payForOperation(params: PayForOperationParams): Promise<PayForOperationResult>;
391
361
  settle(params?: SettleParams): Promise<SettleResult>;