@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,100 @@
|
|
|
1
|
+
import type { Account } from 'near-api-js';
|
|
2
|
+
import { AnnonError } from '../errors.js';
|
|
3
|
+
import { type NearMessage, type NearSignedMessage, type RecoveryProofContext } from '../near/nep413.js';
|
|
4
|
+
import type { TypedData } from '../pay/eip3009.js';
|
|
5
|
+
import { type Authorization, type Identity } from '../settle-near/identity.js';
|
|
6
|
+
import type { SettlementAssets } from '../settle-near/terms.js';
|
|
7
|
+
export interface IdentityWallet {
|
|
8
|
+
identity: Identity;
|
|
9
|
+
authorize(text: string): Promise<Authorization | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export interface EvmWallet extends IdentityWallet {
|
|
12
|
+
address: string;
|
|
13
|
+
signTypedData(data: TypedData): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
/** Accept an EIP-1193 provider or the provider member of an EIP-6963 announcement. */
|
|
16
|
+
export declare function evmWallet(input: {
|
|
17
|
+
request(args: {
|
|
18
|
+
method: string;
|
|
19
|
+
params?: unknown;
|
|
20
|
+
}): Promise<unknown>;
|
|
21
|
+
} | {
|
|
22
|
+
provider: {
|
|
23
|
+
request(args: {
|
|
24
|
+
method: string;
|
|
25
|
+
params?: unknown;
|
|
26
|
+
}): Promise<unknown>;
|
|
27
|
+
};
|
|
28
|
+
}, address: string): EvmWallet;
|
|
29
|
+
export interface SolanaAccount {
|
|
30
|
+
publicKey: Uint8Array;
|
|
31
|
+
address: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SolanaStandard {
|
|
34
|
+
features: {
|
|
35
|
+
'solana:signMessage': {
|
|
36
|
+
signMessage(...inputs: {
|
|
37
|
+
account: SolanaAccount;
|
|
38
|
+
message: Uint8Array;
|
|
39
|
+
}[]): Promise<readonly {
|
|
40
|
+
signature: Uint8Array;
|
|
41
|
+
signedMessage: Uint8Array;
|
|
42
|
+
}[]>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare function solanaWallet(wallet: SolanaStandard, account: SolanaAccount): IdentityWallet;
|
|
47
|
+
export interface NearCall {
|
|
48
|
+
receiverId: string;
|
|
49
|
+
method: string;
|
|
50
|
+
args: object;
|
|
51
|
+
gas?: bigint;
|
|
52
|
+
deposit?: bigint;
|
|
53
|
+
}
|
|
54
|
+
export interface NearWallet extends IdentityWallet {
|
|
55
|
+
call(call: NearCall): Promise<unknown>;
|
|
56
|
+
transferPurchase(message: string, assets?: SettlementAssets): Promise<unknown>;
|
|
57
|
+
/** Adapters default to NEP-413 plus a final full-access-key check before using NEAR recovery. */
|
|
58
|
+
proveControl?: (text: string, context: RecoveryProofContext) => Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
export interface SelectorWallet {
|
|
61
|
+
signMessage?: (p: NearMessage) => Promise<NearSignedMessage | undefined>;
|
|
62
|
+
getAccounts(): Promise<readonly {
|
|
63
|
+
accountId: string;
|
|
64
|
+
}[]>;
|
|
65
|
+
signAndSendTransaction(tx: {
|
|
66
|
+
signerId: string;
|
|
67
|
+
receiverId: string;
|
|
68
|
+
actions: {
|
|
69
|
+
type: 'FunctionCall';
|
|
70
|
+
params: {
|
|
71
|
+
methodName: string;
|
|
72
|
+
args: object;
|
|
73
|
+
gas: string;
|
|
74
|
+
deposit: string;
|
|
75
|
+
};
|
|
76
|
+
}[];
|
|
77
|
+
}): Promise<unknown>;
|
|
78
|
+
}
|
|
79
|
+
export declare function nearSelectorWallet(wallet: SelectorWallet, accountId: string, proveControl?: NearWallet['proveControl']): NearWallet;
|
|
80
|
+
/** Pass a near-api-js Account constructed with a KeyPair signer. The account sends the call itself. */
|
|
81
|
+
export declare function nearKeyPairWallet(account: {
|
|
82
|
+
accountId: string;
|
|
83
|
+
getSigner?: Account['getSigner'];
|
|
84
|
+
callFunction(args: {
|
|
85
|
+
contractId: string;
|
|
86
|
+
methodName: string;
|
|
87
|
+
args: object;
|
|
88
|
+
gas: bigint;
|
|
89
|
+
deposit: bigint;
|
|
90
|
+
}): Promise<unknown>;
|
|
91
|
+
}, proveControl?: NearWallet['proveControl']): NearWallet;
|
|
92
|
+
/** Prepay Annon storage explicitly before zero-deposit register/reopen calls. */
|
|
93
|
+
export declare function storageDeposit(wallet: Pick<NearWallet, 'call'>, contract: string, amount: bigint): Promise<unknown>;
|
|
94
|
+
/** A final funding refusal, safe to correct and retry. */
|
|
95
|
+
export declare class FileFundingRefused extends AnnonError {
|
|
96
|
+
readonly code = "funding_refused";
|
|
97
|
+
constructor();
|
|
98
|
+
}
|
|
99
|
+
/** Explicit, nonwithdrawable purchase storage allocation. Zero attachment uses own prepaid balance. */
|
|
100
|
+
export declare function fundFileStorage(wallet: Pick<NearWallet, 'call'>, contract: string, fileId: string, amount: bigint, prepaid?: boolean): Promise<unknown>;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/** Wallet adapters: authoritative text in, checked authorization out. No browser globals. */
|
|
2
|
+
import { base64 } from '@scure/base';
|
|
3
|
+
import { signMessage as signNearMessage } from 'near-api-js/nep413';
|
|
4
|
+
import { createWalletClient, custom } from 'viem';
|
|
5
|
+
import { base } from 'viem/chains';
|
|
6
|
+
import { AnnonError } from '../errors.js';
|
|
7
|
+
import { proveNearControl, } from '../near/nep413.js';
|
|
8
|
+
import { readOutcome } from '../near/rpc.js';
|
|
9
|
+
import { hex, account as nearAccount } from '../settle-near/codec.js';
|
|
10
|
+
import { parseIdentity, solanaWalletAuth, verifyAuthorization, } from '../settle-near/identity.js';
|
|
11
|
+
import { parsePurchaseMessage } from '../settle-near/purchase.js';
|
|
12
|
+
/** Accept an EIP-1193 provider or the provider member of an EIP-6963 announcement. */
|
|
13
|
+
export function evmWallet(input, address) {
|
|
14
|
+
const provider = 'provider' in input ? input.provider : input;
|
|
15
|
+
const identity = parseIdentity({ kind: 'evm', id: address });
|
|
16
|
+
const client = createWalletClient({
|
|
17
|
+
chain: base,
|
|
18
|
+
transport: custom(provider),
|
|
19
|
+
});
|
|
20
|
+
const selected = async () => {
|
|
21
|
+
const accounts = await provider.request({ method: 'eth_accounts' });
|
|
22
|
+
if (!Array.isArray(accounts) ||
|
|
23
|
+
!accounts.some((a) => typeof a === 'string' && a.toLowerCase() === identity.id))
|
|
24
|
+
throw new AnnonError('wrong_identity', 'wallet does not control the selected identity');
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
identity,
|
|
28
|
+
address: identity.id,
|
|
29
|
+
async authorize(text) {
|
|
30
|
+
await selected();
|
|
31
|
+
const sig = await client.signMessage({
|
|
32
|
+
account: identity.id,
|
|
33
|
+
message: text,
|
|
34
|
+
});
|
|
35
|
+
const auth = { kind: 'evm', sig };
|
|
36
|
+
if (!verifyAuthorization(identity, text, auth))
|
|
37
|
+
throw new AnnonError('invalid_signature', 'wallet signature does not match identity');
|
|
38
|
+
return auth;
|
|
39
|
+
},
|
|
40
|
+
async signTypedData(data) {
|
|
41
|
+
await selected();
|
|
42
|
+
return client.signTypedData({
|
|
43
|
+
...data,
|
|
44
|
+
account: identity.id,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function solanaWallet(wallet, account) {
|
|
50
|
+
const identity = parseIdentity({ kind: 'solana', id: hex(account.publicKey).slice(2) });
|
|
51
|
+
return {
|
|
52
|
+
identity,
|
|
53
|
+
async authorize(text) {
|
|
54
|
+
const results = await wallet.features['solana:signMessage'].signMessage({
|
|
55
|
+
account,
|
|
56
|
+
message: new TextEncoder().encode(text),
|
|
57
|
+
});
|
|
58
|
+
if (results.length !== 1 || !results[0])
|
|
59
|
+
throw new AnnonError('invalid_signature', 'wallet returned no single signature');
|
|
60
|
+
return solanaWalletAuth(identity, text, results[0]);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function nearWallet(accountId, selected, call, proveControl) {
|
|
65
|
+
const identity = parseIdentity({ kind: 'near', id: accountId });
|
|
66
|
+
return {
|
|
67
|
+
identity,
|
|
68
|
+
...(proveControl ? { proveControl } : {}),
|
|
69
|
+
async authorize(_text) {
|
|
70
|
+
await selected();
|
|
71
|
+
return undefined;
|
|
72
|
+
},
|
|
73
|
+
async call(request) {
|
|
74
|
+
await selected();
|
|
75
|
+
return call(request);
|
|
76
|
+
},
|
|
77
|
+
async transferPurchase(message, assets) {
|
|
78
|
+
const p = parsePurchaseMessage(message, assets);
|
|
79
|
+
if (p.route !== 'near-usdc')
|
|
80
|
+
throw new TypeError('not a NEAR USDC purchase');
|
|
81
|
+
if (BigInt(p.expires_at) <= BigInt(Math.floor(Date.now() / 1000)))
|
|
82
|
+
throw new AnnonError('payment_expired', 'purchase expired');
|
|
83
|
+
await selected();
|
|
84
|
+
return call({
|
|
85
|
+
receiverId: p.asset,
|
|
86
|
+
method: 'ft_transfer_call',
|
|
87
|
+
args: { receiver_id: p.contract, amount: p.price, msg: message },
|
|
88
|
+
gas: 150000000000000n,
|
|
89
|
+
deposit: 1n,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function nearSelectorWallet(wallet, accountId, proveControl) {
|
|
95
|
+
return nearWallet(accountId, async () => {
|
|
96
|
+
if (!(await wallet.getAccounts()).some((a) => a.accountId === accountId))
|
|
97
|
+
throw new AnnonError('wrong_identity', 'wallet does not control the NEAR account');
|
|
98
|
+
}, (call) => wallet.signAndSendTransaction({
|
|
99
|
+
signerId: accountId,
|
|
100
|
+
receiverId: call.receiverId,
|
|
101
|
+
actions: [
|
|
102
|
+
{
|
|
103
|
+
type: 'FunctionCall',
|
|
104
|
+
params: {
|
|
105
|
+
methodName: call.method,
|
|
106
|
+
args: call.args,
|
|
107
|
+
gas: String(call.gas ?? 300000000000000n),
|
|
108
|
+
deposit: String(call.deposit ?? 0n),
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
}), proveControl ??
|
|
113
|
+
((text, context) => {
|
|
114
|
+
if (!wallet.signMessage)
|
|
115
|
+
throw new AnnonError('missing_method', 'NEAR recovery requires NEP-413 signMessage');
|
|
116
|
+
return proveNearControl(accountId, text, context, (p) => wallet.signMessage?.(p) ?? Promise.resolve(undefined));
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
/** Pass a near-api-js Account constructed with a KeyPair signer. The account sends the call itself. */
|
|
120
|
+
export function nearKeyPairWallet(account, proveControl) {
|
|
121
|
+
return nearWallet(account.accountId, async () => { }, (call) => account.callFunction({
|
|
122
|
+
contractId: call.receiverId,
|
|
123
|
+
methodName: call.method,
|
|
124
|
+
args: call.args,
|
|
125
|
+
gas: call.gas ?? 300000000000000n,
|
|
126
|
+
deposit: call.deposit ?? 0n,
|
|
127
|
+
}), proveControl ??
|
|
128
|
+
(async (text, context) => {
|
|
129
|
+
if (!account.getSigner)
|
|
130
|
+
throw new AnnonError('missing_method', 'NEAR recovery requires a NEP-413 signer');
|
|
131
|
+
await proveNearControl(account.accountId, text, context, async (payload) => {
|
|
132
|
+
const result = await signNearMessage({ signerAccount: account, payload });
|
|
133
|
+
return {
|
|
134
|
+
accountId: result.accountId,
|
|
135
|
+
publicKey: result.publicKey.toString(),
|
|
136
|
+
signature: base64.encode(result.signature),
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
/** Prepay Annon storage explicitly before zero-deposit register/reopen calls. */
|
|
142
|
+
export async function storageDeposit(wallet, contract, amount) {
|
|
143
|
+
if (amount <= 0n)
|
|
144
|
+
throw new RangeError('storage deposit must be positive');
|
|
145
|
+
return wallet.call({
|
|
146
|
+
receiverId: nearAccount(contract),
|
|
147
|
+
method: 'storage_deposit',
|
|
148
|
+
args: {},
|
|
149
|
+
deposit: amount,
|
|
150
|
+
gas: 30000000000000n,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** A final funding refusal, safe to correct and retry. */
|
|
154
|
+
export class FileFundingRefused extends AnnonError {
|
|
155
|
+
code = 'funding_refused';
|
|
156
|
+
constructor() {
|
|
157
|
+
super('funding_refused', 'File funding was refused.');
|
|
158
|
+
this.name = 'FileFundingRefused';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Explicit, nonwithdrawable purchase storage allocation. Zero attachment uses own prepaid balance. */
|
|
162
|
+
export async function fundFileStorage(wallet, contract, fileId, amount, prepaid = false) {
|
|
163
|
+
if (amount <= 0n || amount >= 2n ** 128n || !/^0x[0-9a-f]{64}$/.test(fileId))
|
|
164
|
+
throw new RangeError('invalid file funding');
|
|
165
|
+
const request = {
|
|
166
|
+
receiverId: nearAccount(contract),
|
|
167
|
+
method: 'fund_file_storage',
|
|
168
|
+
args: { file_id: fileId, amount: amount.toString() },
|
|
169
|
+
deposit: prepaid ? 0n : amount,
|
|
170
|
+
gas: 30000000000000n,
|
|
171
|
+
};
|
|
172
|
+
const refused = (result) => {
|
|
173
|
+
if (!result || typeof result !== 'object' || !('transaction' in result))
|
|
174
|
+
return false;
|
|
175
|
+
try {
|
|
176
|
+
const transaction = result
|
|
177
|
+
.transaction;
|
|
178
|
+
return (readOutcome(result, contract, {
|
|
179
|
+
txHash: transaction.hash,
|
|
180
|
+
signer: transaction.signer_id,
|
|
181
|
+
method: request.method,
|
|
182
|
+
args: request.args,
|
|
183
|
+
}).state === 'refused');
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
let result;
|
|
190
|
+
try {
|
|
191
|
+
result = await wallet.call(request);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
if (error &&
|
|
195
|
+
typeof error === 'object' &&
|
|
196
|
+
'transactionResult' in error &&
|
|
197
|
+
refused(error.transactionResult))
|
|
198
|
+
throw new FileFundingRefused();
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
if (refused(result))
|
|
202
|
+
throw new FileFundingRefused();
|
|
203
|
+
return result;
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,139 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defdone/annon",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Files only the buyer can open: encrypted on the client, the key released by NEAR once the payment is verified.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://annon.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/defdone/annon.git",
|
|
10
|
+
"directory": "packages/annon"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/defdone/annon/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"near",
|
|
17
|
+
"x402",
|
|
18
|
+
"encryption",
|
|
19
|
+
"payments",
|
|
20
|
+
"usdc",
|
|
21
|
+
"mpc",
|
|
22
|
+
"files",
|
|
23
|
+
"agents",
|
|
24
|
+
"cli"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=22"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public",
|
|
31
|
+
"tag": "alpha"
|
|
32
|
+
},
|
|
33
|
+
"type": "module",
|
|
34
|
+
"bin": {
|
|
35
|
+
"annon": "./dist/node/main.js"
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./browser": {
|
|
43
|
+
"types": "./dist/browser/index.d.ts",
|
|
44
|
+
"default": "./dist/browser/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./browser/purchase-bundle.js": "./dist/browser/purchase-bundle.js",
|
|
47
|
+
"./node": {
|
|
48
|
+
"types": "./dist/node/index.d.ts",
|
|
49
|
+
"default": "./dist/node/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./relay": {
|
|
52
|
+
"types": "./dist/relay/index.d.ts",
|
|
53
|
+
"default": "./dist/relay/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./download/host": {
|
|
56
|
+
"types": "./dist/download/host.d.ts",
|
|
57
|
+
"default": "./dist/download/host.js"
|
|
58
|
+
},
|
|
59
|
+
"./download/http": {
|
|
60
|
+
"types": "./dist/download/http.d.ts",
|
|
61
|
+
"default": "./dist/download/http.js"
|
|
62
|
+
},
|
|
63
|
+
"./envelope/pay2": {
|
|
64
|
+
"types": "./dist/envelope/pay2.d.ts",
|
|
65
|
+
"default": "./dist/envelope/pay2.js"
|
|
66
|
+
},
|
|
67
|
+
"./near/rpc": {
|
|
68
|
+
"types": "./dist/near/rpc.d.ts",
|
|
69
|
+
"default": "./dist/near/rpc.js"
|
|
70
|
+
},
|
|
71
|
+
"./pay/seller": {
|
|
72
|
+
"types": "./dist/pay/seller.d.ts",
|
|
73
|
+
"default": "./dist/pay/seller.js"
|
|
74
|
+
},
|
|
75
|
+
"./pay/settle": {
|
|
76
|
+
"types": "./dist/pay/settle.d.ts",
|
|
77
|
+
"default": "./dist/pay/settle.js"
|
|
78
|
+
},
|
|
79
|
+
"./pay/split": {
|
|
80
|
+
"types": "./dist/pay/split.d.ts",
|
|
81
|
+
"default": "./dist/pay/split.js"
|
|
82
|
+
},
|
|
83
|
+
"./pay/store": {
|
|
84
|
+
"types": "./dist/pay/store.d.ts",
|
|
85
|
+
"default": "./dist/pay/store.js"
|
|
86
|
+
},
|
|
87
|
+
"./pay/store-node": {
|
|
88
|
+
"types": "./dist/pay/store-node.d.ts",
|
|
89
|
+
"default": "./dist/pay/store-node.js"
|
|
90
|
+
},
|
|
91
|
+
"./node/signer-mock": {
|
|
92
|
+
"types": "./dist/node/signer-mock.d.ts",
|
|
93
|
+
"default": "./dist/node/signer-mock.js"
|
|
94
|
+
},
|
|
95
|
+
"./node/adapter": {
|
|
96
|
+
"types": "./dist/node/adapter.d.ts",
|
|
97
|
+
"default": "./dist/node/adapter.js"
|
|
98
|
+
},
|
|
99
|
+
"./node/cli": {
|
|
100
|
+
"types": "./dist/node/cli.d.ts",
|
|
101
|
+
"default": "./dist/node/cli.js"
|
|
102
|
+
},
|
|
103
|
+
"./node/errors": {
|
|
104
|
+
"types": "./dist/node/errors.d.ts",
|
|
105
|
+
"default": "./dist/node/errors.js"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"files": [
|
|
109
|
+
"dist",
|
|
110
|
+
"CLI.md",
|
|
111
|
+
"README.md",
|
|
112
|
+
"LICENSE",
|
|
113
|
+
"NOTICE",
|
|
114
|
+
"CHANGELOG.md"
|
|
115
|
+
],
|
|
116
|
+
"devDependencies": {
|
|
117
|
+
"@near-wallet-selector/core": "10.1.4",
|
|
118
|
+
"@near-wallet-selector/hot-wallet": "10.1.4",
|
|
119
|
+
"@near-wallet-selector/meteor-wallet": "10.1.4",
|
|
120
|
+
"@types/node": "26.6.5",
|
|
121
|
+
"buffer": "6.0.3",
|
|
122
|
+
"esbuild": "0.28.2",
|
|
123
|
+
"fake-indexeddb": "6.2.6",
|
|
124
|
+
"util": "0.12.5",
|
|
125
|
+
"vitest": "5.0.5"
|
|
126
|
+
},
|
|
127
|
+
"dependencies": {
|
|
128
|
+
"@noble/curves": "2.4.0",
|
|
129
|
+
"@noble/hashes": "2.4.0",
|
|
130
|
+
"@scure/base": "2.4.0",
|
|
131
|
+
"near-api-js": "7.4.0",
|
|
132
|
+
"viem": "2.57.10"
|
|
133
|
+
},
|
|
134
|
+
"scripts": {
|
|
135
|
+
"build": "rm -rf dist && tsc --noEmit && tsc -p tsconfig.build.json && node scripts/build-browser.ts",
|
|
136
|
+
"test": "vitest run && pnpm validate:package",
|
|
137
|
+
"validate:package": "node scripts/check-package.mjs"
|
|
138
|
+
}
|
|
6
139
|
}
|