@defdone/annon 0.0.0-stage → 0.1.0-alpha.1

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 (214) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/CLI.md +378 -0
  3. package/LICENSE +201 -0
  4. package/NOTICE +7 -0
  5. package/README.md +591 -2
  6. package/dist/api/annon-types.d.ts +108 -0
  7. package/dist/api/annon-types.js +2 -0
  8. package/dist/api/annon.d.ts +117 -0
  9. package/dist/api/annon.js +1152 -0
  10. package/dist/api/hosted-record.d.ts +13 -0
  11. package/dist/api/hosted-record.js +149 -0
  12. package/dist/api/sharing-types.d.ts +109 -0
  13. package/dist/api/sharing-types.js +1 -0
  14. package/dist/api/sharing.d.ts +36 -0
  15. package/dist/api/sharing.js +879 -0
  16. package/dist/browser/download.d.ts +19 -0
  17. package/dist/browser/download.js +52 -0
  18. package/dist/browser/index.d.ts +23 -0
  19. package/dist/browser/index.js +22 -0
  20. package/dist/browser/login-bundle.js +151 -0
  21. package/dist/browser/login.d.ts +1 -0
  22. package/dist/browser/login.js +216 -0
  23. package/dist/browser/purchase-bundle.js +84 -0
  24. package/dist/browser/purchases.d.ts +98 -0
  25. package/dist/browser/purchases.js +735 -0
  26. package/dist/browser/record.d.ts +55 -0
  27. package/dist/browser/record.js +16 -0
  28. package/dist/browser/selling.d.ts +146 -0
  29. package/dist/browser/selling.js +418 -0
  30. package/dist/browser/wallets.d.ts +53 -0
  31. package/dist/browser/wallets.js +286 -0
  32. package/dist/bytes.d.ts +4 -0
  33. package/dist/bytes.js +16 -0
  34. package/dist/download/download.d.ts +59 -0
  35. package/dist/download/download.js +384 -0
  36. package/dist/download/host.d.ts +56 -0
  37. package/dist/download/host.js +161 -0
  38. package/dist/download/http.d.ts +23 -0
  39. package/dist/download/http.js +87 -0
  40. package/dist/download/proof.d.ts +20 -0
  41. package/dist/download/proof.js +79 -0
  42. package/dist/download/upload.d.ts +130 -0
  43. package/dist/download/upload.js +408 -0
  44. package/dist/envelope/evm.d.ts +4 -0
  45. package/dist/envelope/evm.js +32 -0
  46. package/dist/envelope/pay2.d.ts +176 -0
  47. package/dist/envelope/pay2.js +541 -0
  48. package/dist/envelope/replay.d.ts +45 -0
  49. package/dist/envelope/replay.js +186 -0
  50. package/dist/envelope/stream.d.ts +78 -0
  51. package/dist/envelope/stream.js +372 -0
  52. package/dist/errors.d.ts +21 -0
  53. package/dist/errors.js +300 -0
  54. package/dist/index.d.ts +25 -0
  55. package/dist/index.js +23 -0
  56. package/dist/keys/near-ckd.d.ts +47 -0
  57. package/dist/keys/near-ckd.js +96 -0
  58. package/dist/limits.d.ts +4 -0
  59. package/dist/limits.js +4 -0
  60. package/dist/near/nep413.d.ts +22 -0
  61. package/dist/near/nep413.js +39 -0
  62. package/dist/near/rpc.d.ts +170 -0
  63. package/dist/near/rpc.js +423 -0
  64. package/dist/near/texts.d.ts +39 -0
  65. package/dist/near/texts.js +60 -0
  66. package/dist/net/ip.d.ts +7 -0
  67. package/dist/net/ip.js +62 -0
  68. package/dist/net/retry.d.ts +3 -0
  69. package/dist/net/retry.js +31 -0
  70. package/dist/node/adapter-checks.d.ts +6 -0
  71. package/dist/node/adapter-checks.js +13 -0
  72. package/dist/node/adapter.d.ts +8 -0
  73. package/dist/node/adapter.js +98 -0
  74. package/dist/node/agent.d.ts +49 -0
  75. package/dist/node/agent.js +266 -0
  76. package/dist/node/amounts.d.ts +2 -0
  77. package/dist/node/amounts.js +20 -0
  78. package/dist/node/browser-login.d.ts +25 -0
  79. package/dist/node/browser-login.js +219 -0
  80. package/dist/node/budget.d.ts +24 -0
  81. package/dist/node/budget.js +59 -0
  82. package/dist/node/buy-commands.d.ts +24 -0
  83. package/dist/node/buy-commands.js +301 -0
  84. package/dist/node/cli.d.ts +60 -0
  85. package/dist/node/cli.js +201 -0
  86. package/dist/node/command-context.d.ts +82 -0
  87. package/dist/node/command-context.js +77 -0
  88. package/dist/node/config.d.ts +37 -0
  89. package/dist/node/config.js +189 -0
  90. package/dist/node/core-adapter.d.ts +43 -0
  91. package/dist/node/core-adapter.js +122 -0
  92. package/dist/node/errors.d.ts +8 -0
  93. package/dist/node/errors.js +12 -0
  94. package/dist/node/index.d.ts +7 -0
  95. package/dist/node/index.js +5 -0
  96. package/dist/node/io.d.ts +13 -0
  97. package/dist/node/io.js +112 -0
  98. package/dist/node/keychain.d.ts +10 -0
  99. package/dist/node/keychain.js +67 -0
  100. package/dist/node/main.d.ts +2 -0
  101. package/dist/node/main.js +21 -0
  102. package/dist/node/offers.d.ts +16 -0
  103. package/dist/node/offers.js +91 -0
  104. package/dist/node/origin.d.ts +11 -0
  105. package/dist/node/origin.js +80 -0
  106. package/dist/node/paths.d.ts +3 -0
  107. package/dist/node/paths.js +71 -0
  108. package/dist/node/payment-terms.d.ts +26 -0
  109. package/dist/node/payment-terms.js +127 -0
  110. package/dist/node/purchase-commands.d.ts +16 -0
  111. package/dist/node/purchase-commands.js +237 -0
  112. package/dist/node/purchase-guard.d.ts +19 -0
  113. package/dist/node/purchase-guard.js +53 -0
  114. package/dist/node/relay-transport.d.ts +6 -0
  115. package/dist/node/relay-transport.js +173 -0
  116. package/dist/node/resources.d.ts +2 -0
  117. package/dist/node/resources.js +26 -0
  118. package/dist/node/retry-gate.d.ts +15 -0
  119. package/dist/node/retry-gate.js +53 -0
  120. package/dist/node/seller-commands.d.ts +12 -0
  121. package/dist/node/seller-commands.js +207 -0
  122. package/dist/node/sharing.d.ts +3 -0
  123. package/dist/node/sharing.js +28 -0
  124. package/dist/node/shops.d.ts +17 -0
  125. package/dist/node/shops.js +74 -0
  126. package/dist/node/signer-mock.d.ts +11 -0
  127. package/dist/node/signer-mock.js +79 -0
  128. package/dist/node/signer-wallet.d.ts +8 -0
  129. package/dist/node/signer-wallet.js +149 -0
  130. package/dist/node/signing.d.ts +29 -0
  131. package/dist/node/signing.js +200 -0
  132. package/dist/node/storage-commands.d.ts +11 -0
  133. package/dist/node/storage-commands.js +50 -0
  134. package/dist/node/sync-dir.d.ts +1 -0
  135. package/dist/node/sync-dir.js +11 -0
  136. package/dist/node/wallets.d.ts +13 -0
  137. package/dist/node/wallets.js +146 -0
  138. package/dist/oneclick/oneclick.d.ts +132 -0
  139. package/dist/oneclick/oneclick.js +342 -0
  140. package/dist/pay/backup.d.ts +70 -0
  141. package/dist/pay/backup.js +402 -0
  142. package/dist/pay/base.d.ts +135 -0
  143. package/dist/pay/base.js +386 -0
  144. package/dist/pay/eip3009.d.ts +59 -0
  145. package/dist/pay/eip3009.js +72 -0
  146. package/dist/pay/pay.d.ts +86 -0
  147. package/dist/pay/pay.js +297 -0
  148. package/dist/pay/purchase.d.ts +103 -0
  149. package/dist/pay/purchase.js +20 -0
  150. package/dist/pay/recover.d.ts +31 -0
  151. package/dist/pay/recover.js +34 -0
  152. package/dist/pay/seller.d.ts +130 -0
  153. package/dist/pay/seller.js +444 -0
  154. package/dist/pay/settle.d.ts +96 -0
  155. package/dist/pay/settle.js +308 -0
  156. package/dist/pay/split.d.ts +115 -0
  157. package/dist/pay/split.js +256 -0
  158. package/dist/pay/store-node.d.ts +8 -0
  159. package/dist/pay/store-node.js +224 -0
  160. package/dist/pay/store.d.ts +54 -0
  161. package/dist/pay/store.js +135 -0
  162. package/dist/pay/x402.d.ts +95 -0
  163. package/dist/pay/x402.js +136 -0
  164. package/dist/relay/admission.d.ts +8 -0
  165. package/dist/relay/admission.js +58 -0
  166. package/dist/relay/capabilities.d.ts +36 -0
  167. package/dist/relay/capabilities.js +232 -0
  168. package/dist/relay/fees.d.ts +17 -0
  169. package/dist/relay/fees.js +105 -0
  170. package/dist/relay/index.d.ts +10 -0
  171. package/dist/relay/index.js +8 -0
  172. package/dist/relay/keeper-balance.d.ts +17 -0
  173. package/dist/relay/keeper-balance.js +46 -0
  174. package/dist/relay/keeper-runner.d.ts +114 -0
  175. package/dist/relay/keeper-runner.js +703 -0
  176. package/dist/relay/keeper.d.ts +38 -0
  177. package/dist/relay/keeper.js +73 -0
  178. package/dist/relay/ledger.d.ts +155 -0
  179. package/dist/relay/ledger.js +392 -0
  180. package/dist/relay/relay-checks.d.ts +3 -0
  181. package/dist/relay/relay-checks.js +244 -0
  182. package/dist/relay/relay-reconciliation.d.ts +15 -0
  183. package/dist/relay/relay-reconciliation.js +293 -0
  184. package/dist/relay/relay-request.d.ts +6 -0
  185. package/dist/relay/relay-request.js +139 -0
  186. package/dist/relay/relay-transactions.d.ts +23 -0
  187. package/dist/relay/relay-transactions.js +182 -0
  188. package/dist/relay/relay-types.d.ts +128 -0
  189. package/dist/relay/relay-types.js +17 -0
  190. package/dist/relay/relay.d.ts +102 -0
  191. package/dist/relay/relay.js +426 -0
  192. package/dist/relay/reservation.d.ts +29 -0
  193. package/dist/relay/reservation.js +132 -0
  194. package/dist/relay/sponsorship.d.ts +42 -0
  195. package/dist/relay/sponsorship.js +184 -0
  196. package/dist/routes.d.ts +2 -0
  197. package/dist/routes.js +1 -0
  198. package/dist/settle-near/codec.d.ts +17 -0
  199. package/dist/settle-near/codec.js +86 -0
  200. package/dist/settle-near/identity.d.ts +27 -0
  201. package/dist/settle-near/identity.js +80 -0
  202. package/dist/settle-near/purchase.d.ts +40 -0
  203. package/dist/settle-near/purchase.js +153 -0
  204. package/dist/settle-near/terms.d.ts +37 -0
  205. package/dist/settle-near/terms.js +89 -0
  206. package/dist/shops/discovery.d.ts +95 -0
  207. package/dist/shops/discovery.js +384 -0
  208. package/dist/wallet/account-only.d.ts +11 -0
  209. package/dist/wallet/account-only.js +6 -0
  210. package/dist/wallet/uncertain.d.ts +8 -0
  211. package/dist/wallet/uncertain.js +13 -0
  212. package/dist/wallet/wallet.d.ts +100 -0
  213. package/dist/wallet/wallet.js +204 -0
  214. package/package.json +136 -3
@@ -0,0 +1,87 @@
1
+ /** Shared exact-origin CORS policy for the file host and relayer. */
2
+ import { serveFile } from './host.js';
3
+ export const DEFAULT_ORIGINS = ['https://annon.dev', 'https://www.annon.dev'];
4
+ const HOST_HEADERS = 'Content-Type, PAYMENT-SIGNATURE, Annon-Buyer-Proof, Range, Annon-Upload-Authorization';
5
+ const HOST_EXPOSE = 'PAYMENT-REQUIRED, PAYMENT-RESPONSE, Retry-After, Accept-Ranges, Content-Range, Content-Length, Content-Disposition';
6
+ function validOrigin(value, preview = false) {
7
+ try {
8
+ const u = new URL(value);
9
+ return (u.protocol === 'https:' &&
10
+ !u.username &&
11
+ !u.password &&
12
+ u.origin === value &&
13
+ (!preview || (!u.port && /^[a-z0-9-]+\.vercel\.app$/.test(u.hostname))));
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ export function corsPolicy(allowed = [], previews = [], service = 'host', maxAge = 600) {
20
+ if (!allowed.every((v) => validOrigin(v)) || !previews.every((v) => validOrigin(v, true)))
21
+ throw new TypeError('invalid CORS origin');
22
+ return {
23
+ origins: [...new Set([...allowed, ...previews])],
24
+ methods: service === 'host' ? 'GET, POST, PUT, OPTIONS' : 'GET, POST, OPTIONS',
25
+ headers: service === 'host' ? HOST_HEADERS : 'Content-Type',
26
+ expose: service === 'host' ? HOST_EXPOSE : 'Retry-After',
27
+ maxAge,
28
+ };
29
+ }
30
+ export function corsHeaders(origin, allowed = [], expose = HOST_EXPOSE) {
31
+ if (!origin || !validOrigin(origin) || !allowed.includes(origin))
32
+ return { Vary: 'Origin' };
33
+ return {
34
+ 'Access-Control-Allow-Origin': origin,
35
+ 'Access-Control-Expose-Headers': expose,
36
+ Vary: 'Origin',
37
+ };
38
+ }
39
+ export function preflight(headers, policy = corsPolicy()) {
40
+ const origin = headers.get('Origin');
41
+ const method = headers.get('Access-Control-Request-Method');
42
+ const requested = headers.get('Access-Control-Request-Headers');
43
+ const allowedHeaders = policy.headers
44
+ .toLowerCase()
45
+ .split(',')
46
+ .map((s) => s.trim());
47
+ const base = {
48
+ 'Cache-Control': 'no-store',
49
+ Vary: 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers',
50
+ };
51
+ if (!origin ||
52
+ !validOrigin(origin) ||
53
+ !policy.origins.includes(origin) ||
54
+ (method !== null && !policy.methods.split(', ').includes(method)) ||
55
+ (requested !== null &&
56
+ !requested.split(',').every((s) => allowedHeaders.includes(s.trim().toLowerCase()))))
57
+ return { status: 403, headers: base };
58
+ return {
59
+ status: 204,
60
+ headers: {
61
+ ...corsHeaders(origin, policy.origins, policy.expose),
62
+ ...base,
63
+ 'Access-Control-Allow-Methods': policy.methods,
64
+ 'Access-Control-Allow-Headers': policy.headers,
65
+ 'Access-Control-Max-Age': String(policy.maxAge),
66
+ },
67
+ };
68
+ }
69
+ export function hasContentType(value, expected) {
70
+ return value?.split(';')[0]?.trim().toLowerCase() === expected;
71
+ }
72
+ export async function handle(method, headers, o) {
73
+ const policy = corsPolicy(o.allowedOrigins ?? [], o.previewOrigins);
74
+ const cors = {
75
+ 'Cache-Control': 'no-store',
76
+ ...corsHeaders(headers.get('Origin'), policy.origins, policy.expose),
77
+ };
78
+ if (method === 'OPTIONS')
79
+ return preflight(headers, policy);
80
+ if ((method === 'POST' || method === 'PUT') &&
81
+ !hasContentType(headers.get('Content-Type'), 'application/json'))
82
+ return { status: 415, headers: cors };
83
+ if (method !== 'GET')
84
+ return { status: 405, headers: { ...cors, Allow: 'GET, OPTIONS' } };
85
+ const r = await serveFile({ headers }, o);
86
+ return { ...r, headers: { ...cors, ...r.headers } };
87
+ }
@@ -0,0 +1,20 @@
1
+ export declare const BUYER_PROOF_DST = "ANNON-BUYER-PROOF-V1_BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_";
2
+ export declare const BUYER_PROOF_HEADER = "Annon-Buyer-Proof";
3
+ /** The header value: the one-time key's 32-byte secret signs `resourceUrl`. */
4
+ export declare function buyerProof(secret: Uint8Array, resourceUrl: string): string;
5
+ /**
6
+ * Whether `proof` is the buyer key's signature over `resourceUrl`. Both points must decode, be in
7
+ * their subgroups and not be the identity; anything malformed is false, never an exception.
8
+ */
9
+ export declare function verifyBuyerProof(buyerKey: string, resourceUrl: string, proof: string): boolean;
10
+ /** A client signs a proof only when the advertised `resource.url` is where the request goes. */
11
+ export declare function sameResource(advertised: string, requested: string): boolean;
12
+ interface PurchaseProof {
13
+ purchase_id: string;
14
+ grant: number;
15
+ signature: string;
16
+ }
17
+ /** The existing URL signature, accompanied by its final contract lookup coordinates. */
18
+ export declare function purchaseProof(secret: Uint8Array, url: string, purchase_id: string, grant?: number): string;
19
+ export declare function readPurchaseProof(header: string | null): PurchaseProof | null;
20
+ export {};
@@ -0,0 +1,79 @@
1
+ /**
2
+ * `Annon-Buyer-Proof` (specs/download.md section 3): a BLS signature by the purchase's one-time key
3
+ * over the file URL. Only the buyer holds that key's secret (the facilitator sees the payload with
4
+ * its public key, never this header), and the URL ties the proof to one host and file.
5
+ */
6
+ import { bls12_381 as bls } from '@noble/curves/bls12-381.js';
7
+ export const BUYER_PROOF_DST = 'ANNON-BUYER-PROOF-V1_BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_';
8
+ export const BUYER_PROOF_HEADER = 'Annon-Buyer-Proof';
9
+ const sigs = bls.longSignatures;
10
+ const utf8 = new TextEncoder();
11
+ /** `UTF8("annon/v1.1 buyer proof") || 0x0a || UTF8(resource.url)`. */
12
+ const buyerProofMessage = (resourceUrl) => Uint8Array.from([...utf8.encode('annon/v1.1 buyer proof'), 0x0a, ...utf8.encode(resourceUrl)]);
13
+ const b64url = (b) => btoa(String.fromCharCode(...b))
14
+ .replaceAll('+', '-')
15
+ .replaceAll('/', '_')
16
+ .replace(/=+$/, '');
17
+ /** The header value: the one-time key's 32-byte secret signs `resourceUrl`. */
18
+ export function buyerProof(secret, resourceUrl) {
19
+ return b64url(sigs.sign(sigs.hash(buyerProofMessage(resourceUrl), BUYER_PROOF_DST), secret).toBytes(true));
20
+ }
21
+ /**
22
+ * Whether `proof` is the buyer key's signature over `resourceUrl`. Both points must decode, be in
23
+ * their subgroups and not be the identity; anything malformed is false, never an exception.
24
+ */
25
+ export function verifyBuyerProof(buyerKey, resourceUrl, proof) {
26
+ try {
27
+ if (!/^0x[0-9a-f]{96}$/.test(buyerKey) || !/^[A-Za-z0-9_-]{128}$/.test(proof))
28
+ return false;
29
+ const pk = bls.G1.Point.fromBytes(Uint8Array.from(buyerKey.slice(2).match(/../g) ?? [], (h) => Number.parseInt(h, 16)));
30
+ const raw = Uint8Array.from(atob(proof.replaceAll('-', '+').replaceAll('_', '/')), (c) => c.charCodeAt(0));
31
+ const sig = bls.G2.Point.fromBytes(raw);
32
+ if (pk.is0() || sig.is0() || !pk.isTorsionFree() || !sig.isTorsionFree())
33
+ return false;
34
+ return sigs.verify(sig, sigs.hash(buyerProofMessage(resourceUrl), BUYER_PROOF_DST), pk);
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }
40
+ /** The URL as WHATWG parses and serializes it, without the fragment; null if it doesn't parse. */
41
+ function canonical(url) {
42
+ if (!URL.canParse(url))
43
+ return null;
44
+ const u = new URL(url);
45
+ u.hash = '';
46
+ return u.href;
47
+ }
48
+ /** A client signs a proof only when the advertised `resource.url` is where the request goes. */
49
+ export function sameResource(advertised, requested) {
50
+ const a = canonical(advertised);
51
+ return a !== null && a === canonical(requested);
52
+ }
53
+ /** The existing URL signature, accompanied by its final contract lookup coordinates. */
54
+ export function purchaseProof(secret, url, purchase_id, grant = 0) {
55
+ if (!/^0x[0-9a-f]{64}$/.test(purchase_id) ||
56
+ !Number.isInteger(grant) ||
57
+ grant < 0 ||
58
+ grant > 0xffffffff)
59
+ throw new TypeError('invalid purchase/grant');
60
+ return b64url(utf8.encode(JSON.stringify({ purchase_id, grant, signature: buyerProof(secret, url) })));
61
+ }
62
+ export function readPurchaseProof(header) {
63
+ try {
64
+ if (!header || header.length > 512 || !/^[A-Za-z0-9_-]+$/.test(header))
65
+ return null;
66
+ const p = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Uint8Array.from(atob(header.replaceAll('-', '+').replaceAll('_', '/')), (c) => c.charCodeAt(0))));
67
+ if (Object.keys(p).sort().join() !== 'grant,purchase_id,signature' ||
68
+ !/^0x[0-9a-f]{64}$/.test(p.purchase_id) ||
69
+ !Number.isInteger(p.grant) ||
70
+ p.grant < 0 ||
71
+ p.grant > 0xffffffff ||
72
+ !/^[A-Za-z0-9_-]{128}$/.test(p.signature))
73
+ return null;
74
+ return p;
75
+ }
76
+ catch {
77
+ return null;
78
+ }
79
+ }
@@ -0,0 +1,130 @@
1
+ import { AnnonError } from '../errors.js';
2
+ import type { NearSignedMessage } from '../near/nep413.js';
3
+ import { type HostingReservation } from '../relay/reservation.js';
4
+ import { type Authorization, type Identity } from '../settle-near/identity.js';
5
+ import { type SettlementAssets, type Terms } from '../settle-near/terms.js';
6
+ export interface UploadIntent {
7
+ network: string;
8
+ contract: string;
9
+ seller: Identity;
10
+ fileId: string;
11
+ cipherHash: string;
12
+ termsHash: string;
13
+ byteSize: number;
14
+ plaintextSize: number;
15
+ headerSize: number;
16
+ hostOrigin: string;
17
+ metadataHash: string;
18
+ nonce: string;
19
+ expiresAt: number;
20
+ }
21
+ export interface UploadManifest {
22
+ version: 2;
23
+ chunkLog2: number;
24
+ metaLen: number;
25
+ previewLen: number;
26
+ n: number;
27
+ keyCommitments: string[];
28
+ chunkHashes: string[];
29
+ }
30
+ export interface UploadMetadata {
31
+ filename: string;
32
+ title: string;
33
+ description: string;
34
+ }
35
+ export type UploadAuth = Authorization | (NearSignedMessage & {
36
+ kind: 'near';
37
+ });
38
+ export interface UploadAuthorization {
39
+ intent: UploadIntent;
40
+ auth: UploadAuth;
41
+ }
42
+ export interface UploadRequest extends UploadAuthorization {
43
+ terms: Terms;
44
+ manifest: UploadManifest;
45
+ metadata: UploadMetadata;
46
+ }
47
+ export interface UploadCreated {
48
+ uploadId: string;
49
+ state: 'receiving';
50
+ expiresAt: number;
51
+ bodyUrl: string;
52
+ headerUrl: string;
53
+ }
54
+ export interface UploadReserved {
55
+ uploadId: string;
56
+ state: 'reserved';
57
+ reservation: HostingReservation;
58
+ }
59
+ export interface UploadPublished {
60
+ fileId: string;
61
+ url: string;
62
+ header: string;
63
+ expiresAt: number | null;
64
+ }
65
+ export interface UploadBaseSplit {
66
+ state: 'pending' | 'ready';
67
+ address: string;
68
+ kind: 'push';
69
+ salt: string;
70
+ txHash: string | null;
71
+ }
72
+ interface UploadBaseSplitRequest {
73
+ kind: 'push';
74
+ salt: string;
75
+ }
76
+ export interface UploadBaseSplitResult {
77
+ baseSplit: UploadBaseSplit | null;
78
+ }
79
+ export type UploadStatus = (UploadCreated | UploadReserved | {
80
+ uploadId: string;
81
+ state: 'published';
82
+ result: UploadPublished;
83
+ }) & UploadBaseSplitResult;
84
+ export declare const uploadText: (i: UploadIntent) => string;
85
+ export declare function uploadOrigin(value: string): string;
86
+ export declare function normalizeMetadata(input: unknown): UploadMetadata;
87
+ export declare function metadataHash(metadata: UploadMetadata): Promise<string>;
88
+ export declare function parseUploadIntent(input: unknown): UploadIntent;
89
+ export declare function parseUploadAuth(input: unknown): UploadAuth;
90
+ export declare function parseUpload(input: unknown): UploadRequest;
91
+ export declare function verifyUploadAuthorization(a: UploadAuthorization, o: {
92
+ network: string;
93
+ contract: string;
94
+ hostOrigin: string;
95
+ now: number;
96
+ nearRpc: string;
97
+ authSeconds?: number;
98
+ }): Promise<void>;
99
+ export declare function verifyUpload(input: UploadRequest, o: Parameters<typeof verifyUploadAuthorization>[1] & {
100
+ assets?: SettlementAssets;
101
+ }): Promise<void>;
102
+ export declare function encodeUploadAuthorization(input: UploadAuthorization): string;
103
+ export declare function decodeUploadAuthorization(value: string, max?: number): UploadAuthorization;
104
+ export type UploadErrorCode = 'budget' | 'disabled' | 'settlement_pending' | 'route_unavailable' | 'bad_request' | 'bad_signature' | 'too_large' | 'upload_expired' | 'upload_conflict' | 'upload_incomplete' | 'host_capacity' | 'cipher_hash_mismatch' | 'unknown_file' | 'file_invalid' | 'taken_down' | 'sales_stopped' | 'rate_limited' | 'unavailable' | 'operation_failed';
105
+ /** HTTP failures use the shared error model and retain only checked retry evidence. */
106
+ export type UploadResult<T> = {
107
+ ok: true;
108
+ value: T;
109
+ } | {
110
+ ok: false;
111
+ error: AnnonError & {
112
+ retryAfterSeconds?: number;
113
+ };
114
+ };
115
+ export declare class UploadClient {
116
+ readonly origin: string;
117
+ private readonly fetcher;
118
+ constructor(origin: string, options?: {
119
+ fetch?: typeof fetch;
120
+ });
121
+ private request;
122
+ private requestJson;
123
+ private path;
124
+ create(request: UploadRequest): Promise<UploadResult<UploadCreated | UploadStatus>>;
125
+ body(id: string, auth: UploadAuthorization, body: ReadableStream<Uint8Array> | Blob): Promise<UploadResult<UploadReserved>>;
126
+ header(id: string, auth: UploadAuthorization, header: Uint8Array<ArrayBuffer>): Promise<UploadResult<UploadPublished>>;
127
+ status(id: string, auth: UploadAuthorization): Promise<UploadResult<UploadStatus>>;
128
+ baseSplit(id: string, auth: UploadAuthorization, input: UploadBaseSplitRequest): Promise<UploadResult<UploadBaseSplitResult>>;
129
+ }
130
+ export {};