@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.
- package/CHANGELOG.md +63 -0
- package/CLI.md +378 -0
- package/LICENSE +201 -0
- package/NOTICE +7 -0
- package/README.md +591 -2
- package/dist/api/annon-types.d.ts +108 -0
- package/dist/api/annon-types.js +2 -0
- package/dist/api/annon.d.ts +117 -0
- package/dist/api/annon.js +1152 -0
- package/dist/api/hosted-record.d.ts +13 -0
- package/dist/api/hosted-record.js +149 -0
- package/dist/api/sharing-types.d.ts +109 -0
- package/dist/api/sharing-types.js +1 -0
- package/dist/api/sharing.d.ts +36 -0
- package/dist/api/sharing.js +879 -0
- package/dist/browser/download.d.ts +19 -0
- package/dist/browser/download.js +52 -0
- package/dist/browser/index.d.ts +23 -0
- package/dist/browser/index.js +22 -0
- package/dist/browser/login-bundle.js +151 -0
- package/dist/browser/login.d.ts +1 -0
- package/dist/browser/login.js +216 -0
- package/dist/browser/purchase-bundle.js +84 -0
- package/dist/browser/purchases.d.ts +98 -0
- package/dist/browser/purchases.js +735 -0
- package/dist/browser/record.d.ts +55 -0
- package/dist/browser/record.js +16 -0
- package/dist/browser/selling.d.ts +146 -0
- package/dist/browser/selling.js +418 -0
- package/dist/browser/wallets.d.ts +53 -0
- package/dist/browser/wallets.js +286 -0
- package/dist/bytes.d.ts +4 -0
- package/dist/bytes.js +16 -0
- package/dist/download/download.d.ts +59 -0
- package/dist/download/download.js +384 -0
- package/dist/download/host.d.ts +56 -0
- package/dist/download/host.js +161 -0
- package/dist/download/http.d.ts +23 -0
- package/dist/download/http.js +87 -0
- package/dist/download/proof.d.ts +20 -0
- package/dist/download/proof.js +79 -0
- package/dist/download/upload.d.ts +130 -0
- package/dist/download/upload.js +408 -0
- package/dist/envelope/evm.d.ts +4 -0
- package/dist/envelope/evm.js +32 -0
- package/dist/envelope/pay2.d.ts +176 -0
- package/dist/envelope/pay2.js +541 -0
- package/dist/envelope/replay.d.ts +45 -0
- package/dist/envelope/replay.js +186 -0
- package/dist/envelope/stream.d.ts +78 -0
- package/dist/envelope/stream.js +372 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +300 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +23 -0
- package/dist/keys/near-ckd.d.ts +47 -0
- package/dist/keys/near-ckd.js +96 -0
- package/dist/limits.d.ts +4 -0
- package/dist/limits.js +4 -0
- package/dist/near/nep413.d.ts +22 -0
- package/dist/near/nep413.js +39 -0
- package/dist/near/rpc.d.ts +170 -0
- package/dist/near/rpc.js +423 -0
- package/dist/near/texts.d.ts +39 -0
- package/dist/near/texts.js +60 -0
- package/dist/net/ip.d.ts +7 -0
- package/dist/net/ip.js +62 -0
- package/dist/net/retry.d.ts +3 -0
- package/dist/net/retry.js +31 -0
- package/dist/node/adapter-checks.d.ts +6 -0
- package/dist/node/adapter-checks.js +13 -0
- package/dist/node/adapter.d.ts +8 -0
- package/dist/node/adapter.js +98 -0
- package/dist/node/agent.d.ts +49 -0
- package/dist/node/agent.js +266 -0
- package/dist/node/amounts.d.ts +2 -0
- package/dist/node/amounts.js +20 -0
- package/dist/node/browser-login.d.ts +25 -0
- package/dist/node/browser-login.js +219 -0
- package/dist/node/budget.d.ts +24 -0
- package/dist/node/budget.js +59 -0
- package/dist/node/buy-commands.d.ts +24 -0
- package/dist/node/buy-commands.js +301 -0
- package/dist/node/cli.d.ts +60 -0
- package/dist/node/cli.js +201 -0
- package/dist/node/command-context.d.ts +82 -0
- package/dist/node/command-context.js +77 -0
- package/dist/node/config.d.ts +37 -0
- package/dist/node/config.js +189 -0
- package/dist/node/core-adapter.d.ts +43 -0
- package/dist/node/core-adapter.js +122 -0
- package/dist/node/errors.d.ts +8 -0
- package/dist/node/errors.js +12 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.js +5 -0
- package/dist/node/io.d.ts +13 -0
- package/dist/node/io.js +112 -0
- package/dist/node/keychain.d.ts +10 -0
- package/dist/node/keychain.js +67 -0
- package/dist/node/main.d.ts +2 -0
- package/dist/node/main.js +21 -0
- package/dist/node/offers.d.ts +16 -0
- package/dist/node/offers.js +91 -0
- package/dist/node/origin.d.ts +11 -0
- package/dist/node/origin.js +80 -0
- package/dist/node/paths.d.ts +3 -0
- package/dist/node/paths.js +71 -0
- package/dist/node/payment-terms.d.ts +26 -0
- package/dist/node/payment-terms.js +127 -0
- package/dist/node/purchase-commands.d.ts +16 -0
- package/dist/node/purchase-commands.js +237 -0
- package/dist/node/purchase-guard.d.ts +19 -0
- package/dist/node/purchase-guard.js +53 -0
- package/dist/node/relay-transport.d.ts +6 -0
- package/dist/node/relay-transport.js +173 -0
- package/dist/node/resources.d.ts +2 -0
- package/dist/node/resources.js +26 -0
- package/dist/node/retry-gate.d.ts +15 -0
- package/dist/node/retry-gate.js +53 -0
- package/dist/node/seller-commands.d.ts +12 -0
- package/dist/node/seller-commands.js +207 -0
- package/dist/node/sharing.d.ts +3 -0
- package/dist/node/sharing.js +28 -0
- package/dist/node/shops.d.ts +17 -0
- package/dist/node/shops.js +74 -0
- package/dist/node/signer-mock.d.ts +11 -0
- package/dist/node/signer-mock.js +79 -0
- package/dist/node/signer-wallet.d.ts +8 -0
- package/dist/node/signer-wallet.js +149 -0
- package/dist/node/signing.d.ts +29 -0
- package/dist/node/signing.js +200 -0
- package/dist/node/storage-commands.d.ts +11 -0
- package/dist/node/storage-commands.js +50 -0
- package/dist/node/sync-dir.d.ts +1 -0
- package/dist/node/sync-dir.js +11 -0
- package/dist/node/wallets.d.ts +13 -0
- package/dist/node/wallets.js +146 -0
- package/dist/oneclick/oneclick.d.ts +132 -0
- package/dist/oneclick/oneclick.js +342 -0
- package/dist/pay/backup.d.ts +70 -0
- package/dist/pay/backup.js +402 -0
- package/dist/pay/base.d.ts +135 -0
- package/dist/pay/base.js +386 -0
- package/dist/pay/eip3009.d.ts +59 -0
- package/dist/pay/eip3009.js +72 -0
- package/dist/pay/pay.d.ts +86 -0
- package/dist/pay/pay.js +297 -0
- package/dist/pay/purchase.d.ts +103 -0
- package/dist/pay/purchase.js +20 -0
- package/dist/pay/recover.d.ts +31 -0
- package/dist/pay/recover.js +34 -0
- package/dist/pay/seller.d.ts +130 -0
- package/dist/pay/seller.js +444 -0
- package/dist/pay/settle.d.ts +96 -0
- package/dist/pay/settle.js +308 -0
- package/dist/pay/split.d.ts +115 -0
- package/dist/pay/split.js +256 -0
- package/dist/pay/store-node.d.ts +8 -0
- package/dist/pay/store-node.js +224 -0
- package/dist/pay/store.d.ts +54 -0
- package/dist/pay/store.js +135 -0
- package/dist/pay/x402.d.ts +95 -0
- package/dist/pay/x402.js +136 -0
- package/dist/relay/admission.d.ts +8 -0
- package/dist/relay/admission.js +58 -0
- package/dist/relay/capabilities.d.ts +36 -0
- package/dist/relay/capabilities.js +232 -0
- package/dist/relay/fees.d.ts +17 -0
- package/dist/relay/fees.js +105 -0
- package/dist/relay/index.d.ts +10 -0
- package/dist/relay/index.js +8 -0
- package/dist/relay/keeper-balance.d.ts +17 -0
- package/dist/relay/keeper-balance.js +46 -0
- package/dist/relay/keeper-runner.d.ts +114 -0
- package/dist/relay/keeper-runner.js +703 -0
- package/dist/relay/keeper.d.ts +38 -0
- package/dist/relay/keeper.js +73 -0
- package/dist/relay/ledger.d.ts +155 -0
- package/dist/relay/ledger.js +392 -0
- package/dist/relay/relay-checks.d.ts +3 -0
- package/dist/relay/relay-checks.js +244 -0
- package/dist/relay/relay-reconciliation.d.ts +15 -0
- package/dist/relay/relay-reconciliation.js +293 -0
- package/dist/relay/relay-request.d.ts +6 -0
- package/dist/relay/relay-request.js +139 -0
- package/dist/relay/relay-transactions.d.ts +23 -0
- package/dist/relay/relay-transactions.js +182 -0
- package/dist/relay/relay-types.d.ts +128 -0
- package/dist/relay/relay-types.js +17 -0
- package/dist/relay/relay.d.ts +102 -0
- package/dist/relay/relay.js +426 -0
- package/dist/relay/reservation.d.ts +29 -0
- package/dist/relay/reservation.js +132 -0
- package/dist/relay/sponsorship.d.ts +42 -0
- package/dist/relay/sponsorship.js +184 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +1 -0
- package/dist/settle-near/codec.d.ts +17 -0
- package/dist/settle-near/codec.js +86 -0
- package/dist/settle-near/identity.d.ts +27 -0
- package/dist/settle-near/identity.js +80 -0
- package/dist/settle-near/purchase.d.ts +40 -0
- package/dist/settle-near/purchase.js +153 -0
- package/dist/settle-near/terms.d.ts +37 -0
- package/dist/settle-near/terms.js +89 -0
- package/dist/shops/discovery.d.ts +95 -0
- package/dist/shops/discovery.js +384 -0
- package/dist/wallet/account-only.d.ts +11 -0
- package/dist/wallet/account-only.js +6 -0
- package/dist/wallet/uncertain.d.ts +8 -0
- package/dist/wallet/uncertain.js +13 -0
- package/dist/wallet/wallet.d.ts +100 -0
- package/dist/wallet/wallet.js +204 -0
- package/package.json +136 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { signInAccountOnly } from '../wallet/account-only.js';
|
|
3
|
+
import { evmWallet } from '../wallet/wallet.js';
|
|
4
|
+
Object.assign(globalThis, { Buffer });
|
|
5
|
+
const pair = document.getElementById('pair');
|
|
6
|
+
const display = document.getElementById('action');
|
|
7
|
+
const status = document.getElementById('status');
|
|
8
|
+
const approve = document.getElementById('approve');
|
|
9
|
+
const nearChoice = document.getElementById('near-wallet');
|
|
10
|
+
const hotChoice = document.getElementById('near-wallet-hot');
|
|
11
|
+
/** Signing-request chains the page can bind a NEAR wallet to. Anything else is refused. */
|
|
12
|
+
const NEAR_NETWORKS = new Map([
|
|
13
|
+
['near:mainnet', 'mainnet'],
|
|
14
|
+
['near:testnet', 'testnet'],
|
|
15
|
+
]);
|
|
16
|
+
/** The selector's only RPC per network. The page CSP allows exactly these (browser-login.ts). */
|
|
17
|
+
const NEAR_RPC = {
|
|
18
|
+
mainnet: 'https://free.rpc.fastnear.com',
|
|
19
|
+
testnet: 'https://test.rpc.fastnear.com',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* NEAR wallets offered on this page and the networks each is bound to. MyNearWallet is retired
|
|
23
|
+
* and no longer connects to apps. HOT's selector module sends no network with its requests, so
|
|
24
|
+
* it is offered for mainnet only and never loaded for another network.
|
|
25
|
+
*/
|
|
26
|
+
const NEAR_WALLETS = new Map([
|
|
27
|
+
['meteor-wallet', { name: 'Meteor Wallet', networks: ['mainnet', 'testnet'] }],
|
|
28
|
+
['hot-wallet', { name: 'HOT Wallet', networks: ['mainnet'] }],
|
|
29
|
+
]);
|
|
30
|
+
const fragment = new URLSearchParams(location.hash.slice(1));
|
|
31
|
+
const redirected = location.pathname === '/callback';
|
|
32
|
+
let capability = redirected ? '' : location.hash.slice(1);
|
|
33
|
+
history.replaceState(null, '', location.pathname);
|
|
34
|
+
const api = async (path, body) => {
|
|
35
|
+
const r = await fetch(path, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: { authorization: `Bearer ${capability}`, 'content-type': 'application/json' },
|
|
38
|
+
cache: 'no-store',
|
|
39
|
+
credentials: 'omit',
|
|
40
|
+
redirect: 'error',
|
|
41
|
+
body: JSON.stringify(body ?? {}),
|
|
42
|
+
});
|
|
43
|
+
if (!r.ok)
|
|
44
|
+
throw new Error('Session expired or wallet result rejected. Return to the terminal.');
|
|
45
|
+
return r.json();
|
|
46
|
+
};
|
|
47
|
+
const used = new Set();
|
|
48
|
+
const callbacks = new Map();
|
|
49
|
+
let current;
|
|
50
|
+
if (redirected) {
|
|
51
|
+
// Only a per-action opaque nonce leaves this origin. The capability stays in the opener.
|
|
52
|
+
window.opener?.postMessage({
|
|
53
|
+
type: 'annon-wallet-result',
|
|
54
|
+
state: fragment.get('state'),
|
|
55
|
+
result: {
|
|
56
|
+
accountId: fragment.get('accountId'),
|
|
57
|
+
publicKey: fragment.get('publicKey'),
|
|
58
|
+
signature: fragment.get('signature'),
|
|
59
|
+
},
|
|
60
|
+
}, location.origin);
|
|
61
|
+
status.textContent = 'Proof returned to the approval window. Return to your terminal.';
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
window.addEventListener('message', (event) => {
|
|
65
|
+
if (event.origin !== location.origin || event.data?.type !== 'annon-wallet-result')
|
|
66
|
+
return;
|
|
67
|
+
const id = callbacks.get(event.data.state);
|
|
68
|
+
if (!id)
|
|
69
|
+
return;
|
|
70
|
+
callbacks.delete(event.data.state);
|
|
71
|
+
void api('/api/result', { id, result: event.data.result })
|
|
72
|
+
.then(() => {
|
|
73
|
+
status.textContent = 'Proof verified. Return to your terminal.';
|
|
74
|
+
})
|
|
75
|
+
.catch((e) => {
|
|
76
|
+
status.textContent = e.message;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function poll() {
|
|
81
|
+
if (!capability) {
|
|
82
|
+
status.textContent = 'Open the exact URL printed by your CLI.';
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const r = await api('/api/action');
|
|
87
|
+
pair.textContent = `Pairing code: ${r.pairingCode}. Match this with your terminal.`;
|
|
88
|
+
current = r.action ?? undefined;
|
|
89
|
+
display.textContent = current ? JSON.stringify(current, null, 2) : 'Waiting for the CLI…';
|
|
90
|
+
approve.disabled = !current || used.has(current.id);
|
|
91
|
+
if (hotChoice)
|
|
92
|
+
hotChoice.disabled =
|
|
93
|
+
current?.chain?.startsWith('near:') === true && current.chain !== 'near:mainnet';
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
void poll();
|
|
96
|
+
}, 1000);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
status.textContent = e.message;
|
|
100
|
+
capability = '';
|
|
101
|
+
approve.disabled = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
approve.onclick = async () => {
|
|
105
|
+
const q = current;
|
|
106
|
+
if (!q || used.has(q.id) || Date.now() >= q.expiresAt)
|
|
107
|
+
return;
|
|
108
|
+
used.add(q.id);
|
|
109
|
+
approve.disabled = true;
|
|
110
|
+
try {
|
|
111
|
+
let result;
|
|
112
|
+
if (q.operation.startsWith('evm.')) {
|
|
113
|
+
const provider = window.ethereum;
|
|
114
|
+
if (!provider)
|
|
115
|
+
throw new Error('Install an injected EVM wallet.');
|
|
116
|
+
const accounts = (await provider.request({ method: 'eth_requestAccounts' }));
|
|
117
|
+
const address = q.account || accounts[0];
|
|
118
|
+
if (!address)
|
|
119
|
+
throw new Error('No account');
|
|
120
|
+
const chain = await provider.request({ method: 'eth_chainId' });
|
|
121
|
+
if (`eip155:${BigInt(String(chain))}` !== q.chain)
|
|
122
|
+
throw new Error(`Select ${q.chain} in your wallet.`);
|
|
123
|
+
const wallet = evmWallet(provider, address.toLowerCase());
|
|
124
|
+
result =
|
|
125
|
+
q.operation === 'evm.personalSign'
|
|
126
|
+
? {
|
|
127
|
+
signature: (await wallet.authorize(q.payload.message))?.sig ?? '',
|
|
128
|
+
account: wallet.identity.id,
|
|
129
|
+
}
|
|
130
|
+
: { signature: await wallet.signTypedData(q.payload) };
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const networkId = NEAR_NETWORKS.get(q.chain);
|
|
134
|
+
if (!networkId)
|
|
135
|
+
throw new Error(`Browser NEAR wallets support near:mainnet and near:testnet, not ${q.chain}.`);
|
|
136
|
+
const id = nearChoice?.value || 'meteor-wallet';
|
|
137
|
+
const offered = NEAR_WALLETS.get(id);
|
|
138
|
+
if (!offered)
|
|
139
|
+
throw new Error('Unknown NEAR wallet');
|
|
140
|
+
if (!offered.networks.includes(networkId))
|
|
141
|
+
throw new Error(`${offered.name} is offered for near:mainnet only. Pick Meteor Wallet.`);
|
|
142
|
+
// Only the chosen wallet is loaded, on first use: the page starts without wallet code
|
|
143
|
+
// touching storage or listeners, and a refused wallet never runs.
|
|
144
|
+
const [{ setupWalletSelector }, module] = await Promise.all([
|
|
145
|
+
import('@near-wallet-selector/core'),
|
|
146
|
+
id === 'hot-wallet'
|
|
147
|
+
? import('@near-wallet-selector/hot-wallet').then((m) => m.setupHotWallet())
|
|
148
|
+
: import('@near-wallet-selector/meteor-wallet').then((m) => m.setupMeteorWallet()),
|
|
149
|
+
]);
|
|
150
|
+
const selector = await setupWalletSelector({
|
|
151
|
+
network: networkId,
|
|
152
|
+
fallbackRpcUrls: [NEAR_RPC[networkId]],
|
|
153
|
+
modules: [module],
|
|
154
|
+
});
|
|
155
|
+
const wallet = await selector.wallet(id);
|
|
156
|
+
const accounts = await signInAccountOnly(wallet);
|
|
157
|
+
const account = q.account || accounts[0]?.accountId;
|
|
158
|
+
if (!account || !accounts.some((a) => a.accountId === account))
|
|
159
|
+
throw new Error('Select the requested NEAR account.');
|
|
160
|
+
if (q.operation === 'near.nep413') {
|
|
161
|
+
if (!wallet.signMessage)
|
|
162
|
+
throw new Error('NEP-413 unavailable');
|
|
163
|
+
const p = q.payload;
|
|
164
|
+
const state = crypto.randomUUID();
|
|
165
|
+
callbacks.set(state, q.id);
|
|
166
|
+
const signed = await wallet.signMessage({
|
|
167
|
+
...p,
|
|
168
|
+
nonce: Buffer.from(p.nonce),
|
|
169
|
+
state,
|
|
170
|
+
});
|
|
171
|
+
if (!signed)
|
|
172
|
+
return; // redirect wallets: /callback forwards the fragment
|
|
173
|
+
callbacks.delete(state);
|
|
174
|
+
result = signed;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const p = q.payload;
|
|
178
|
+
const outcome = await wallet.signAndSendTransaction({
|
|
179
|
+
signerId: account,
|
|
180
|
+
receiverId: p.receiverId,
|
|
181
|
+
// Selector v10 passes Borsh Action structs through to its transaction encoder.
|
|
182
|
+
actions: [
|
|
183
|
+
{
|
|
184
|
+
functionCall: {
|
|
185
|
+
methodName: p.method,
|
|
186
|
+
args: Buffer.from(JSON.stringify(p.args)),
|
|
187
|
+
gas: BigInt(p.gas),
|
|
188
|
+
deposit: BigInt(p.deposit),
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
});
|
|
193
|
+
if (!outcome)
|
|
194
|
+
return;
|
|
195
|
+
result = { txHash: outcome.transaction.hash };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
await api('/api/result', { id: q.id, result });
|
|
199
|
+
status.textContent = 'Verified. Return to the terminal.';
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
status.textContent = e.message;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
approve.disabled = true;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
if (!redirected) {
|
|
209
|
+
void (async () => {
|
|
210
|
+
if (!capability)
|
|
211
|
+
capability = (await api('/api/bootstrap')).capability;
|
|
212
|
+
await poll();
|
|
213
|
+
})().catch((e) => {
|
|
214
|
+
status.textContent = e.message;
|
|
215
|
+
});
|
|
216
|
+
}
|