@defdone/annon 0.0.0-stage → 0.1.0-alpha.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.
- package/CHANGELOG.md +56 -0
- package/CLI.md +378 -0
- package/LICENSE +201 -0
- package/NOTICE +7 -0
- package/README.md +581 -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 +116 -0
- package/dist/browser/login.d.ts +1 -0
- package/dist/browser/login.js +177 -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 +99 -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 +18 -0
- package/dist/node/browser-login.js +212 -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 +147 -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 +393 -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 +135 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { setupWalletSelector } from '@near-wallet-selector/core';
|
|
2
|
+
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { signInAccountOnly } from '../wallet/account-only.js';
|
|
5
|
+
import { evmWallet } from '../wallet/wallet.js';
|
|
6
|
+
Object.assign(globalThis, { Buffer });
|
|
7
|
+
const pair = document.getElementById('pair');
|
|
8
|
+
const display = document.getElementById('action');
|
|
9
|
+
const status = document.getElementById('status');
|
|
10
|
+
const approve = document.getElementById('approve');
|
|
11
|
+
const fragment = new URLSearchParams(location.hash.slice(1));
|
|
12
|
+
const redirected = location.pathname === '/callback';
|
|
13
|
+
let capability = redirected ? '' : location.hash.slice(1);
|
|
14
|
+
history.replaceState(null, '', location.pathname);
|
|
15
|
+
const api = async (path, body) => {
|
|
16
|
+
const r = await fetch(path, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: { authorization: `Bearer ${capability}`, 'content-type': 'application/json' },
|
|
19
|
+
cache: 'no-store',
|
|
20
|
+
credentials: 'omit',
|
|
21
|
+
redirect: 'error',
|
|
22
|
+
body: JSON.stringify(body ?? {}),
|
|
23
|
+
});
|
|
24
|
+
if (!r.ok)
|
|
25
|
+
throw new Error('Session expired or wallet result rejected. Return to the terminal.');
|
|
26
|
+
return r.json();
|
|
27
|
+
};
|
|
28
|
+
const used = new Set();
|
|
29
|
+
const callbacks = new Map();
|
|
30
|
+
let current;
|
|
31
|
+
if (redirected) {
|
|
32
|
+
// Only a per-action opaque nonce leaves this origin. The capability stays in the opener.
|
|
33
|
+
window.opener?.postMessage({
|
|
34
|
+
type: 'annon-wallet-result',
|
|
35
|
+
state: fragment.get('state'),
|
|
36
|
+
result: {
|
|
37
|
+
accountId: fragment.get('accountId'),
|
|
38
|
+
publicKey: fragment.get('publicKey'),
|
|
39
|
+
signature: fragment.get('signature'),
|
|
40
|
+
},
|
|
41
|
+
}, location.origin);
|
|
42
|
+
status.textContent = 'Proof returned to the approval window. Return to your terminal.';
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
window.addEventListener('message', (event) => {
|
|
46
|
+
if (event.origin !== location.origin || event.data?.type !== 'annon-wallet-result')
|
|
47
|
+
return;
|
|
48
|
+
const id = callbacks.get(event.data.state);
|
|
49
|
+
if (!id)
|
|
50
|
+
return;
|
|
51
|
+
callbacks.delete(event.data.state);
|
|
52
|
+
void api('/api/result', { id, result: event.data.result })
|
|
53
|
+
.then(() => {
|
|
54
|
+
status.textContent = 'Proof verified. Return to your terminal.';
|
|
55
|
+
})
|
|
56
|
+
.catch((e) => {
|
|
57
|
+
status.textContent = e.message;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async function poll() {
|
|
62
|
+
if (!capability) {
|
|
63
|
+
status.textContent = 'Open the exact URL printed by your CLI.';
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const r = await api('/api/action');
|
|
68
|
+
pair.textContent = `Pairing code: ${r.pairingCode}. Match this with your terminal.`;
|
|
69
|
+
current = r.action ?? undefined;
|
|
70
|
+
display.textContent = current ? JSON.stringify(current, null, 2) : 'Waiting for the CLI…';
|
|
71
|
+
approve.disabled = !current || used.has(current.id);
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
void poll();
|
|
74
|
+
}, 1000);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
status.textContent = e.message;
|
|
78
|
+
capability = '';
|
|
79
|
+
approve.disabled = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
approve.onclick = async () => {
|
|
83
|
+
const q = current;
|
|
84
|
+
if (!q || used.has(q.id) || Date.now() >= q.expiresAt)
|
|
85
|
+
return;
|
|
86
|
+
used.add(q.id);
|
|
87
|
+
approve.disabled = true;
|
|
88
|
+
try {
|
|
89
|
+
let result;
|
|
90
|
+
if (q.operation.startsWith('evm.')) {
|
|
91
|
+
const provider = window.ethereum;
|
|
92
|
+
if (!provider)
|
|
93
|
+
throw new Error('Install an injected EVM wallet.');
|
|
94
|
+
const accounts = (await provider.request({ method: 'eth_requestAccounts' }));
|
|
95
|
+
const address = q.account || accounts[0];
|
|
96
|
+
if (!address)
|
|
97
|
+
throw new Error('No account');
|
|
98
|
+
const chain = await provider.request({ method: 'eth_chainId' });
|
|
99
|
+
if (`eip155:${BigInt(String(chain))}` !== q.chain)
|
|
100
|
+
throw new Error(`Select ${q.chain} in your wallet.`);
|
|
101
|
+
const wallet = evmWallet(provider, address.toLowerCase());
|
|
102
|
+
result =
|
|
103
|
+
q.operation === 'evm.personalSign'
|
|
104
|
+
? {
|
|
105
|
+
signature: (await wallet.authorize(q.payload.message))?.sig ?? '',
|
|
106
|
+
account: wallet.identity.id,
|
|
107
|
+
}
|
|
108
|
+
: { signature: await wallet.signTypedData(q.payload) };
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const networkId = q.chain === 'near:mainnet' ? 'mainnet' : 'testnet';
|
|
112
|
+
const selector = await setupWalletSelector({
|
|
113
|
+
network: networkId,
|
|
114
|
+
modules: [setupMyNearWallet()],
|
|
115
|
+
});
|
|
116
|
+
const wallet = await selector.wallet('my-near-wallet');
|
|
117
|
+
const accounts = await signInAccountOnly(wallet);
|
|
118
|
+
const account = q.account || accounts[0]?.accountId;
|
|
119
|
+
if (!account || !accounts.some((a) => a.accountId === account))
|
|
120
|
+
throw new Error('Select the requested NEAR account.');
|
|
121
|
+
if (q.operation === 'near.nep413') {
|
|
122
|
+
if (!wallet.signMessage)
|
|
123
|
+
throw new Error('NEP-413 unavailable');
|
|
124
|
+
const p = q.payload;
|
|
125
|
+
const state = crypto.randomUUID();
|
|
126
|
+
callbacks.set(state, q.id);
|
|
127
|
+
const signed = await wallet.signMessage({
|
|
128
|
+
...p,
|
|
129
|
+
nonce: Buffer.from(p.nonce),
|
|
130
|
+
state,
|
|
131
|
+
});
|
|
132
|
+
if (!signed)
|
|
133
|
+
return; // redirect wallet: /callback forwards fragment
|
|
134
|
+
callbacks.delete(state);
|
|
135
|
+
result = signed;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const p = q.payload;
|
|
139
|
+
const outcome = await wallet.signAndSendTransaction({
|
|
140
|
+
signerId: account,
|
|
141
|
+
receiverId: p.receiverId,
|
|
142
|
+
// Selector v10 passes Borsh Action structs through to its transaction encoder.
|
|
143
|
+
actions: [
|
|
144
|
+
{
|
|
145
|
+
functionCall: {
|
|
146
|
+
methodName: p.method,
|
|
147
|
+
args: Buffer.from(JSON.stringify(p.args)),
|
|
148
|
+
gas: BigInt(p.gas),
|
|
149
|
+
deposit: BigInt(p.deposit),
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
if (!outcome)
|
|
155
|
+
return;
|
|
156
|
+
result = { txHash: outcome.transaction.hash };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
await api('/api/result', { id: q.id, result });
|
|
160
|
+
status.textContent = 'Verified. Return to the terminal.';
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
status.textContent = e.message;
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
approve.disabled = true;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
if (!redirected) {
|
|
170
|
+
void (async () => {
|
|
171
|
+
if (!capability)
|
|
172
|
+
capability = (await api('/api/bootstrap')).capability;
|
|
173
|
+
await poll();
|
|
174
|
+
})().catch((e) => {
|
|
175
|
+
status.textContent = e.message;
|
|
176
|
+
});
|
|
177
|
+
}
|