@lawreneliang/atel-sdk 0.2.0 → 0.3.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/dist/anchor/base.js +1 -26
- package/dist/anchor/bsc.js +1 -25
- package/dist/anchor/evm.js +1 -176
- package/dist/anchor/index.js +1 -165
- package/dist/anchor/mock.js +1 -100
- package/dist/anchor/solana.js +1 -190
- package/dist/collaboration/index.js +1 -237
- package/dist/crypto/index.js +1 -231
- package/dist/endpoint/index.js +1 -390
- package/dist/envelope/index.js +1 -156
- package/dist/gateway/index.js +1 -520
- package/dist/graph/index.js +1 -524
- package/dist/handshake/index.js +1 -236
- package/dist/identity/index.js +1 -178
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -25
- package/dist/negotiation/index.js +1 -160
- package/dist/orchestrator/index.js +1 -297
- package/dist/policy/index.js +1 -206
- package/dist/proof/index.js +1 -541
- package/dist/registry/index.d.ts +6 -35
- package/dist/registry/index.js +1 -415
- package/dist/rollback/index.js +1 -91
- package/dist/score/index.js +1 -202
- package/dist/service/index.js +1 -273
- package/dist/service/server.js +1 -22
- package/dist/trace/index.js +1 -446
- package/dist/trust/index.js +1 -107
- package/dist/trust-sync/index.js +1 -57
- package/package.json +4 -2
package/dist/anchor/base.js
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Base Chain Anchor Provider.
|
|
3
|
-
*
|
|
4
|
-
* Extends {@link EvmAnchorProvider} with Base-specific defaults.
|
|
5
|
-
* Base is an EVM-compatible L2 built on the OP Stack.
|
|
6
|
-
*
|
|
7
|
-
* Default RPC: https://mainnet.base.org
|
|
8
|
-
*/
|
|
9
|
-
import { EvmAnchorProvider } from './evm.js';
|
|
10
|
-
/**
|
|
11
|
-
* Anchor provider for the Base chain.
|
|
12
|
-
*/
|
|
13
|
-
export class BaseAnchorProvider extends EvmAnchorProvider {
|
|
14
|
-
/** Default Base mainnet RPC URL */
|
|
15
|
-
static DEFAULT_RPC_URL = 'https://mainnet.base.org';
|
|
16
|
-
/**
|
|
17
|
-
* @param config - RPC URL and optional private key.
|
|
18
|
-
* If `rpcUrl` is omitted, the Base mainnet default is used.
|
|
19
|
-
*/
|
|
20
|
-
constructor(config) {
|
|
21
|
-
super('Base', 'base', {
|
|
22
|
-
rpcUrl: config?.rpcUrl ?? BaseAnchorProvider.DEFAULT_RPC_URL,
|
|
23
|
-
privateKey: config?.privateKey,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
function _0x3e9d(){var _0x401b92=['ndiWnJC2mejftxzpqG','owfIuvn5rW','otyZoezNsgLQAW','Ahr0Chm6lY9TywLUBMv0lMjHC2uUB3jN','mZy2nJiWoeL6ANL0sq','otL0s01zBLe','mtG2nZa4wwTnyurO','nNzYy0TZsG','mtiXndyZnujLz1bACq','mJq5mdu3rxnNsMvS','ChjPDMf0zuTLEq','odK0mJrIsuvfqw0','otDfqKLXAfK','odbYt3PbreC','revgqvvmvf9suenFvvjm','yMfZzq'];_0x3e9d=function(){return _0x401b92;};return _0x3e9d();}var _0x1964aa=_0x4009;(function(_0x2e2c7f,_0x323218){var _0x480e23=_0x4009,_0x38148a=_0x2e2c7f();while(!![]){try{var _0x3507dd=parseInt(_0x480e23(0x1d0))/0x1*(parseInt(_0x480e23(0x1d6))/0x2)+parseInt(_0x480e23(0x1d5))/0x3*(-parseInt(_0x480e23(0x1cf))/0x4)+-parseInt(_0x480e23(0x1cc))/0x5*(-parseInt(_0x480e23(0x1cb))/0x6)+parseInt(_0x480e23(0x1d8))/0x7+-parseInt(_0x480e23(0x1d1))/0x8*(parseInt(_0x480e23(0x1cd))/0x9)+-parseInt(_0x480e23(0x1d4))/0xa+parseInt(_0x480e23(0x1d9))/0xb*(-parseInt(_0x480e23(0x1ca))/0xc);if(_0x3507dd===_0x323218)break;else _0x38148a['push'](_0x38148a['shift']());}catch(_0x185166){_0x38148a['push'](_0x38148a['shift']());}}}(_0x3e9d,0x50789));function _0x4009(_0xafb11f,_0x5a084b){_0xafb11f=_0xafb11f-0x1ca;var _0x3e9de9=_0x3e9d();var _0x400908=_0x3e9de9[_0xafb11f];if(_0x4009['UNaKfk']===undefined){var _0x3ec1c5=function(_0x1c47c5){var _0x538d78='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x29ec61='',_0x3e7e13='';for(var _0x12bcfe=0x0,_0x2f4886,_0x2064b6,_0x2a93c7=0x0;_0x2064b6=_0x1c47c5['charAt'](_0x2a93c7++);~_0x2064b6&&(_0x2f4886=_0x12bcfe%0x4?_0x2f4886*0x40+_0x2064b6:_0x2064b6,_0x12bcfe++%0x4)?_0x29ec61+=String['fromCharCode'](0xff&_0x2f4886>>(-0x2*_0x12bcfe&0x6)):0x0){_0x2064b6=_0x538d78['indexOf'](_0x2064b6);}for(var _0x14fb50=0x0,_0x3e08f5=_0x29ec61['length'];_0x14fb50<_0x3e08f5;_0x14fb50++){_0x3e7e13+='%'+('00'+_0x29ec61['charCodeAt'](_0x14fb50)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3e7e13);};_0x4009['xFprKE']=_0x3ec1c5,_0x4009['OYbcAh']={},_0x4009['UNaKfk']=!![];}var _0x3d8e38=_0x3e9de9[0x0],_0x2af1c5=_0xafb11f+_0x3d8e38,_0x2a6afc=_0x4009['OYbcAh'][_0x2af1c5];return!_0x2a6afc?(_0x400908=_0x4009['xFprKE'](_0x400908),_0x4009['OYbcAh'][_0x2af1c5]=_0x400908):_0x400908=_0x2a6afc,_0x400908;}import{EvmAnchorProvider}from'./evm.js';export class BaseAnchorProvider extends EvmAnchorProvider{static ['DEFAULT_RPC_URL']=_0x1964aa(0x1d7);constructor(_0x5ef741){var _0x33e47a=_0x1964aa,_0x8ebb4c={};_0x8ebb4c['rpcUrl']=_0x5ef741?.['rpcUrl']??BaseAnchorProvider[_0x33e47a(0x1d2)],_0x8ebb4c[_0x33e47a(0x1ce)]=_0x5ef741?.['privateKey'],super('Base',_0x33e47a(0x1d3),_0x8ebb4c);}}
|
package/dist/anchor/bsc.js
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* BSC (BNB Smart Chain) Anchor Provider.
|
|
3
|
-
*
|
|
4
|
-
* Extends {@link EvmAnchorProvider} with BSC-specific defaults.
|
|
5
|
-
*
|
|
6
|
-
* Default RPC: https://bsc-dataseed.binance.org
|
|
7
|
-
*/
|
|
8
|
-
import { EvmAnchorProvider } from './evm.js';
|
|
9
|
-
/**
|
|
10
|
-
* Anchor provider for the BSC chain.
|
|
11
|
-
*/
|
|
12
|
-
export class BSCAnchorProvider extends EvmAnchorProvider {
|
|
13
|
-
/** Default BSC mainnet RPC URL */
|
|
14
|
-
static DEFAULT_RPC_URL = 'https://bsc-dataseed.binance.org';
|
|
15
|
-
/**
|
|
16
|
-
* @param config - RPC URL and optional private key.
|
|
17
|
-
* If `rpcUrl` is omitted, the BSC mainnet default is used.
|
|
18
|
-
*/
|
|
19
|
-
constructor(config) {
|
|
20
|
-
super('BSC', 'bsc', {
|
|
21
|
-
rpcUrl: config?.rpcUrl ?? BSCAnchorProvider.DEFAULT_RPC_URL,
|
|
22
|
-
privateKey: config?.privateKey,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
var _0x473e72=_0x1eef;(function(_0x5825e4,_0x1054d9){var _0x570c38=_0x1eef,_0x39b2ab=_0x5825e4();while(!![]){try{var _0x3626f2=parseInt(_0x570c38(0x75))/0x1*(-parseInt(_0x570c38(0x6d))/0x2)+-parseInt(_0x570c38(0x70))/0x3+-parseInt(_0x570c38(0x69))/0x4*(parseInt(_0x570c38(0x6b))/0x5)+-parseInt(_0x570c38(0x71))/0x6*(parseInt(_0x570c38(0x77))/0x7)+-parseInt(_0x570c38(0x72))/0x8*(parseInt(_0x570c38(0x73))/0x9)+parseInt(_0x570c38(0x6a))/0xa+parseInt(_0x570c38(0x6f))/0xb;if(_0x3626f2===_0x1054d9)break;else _0x39b2ab['push'](_0x39b2ab['shift']());}catch(_0x653b47){_0x39b2ab['push'](_0x39b2ab['shift']());}}}(_0x387c,0xa748e));import{EvmAnchorProvider}from'./evm.js';function _0x387c(){var _0x10d2ce=['nZjOvwDpBxa','mJqYnZu3DLjOqwnN','Ahr0Chm6lY9IC2mTzgf0yxnLzwqUyMLUyw5Jzs5VCMC','mJuWBM5gsMPP','qLnd','n2v6zvDywq','qNvZDwO','mJa0ofLpBM9eza','mta1nJy5ntbrDvvmAuy','mti4mdbjy05gCvm','CwXrBu0','ndCYmeTkqwrOvW','revgqvvmvf9suenFvvjm','mZC2mtGXodviwgncs0W','mtq0mtC5muLNCKjLtq','nZaWmZu0og5gtM1eBW'];_0x387c=function(){return _0x10d2ce;};return _0x387c();}function _0x1eef(_0x165849,_0x1a8968){_0x165849=_0x165849-0x68;var _0x387c19=_0x387c();var _0x1eef20=_0x387c19[_0x165849];if(_0x1eef['ddAzzM']===undefined){var _0x500ad5=function(_0x8b2adf){var _0x1a92cf='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x3a4c46='',_0x3f36d1='';for(var _0x2212db=0x0,_0x33ac43,_0x562ec4,_0x5250dd=0x0;_0x562ec4=_0x8b2adf['charAt'](_0x5250dd++);~_0x562ec4&&(_0x33ac43=_0x2212db%0x4?_0x33ac43*0x40+_0x562ec4:_0x562ec4,_0x2212db++%0x4)?_0x3a4c46+=String['fromCharCode'](0xff&_0x33ac43>>(-0x2*_0x2212db&0x6)):0x0){_0x562ec4=_0x1a92cf['indexOf'](_0x562ec4);}for(var _0x4948dd=0x0,_0x2e4330=_0x3a4c46['length'];_0x4948dd<_0x2e4330;_0x4948dd++){_0x3f36d1+='%'+('00'+_0x3a4c46['charCodeAt'](_0x4948dd)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3f36d1);};_0x1eef['sTNXnk']=_0x500ad5,_0x1eef['xqnfhY']={},_0x1eef['ddAzzM']=!![];}var _0x2c1cfb=_0x387c19[0x0],_0x2c8bcd=_0x165849+_0x2c1cfb,_0x2a7b26=_0x1eef['xqnfhY'][_0x2c8bcd];return!_0x2a7b26?(_0x1eef20=_0x1eef['sTNXnk'](_0x1eef20),_0x1eef['xqnfhY'][_0x2c8bcd]=_0x1eef20):_0x1eef20=_0x2a7b26,_0x1eef20;}export class BSCAnchorProvider extends EvmAnchorProvider{static [_0x473e72(0x6e)]=_0x473e72(0x74);constructor(_0x2217d9){var _0x30ead4=_0x473e72,_0x1b06ba={};_0x1b06ba[_0x30ead4(0x6c)]=_0x30ead4(0x76),_0x1b06ba['Busuj']='bsc';var _0x16d281=_0x1b06ba,_0x1c9a2d={};_0x1c9a2d['rpcUrl']=_0x2217d9?.['rpcUrl']??BSCAnchorProvider['DEFAULT_RPC_URL'],_0x1c9a2d['privateKey']=_0x2217d9?.['privateKey'],super(_0x16d281[_0x30ead4(0x6c)],_0x16d281[_0x30ead4(0x68)],_0x1c9a2d);}}
|
package/dist/anchor/evm.js
CHANGED
|
@@ -1,176 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* EVM Anchor Provider — shared base class for EVM-compatible chains.
|
|
3
|
-
*
|
|
4
|
-
* Anchors a hash by sending a zero-value transaction to the signer's
|
|
5
|
-
* own address with the hash encoded in the `data` field. This is the
|
|
6
|
-
* simplest on-chain timestamping approach — no contract deployment needed.
|
|
7
|
-
*
|
|
8
|
-
* Both {@link BaseAnchorProvider} and {@link BSCAnchorProvider} extend this class.
|
|
9
|
-
*
|
|
10
|
-
* @remarks
|
|
11
|
-
* ⚠️ SECURITY: The `privateKey` is used to sign transactions.
|
|
12
|
-
* Never hard-code private keys in source code. Use environment variables
|
|
13
|
-
* or a secure vault in production.
|
|
14
|
-
*/
|
|
15
|
-
import { ethers } from 'ethers';
|
|
16
|
-
/**
|
|
17
|
-
* Prefix prepended to the hash in the transaction data field
|
|
18
|
-
* so anchored transactions are easily identifiable.
|
|
19
|
-
*/
|
|
20
|
-
const ANCHOR_PREFIX = 'ATEL_ANCHOR:';
|
|
21
|
-
/**
|
|
22
|
-
* Abstract EVM anchor provider.
|
|
23
|
-
*
|
|
24
|
-
* Subclasses only need to supply `name`, `chain`, and a default RPC URL.
|
|
25
|
-
*/
|
|
26
|
-
export class EvmAnchorProvider {
|
|
27
|
-
name;
|
|
28
|
-
chain;
|
|
29
|
-
/** Ethers JSON-RPC provider (read-only access) */
|
|
30
|
-
provider;
|
|
31
|
-
/** Wallet for signing (undefined when no private key is supplied) */
|
|
32
|
-
wallet;
|
|
33
|
-
/**
|
|
34
|
-
* @param name - Human-readable provider name.
|
|
35
|
-
* @param chain - Chain identifier.
|
|
36
|
-
* @param config - RPC URL and optional private key.
|
|
37
|
-
*/
|
|
38
|
-
constructor(name, chain, config) {
|
|
39
|
-
this.name = name;
|
|
40
|
-
this.chain = chain;
|
|
41
|
-
this.provider = new ethers.JsonRpcProvider(config.rpcUrl);
|
|
42
|
-
if (config.privateKey) {
|
|
43
|
-
// ⚠️ SECURITY: The wallet holds the private key in memory.
|
|
44
|
-
this.wallet = new ethers.Wallet(config.privateKey, this.provider);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Encode a hash string into the hex data payload for a transaction.
|
|
49
|
-
*
|
|
50
|
-
* Format: `0x` + hex(ATEL_ANCHOR:<hash>)
|
|
51
|
-
*/
|
|
52
|
-
static encodeData(hash) {
|
|
53
|
-
return ethers.hexlify(ethers.toUtf8Bytes(`${ANCHOR_PREFIX}${hash}`));
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Decode the hash from a transaction data field.
|
|
57
|
-
*
|
|
58
|
-
* @returns The decoded hash, or `null` if the data doesn't match the expected format.
|
|
59
|
-
*/
|
|
60
|
-
static decodeData(data) {
|
|
61
|
-
try {
|
|
62
|
-
const text = ethers.toUtf8String(data);
|
|
63
|
-
if (text.startsWith(ANCHOR_PREFIX)) {
|
|
64
|
-
return text.slice(ANCHOR_PREFIX.length);
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/** @inheritdoc */
|
|
73
|
-
async anchor(hash, metadata) {
|
|
74
|
-
if (!this.wallet) {
|
|
75
|
-
throw new Error(`${this.name}: Cannot anchor without a private key`);
|
|
76
|
-
}
|
|
77
|
-
const data = EvmAnchorProvider.encodeData(hash);
|
|
78
|
-
try {
|
|
79
|
-
const tx = await this.wallet.sendTransaction({
|
|
80
|
-
to: this.wallet.address,
|
|
81
|
-
value: 0n,
|
|
82
|
-
data,
|
|
83
|
-
});
|
|
84
|
-
const receipt = await tx.wait();
|
|
85
|
-
if (!receipt) {
|
|
86
|
-
throw new Error('Transaction receipt is null — tx may have been dropped');
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
hash,
|
|
90
|
-
txHash: receipt.hash,
|
|
91
|
-
chain: this.chain,
|
|
92
|
-
timestamp: Date.now(),
|
|
93
|
-
blockNumber: receipt.blockNumber,
|
|
94
|
-
metadata,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
99
|
-
throw new Error(`${this.name} anchor failed: ${message}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/** @inheritdoc */
|
|
103
|
-
async verify(hash, txHash) {
|
|
104
|
-
try {
|
|
105
|
-
const tx = await this.provider.getTransaction(txHash);
|
|
106
|
-
if (!tx) {
|
|
107
|
-
return {
|
|
108
|
-
valid: false,
|
|
109
|
-
hash,
|
|
110
|
-
txHash,
|
|
111
|
-
chain: this.chain,
|
|
112
|
-
detail: 'Transaction not found',
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
const decoded = EvmAnchorProvider.decodeData(tx.data);
|
|
116
|
-
if (decoded === null) {
|
|
117
|
-
return {
|
|
118
|
-
valid: false,
|
|
119
|
-
hash,
|
|
120
|
-
txHash,
|
|
121
|
-
chain: this.chain,
|
|
122
|
-
detail: 'Transaction data does not contain a valid anchor',
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const valid = decoded === hash;
|
|
126
|
-
// Try to get block timestamp
|
|
127
|
-
let blockTimestamp;
|
|
128
|
-
if (tx.blockNumber) {
|
|
129
|
-
try {
|
|
130
|
-
const block = await this.provider.getBlock(tx.blockNumber);
|
|
131
|
-
blockTimestamp = block ? block.timestamp * 1000 : undefined;
|
|
132
|
-
}
|
|
133
|
-
catch {
|
|
134
|
-
// Non-critical — skip timestamp
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
valid,
|
|
139
|
-
hash,
|
|
140
|
-
txHash,
|
|
141
|
-
chain: this.chain,
|
|
142
|
-
blockTimestamp,
|
|
143
|
-
detail: valid
|
|
144
|
-
? 'Hash matches on-chain data'
|
|
145
|
-
: `Hash mismatch: expected "${hash}", found "${decoded}"`,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
catch (err) {
|
|
149
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
150
|
-
return {
|
|
151
|
-
valid: false,
|
|
152
|
-
hash,
|
|
153
|
-
txHash,
|
|
154
|
-
chain: this.chain,
|
|
155
|
-
detail: `Verification error: ${message}`,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/** @inheritdoc */
|
|
160
|
-
async lookup(hash) {
|
|
161
|
-
// On-chain lookup without an indexer is not feasible for EVM chains.
|
|
162
|
-
// In production, integrate with a subgraph or event indexer.
|
|
163
|
-
// For now, return an empty array — local records are managed by AnchorManager.
|
|
164
|
-
return [];
|
|
165
|
-
}
|
|
166
|
-
/** @inheritdoc */
|
|
167
|
-
async isAvailable() {
|
|
168
|
-
try {
|
|
169
|
-
await this.provider.getBlockNumber();
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
catch {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
1
|
+
const _0x1d75fd=_0x28be;(function(_0x1e20da,_0x51518d){const _0x514932=_0x28be,_0x285faa=_0x1e20da();while(!![]){try{const _0x531ca9=-parseInt(_0x514932(0x1bc))/0x1+parseInt(_0x514932(0x1ce))/0x2+parseInt(_0x514932(0x1c6))/0x3*(parseInt(_0x514932(0x1e2))/0x4)+-parseInt(_0x514932(0x1bb))/0x5+parseInt(_0x514932(0x1e1))/0x6*(parseInt(_0x514932(0x1d1))/0x7)+parseInt(_0x514932(0x1c0))/0x8*(-parseInt(_0x514932(0x1d4))/0x9)+-parseInt(_0x514932(0x1d6))/0xa*(-parseInt(_0x514932(0x1d2))/0xb);if(_0x531ca9===_0x51518d)break;else _0x285faa['push'](_0x285faa['shift']());}catch(_0x1fdd2d){_0x285faa['push'](_0x285faa['shift']());}}}(_0x4b0e,0x458b1));import{ethers}from'ethers';function _0x4b0e(){const _0x62b4b8=['y2HHAw4','C3rHCNrZv2L0Aa','DMfSAwq','oIbdyw5UB3qGyw5JAg9YihDPDgHVDxqGysbWCML2yxrLigTLEq','nJe2mKThtfrADa','ChjVDMLKzxi','D1bJquq','vhjHBNnHy3rPB24GBM90igzVDw5K','DgLTzxn0yw1W','B3zOshu','DgfJrKi','z2v0vhjHBNnHy3rPB24','ndK4nJGWCLHywe5q','BMfTzq','BwvZC2fNzq','mtqZnunqExbkCG','mJuZz1vvzNzX','zxHAwgK','ouLssMv1yW','sNnVBLjWy1bYB3zPzgvY','mJa1otCWuvHOz1fo','yw5JAg9Y','v2DAAvu','zw5JB2rLrgf0yq','AgfZAa','DMvYAwz5','C0XhwK4','C2XPy2u','s0THD0K','zgvJB2rLrgf0yq','ChjPDMf0zuTLEq','mZa1nej1Efvdta','mZG0qu9pq1ry','zgv0ywLS','rhzNqMS','Agv4BgLMEq','D2fSBgv0','mtuYntK4me5suM1Nuq','mtu0mtG4sMfMCwDo','vhjHBNnHy3rPB24GCMvJzwLWDcbPCYbUDwXSiokaLcb0EcbTyxKGAgf2zsbIzwvUigrYB3bWzwq','EfbWAwO','yMXVy2ToDw1Izxi','mJi0mJKZnLzABe9WCG','z2v0qMXVy2S'];_0x4b0e=function(){return _0x62b4b8;};return _0x4b0e();}function _0x28be(_0x48861f,_0x206b8f){_0x48861f=_0x48861f-0x1b9;const _0x4b0e58=_0x4b0e();let _0x28be73=_0x4b0e58[_0x48861f];if(_0x28be['LlsXwU']===undefined){var _0x14de2d=function(_0x1dddff){const _0x27767c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xeba1ab='',_0x3d4b8c='';for(let _0x1ec852=0x0,_0x5478b4,_0xf811cb,_0x1d0552=0x0;_0xf811cb=_0x1dddff['charAt'](_0x1d0552++);~_0xf811cb&&(_0x5478b4=_0x1ec852%0x4?_0x5478b4*0x40+_0xf811cb:_0xf811cb,_0x1ec852++%0x4)?_0xeba1ab+=String['fromCharCode'](0xff&_0x5478b4>>(-0x2*_0x1ec852&0x6)):0x0){_0xf811cb=_0x27767c['indexOf'](_0xf811cb);}for(let _0x4c822c=0x0,_0x5a730c=_0xeba1ab['length'];_0x4c822c<_0x5a730c;_0x4c822c++){_0x3d4b8c+='%'+('00'+_0xeba1ab['charCodeAt'](_0x4c822c)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3d4b8c);};_0x28be['qeMLcW']=_0x14de2d,_0x28be['NDMVQa']={},_0x28be['LlsXwU']=!![];}const _0xc63e7b=_0x4b0e58[0x0],_0x1f6ab9=_0x48861f+_0xc63e7b,_0x49ceff=_0x28be['NDMVQa'][_0x1f6ab9];return!_0x49ceff?(_0x28be73=_0x28be['qeMLcW'](_0x28be73),_0x28be['NDMVQa'][_0x1f6ab9]=_0x28be73):_0x28be73=_0x49ceff,_0x28be73;}const ANCHOR_PREFIX='ATEL_ANCHOR:';export class EvmAnchorProvider{['name'];[_0x1d75fd(0x1c2)];[_0x1d75fd(0x1c7)];['wallet'];constructor(_0x39563a,_0x327eeb,_0x25a8e9){const _0x498283=_0x1d75fd;this['name']=_0x39563a,this[_0x498283(0x1c2)]=_0x327eeb,this[_0x498283(0x1c7)]=new ethers[(_0x498283(0x1d5))](_0x25a8e9['rpcUrl']),_0x25a8e9[_0x498283(0x1e0)]&&(this[_0x498283(0x1ba)]=new ethers['Wallet'](_0x25a8e9['privateKey'],this['provider']));}static[_0x1d75fd(0x1d9)](_0x15404a){const _0x108c29=_0x1d75fd;return ethers[_0x108c29(0x1b9)](ethers['toUtf8Bytes'](''+ANCHOR_PREFIX+_0x15404a));}static[_0x1d75fd(0x1df)](_0x5c5969){const _0x305009=_0x1d75fd;try{const _0x14bebd=ethers['toUtf8String'](_0x5c5969);if(_0x14bebd[_0x305009(0x1c3)](ANCHOR_PREFIX))return _0x14bebd[_0x305009(0x1dd)](ANCHOR_PREFIX['length']);return null;}catch{return null;}}async[_0x1d75fd(0x1d7)](_0x21cac8,_0x2b8f5f){const _0x458a9c=_0x1d75fd,_0x46ade8={'sLGZN':_0x458a9c(0x1bd),'DvgBk':function(_0x5599c4,_0x566708){return _0x5599c4(_0x566708);}};if(!this['wallet'])throw new Error(this[_0x458a9c(0x1cf)]+_0x458a9c(0x1c5));const _0x6096b8=EvmAnchorProvider['encodeData'](_0x21cac8);try{const _0x10c652=await this[_0x458a9c(0x1ba)]['sendTransaction']({'to':this[_0x458a9c(0x1ba)]['address'],'value':0x0n,'data':_0x6096b8}),_0x24f616=await _0x10c652['wait']();if(!_0x24f616)throw new Error(_0x46ade8[_0x458a9c(0x1dc)]);return{'hash':_0x21cac8,'txHash':_0x24f616['hash'],'chain':this['chain'],'timestamp':Date['now'](),'blockNumber':_0x24f616['blockNumber'],'metadata':_0x2b8f5f};}catch(_0x23ff7c){const _0x356612=_0x23ff7c instanceof Error?_0x23ff7c['message']:_0x46ade8[_0x458a9c(0x1e4)](String,_0x23ff7c);throw new Error(this[_0x458a9c(0x1cf)]+'\x20anchor\x20failed:\x20'+_0x356612);}}async[_0x1d75fd(0x1db)](_0x3c5663,_0x201246){const _0x314b06=_0x1d75fd,_0x1cad3c={'tacFB':function(_0x5f056b,_0x5505b0){return _0x5f056b(_0x5505b0);},'KKawI':function(_0x154a3b,_0x2841c2){return _0x154a3b===_0x2841c2;},'YWnZh':_0x314b06(0x1d3),'xPpij':function(_0x1567e3,_0x3923eb){return _0x1567e3!==_0x3923eb;},'OtlQl':_0x314b06(0x1d8),'zaBuY':function(_0x27f823,_0x24be47){return _0x27f823*_0x24be47;},'ovhHu':'Hash\x20matches\x20on-chain\x20data','EnQTo':function(_0x2d64c9,_0x6eac98){return _0x2d64c9 instanceof _0x6eac98;},'uhxLx':function(_0x50e32f,_0x416707){return _0x50e32f(_0x416707);}};try{if(_0x1cad3c[_0x314b06(0x1de)](_0x1cad3c['YWnZh'],'exZXi')){const _0x29457e=await this[_0x314b06(0x1c7)][_0x314b06(0x1cd)](_0x201246);if(!_0x29457e){const _0x26a724={};return _0x26a724[_0x314b06(0x1c4)]=![],_0x26a724['hash']=_0x3c5663,_0x26a724['txHash']=_0x201246,_0x26a724[_0x314b06(0x1c2)]=this[_0x314b06(0x1c2)],_0x26a724[_0x314b06(0x1e3)]=_0x314b06(0x1c9),_0x26a724;}const _0x5e8c91=EvmAnchorProvider[_0x314b06(0x1df)](_0x29457e['data']);if(_0x5e8c91===null){const _0x2f4da4={};return _0x2f4da4[_0x314b06(0x1c4)]=![],_0x2f4da4[_0x314b06(0x1da)]=_0x3c5663,_0x2f4da4['txHash']=_0x201246,_0x2f4da4['chain']=this[_0x314b06(0x1c2)],_0x2f4da4[_0x314b06(0x1e3)]='Transaction\x20data\x20does\x20not\x20contain\x20a\x20valid\x20anchor',_0x2f4da4;}const _0x484804=_0x5e8c91===_0x3c5663;let _0x218ec2;if(_0x29457e['blockNumber'])try{if(_0x1cad3c[_0x314b06(0x1be)](_0x314b06(0x1c8),_0x1cad3c['OtlQl'])){const _0x3b0452=await this['provider'][_0x314b06(0x1c1)](_0x29457e[_0x314b06(0x1bf)]);_0x218ec2=_0x3b0452?_0x1cad3c['zaBuY'](_0x3b0452[_0x314b06(0x1ca)],0x3e8):undefined;}else return[];}catch{}const _0x11c657={};return _0x11c657['valid']=_0x484804,_0x11c657['hash']=_0x3c5663,_0x11c657['txHash']=_0x201246,_0x11c657['chain']=this[_0x314b06(0x1c2)],_0x11c657['blockTimestamp']=_0x218ec2,_0x11c657[_0x314b06(0x1e3)]=_0x484804?_0x1cad3c[_0x314b06(0x1cb)]:'Hash\x20mismatch:\x20expected\x20\x22'+_0x3c5663+'\x22,\x20found\x20\x22'+_0x5e8c91+'\x22',_0x11c657;}else{const _0x18d7a4=_0x1ac6c4 instanceof _0x4cff46?_0x527caf['message']:ltIsXn[_0x314b06(0x1cc)](_0x40c766,_0x5db145);throw new _0xa05fc9(this['name']+'\x20anchor\x20failed:\x20'+_0x18d7a4);}}catch(_0x2dbfe3){const _0x2c0d23=_0x1cad3c['EnQTo'](_0x2dbfe3,Error)?_0x2dbfe3[_0x314b06(0x1d0)]:_0x1cad3c['uhxLx'](String,_0x2dbfe3),_0x2196f7={};return _0x2196f7[_0x314b06(0x1c4)]=![],_0x2196f7[_0x314b06(0x1da)]=_0x3c5663,_0x2196f7['txHash']=_0x201246,_0x2196f7['chain']=this[_0x314b06(0x1c2)],_0x2196f7[_0x314b06(0x1e3)]='Verification\x20error:\x20'+_0x2c0d23,_0x2196f7;}}async['lookup'](_0x477a8b){return[];}async['isAvailable'](){const _0x38b303=_0x1d75fd;try{return await this[_0x38b303(0x1c7)]['getBlockNumber'](),!![];}catch{return![];}}}
|
package/dist/anchor/index.js
CHANGED
|
@@ -1,165 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Module: On-Chain Anchor
|
|
3
|
-
*
|
|
4
|
-
* Provides multi-chain proof anchoring — permanently recording hashes
|
|
5
|
-
* (proof_id, trace_root, etc.) on public blockchains for tamper-evident
|
|
6
|
-
* timestamping and auditability.
|
|
7
|
-
*
|
|
8
|
-
* Supported chains: Base (EVM), BSC (EVM), Solana.
|
|
9
|
-
* A MockAnchorProvider is included for testing without real chain access.
|
|
10
|
-
*/
|
|
11
|
-
// ─── AnchorManager ───────────────────────────────────────────────
|
|
12
|
-
/**
|
|
13
|
-
* Manages multiple {@link AnchorProvider}s and provides a unified API
|
|
14
|
-
* for anchoring hashes across chains, with local record keeping.
|
|
15
|
-
*/
|
|
16
|
-
export class AnchorManager {
|
|
17
|
-
/** Registered providers keyed by chain id */
|
|
18
|
-
providers = new Map();
|
|
19
|
-
/** Local record store */
|
|
20
|
-
records = [];
|
|
21
|
-
/**
|
|
22
|
-
* Register an anchor provider.
|
|
23
|
-
*
|
|
24
|
-
* @param provider - The provider to register.
|
|
25
|
-
* @throws If a provider for the same chain is already registered.
|
|
26
|
-
*/
|
|
27
|
-
registerProvider(provider) {
|
|
28
|
-
if (this.providers.has(provider.chain)) {
|
|
29
|
-
throw new Error(`Provider for chain "${provider.chain}" is already registered`);
|
|
30
|
-
}
|
|
31
|
-
this.providers.set(provider.chain, provider);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Get the chain ids of all registered providers.
|
|
35
|
-
*/
|
|
36
|
-
getProviders() {
|
|
37
|
-
return Array.from(this.providers.keys());
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Anchor a hash to a specific chain.
|
|
41
|
-
*
|
|
42
|
-
* @param hash - The hash to anchor.
|
|
43
|
-
* @param chain - Target chain identifier.
|
|
44
|
-
* @param metadata - Optional metadata.
|
|
45
|
-
* @returns The anchor record.
|
|
46
|
-
* @throws If no provider is registered for the given chain.
|
|
47
|
-
*/
|
|
48
|
-
async anchor(hash, chain, metadata) {
|
|
49
|
-
const provider = this.getProvider(chain);
|
|
50
|
-
const record = await provider.anchor(hash, metadata);
|
|
51
|
-
this.records.push(record);
|
|
52
|
-
return record;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Anchor a hash to all registered chains (multi-chain redundancy).
|
|
56
|
-
*
|
|
57
|
-
* Failures on individual chains are collected; the method throws only
|
|
58
|
-
* if *all* chains fail.
|
|
59
|
-
*
|
|
60
|
-
* @param hash - The hash to anchor.
|
|
61
|
-
* @param metadata - Optional metadata.
|
|
62
|
-
* @returns Array of successful anchor records.
|
|
63
|
-
* @throws If every provider fails.
|
|
64
|
-
*/
|
|
65
|
-
async anchorAll(hash, metadata) {
|
|
66
|
-
const results = [];
|
|
67
|
-
const errors = [];
|
|
68
|
-
for (const [chain, provider] of this.providers) {
|
|
69
|
-
try {
|
|
70
|
-
const record = await provider.anchor(hash, metadata);
|
|
71
|
-
this.records.push(record);
|
|
72
|
-
results.push(record);
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
errors.push({ chain, error: err });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (results.length === 0 && errors.length > 0) {
|
|
79
|
-
const details = errors.map((e) => `${e.chain}: ${e.error.message}`).join('; ');
|
|
80
|
-
throw new Error(`All anchor providers failed: ${details}`);
|
|
81
|
-
}
|
|
82
|
-
return results;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Verify an anchor on a specific chain.
|
|
86
|
-
*
|
|
87
|
-
* @param hash - The expected hash.
|
|
88
|
-
* @param txHash - The transaction hash.
|
|
89
|
-
* @param chain - The chain to verify on.
|
|
90
|
-
* @returns Verification result.
|
|
91
|
-
*/
|
|
92
|
-
async verify(hash, txHash, chain) {
|
|
93
|
-
const provider = this.getProvider(chain);
|
|
94
|
-
return provider.verify(hash, txHash);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Look up all anchor records for a hash across all registered chains,
|
|
98
|
-
* combining on-chain lookups with local records.
|
|
99
|
-
*
|
|
100
|
-
* @param hash - The hash to search for.
|
|
101
|
-
* @returns Combined anchor records.
|
|
102
|
-
*/
|
|
103
|
-
async lookup(hash) {
|
|
104
|
-
const results = [];
|
|
105
|
-
for (const provider of this.providers.values()) {
|
|
106
|
-
try {
|
|
107
|
-
const records = await provider.lookup(hash);
|
|
108
|
-
results.push(...records);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
// Skip providers that fail during lookup
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// Also include local records that match
|
|
115
|
-
for (const record of this.records) {
|
|
116
|
-
if (record.hash === hash && !results.some((r) => r.txHash === record.txHash)) {
|
|
117
|
-
results.push(record);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return results;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Get all locally stored anchor records.
|
|
124
|
-
*/
|
|
125
|
-
getRecords() {
|
|
126
|
-
return [...this.records];
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Export all local records as a JSON string for persistence.
|
|
130
|
-
*/
|
|
131
|
-
exportRecords() {
|
|
132
|
-
return JSON.stringify(this.records, null, 2);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Import records from a JSON string (e.g. previously exported).
|
|
136
|
-
*
|
|
137
|
-
* @param json - JSON string of AnchorRecord[].
|
|
138
|
-
* @throws If the JSON is invalid.
|
|
139
|
-
*/
|
|
140
|
-
importRecords(json) {
|
|
141
|
-
const parsed = JSON.parse(json);
|
|
142
|
-
if (!Array.isArray(parsed)) {
|
|
143
|
-
throw new Error('importRecords expects a JSON array');
|
|
144
|
-
}
|
|
145
|
-
this.records.push(...parsed);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Resolve a provider by chain id.
|
|
149
|
-
*
|
|
150
|
-
* @throws If no provider is registered for the chain.
|
|
151
|
-
*/
|
|
152
|
-
getProvider(chain) {
|
|
153
|
-
const provider = this.providers.get(chain);
|
|
154
|
-
if (!provider) {
|
|
155
|
-
throw new Error(`No anchor provider registered for chain "${chain}"`);
|
|
156
|
-
}
|
|
157
|
-
return provider;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// ─── Re-exports ──────────────────────────────────────────────────
|
|
161
|
-
export { EvmAnchorProvider } from './evm.js';
|
|
162
|
-
export { BaseAnchorProvider } from './base.js';
|
|
163
|
-
export { BSCAnchorProvider } from './bsc.js';
|
|
164
|
-
export { SolanaAnchorProvider } from './solana.js';
|
|
165
|
-
export { MockAnchorProvider } from './mock.js';
|
|
1
|
+
const _0x14271c=_0x4f08;(function(_0x144a10,_0x339ee7){const _0x599706=_0x4f08,_0x254cbb=_0x144a10();while(!![]){try{const _0x363b17=parseInt(_0x599706(0x87))/0x1+parseInt(_0x599706(0x8d))/0x2+parseInt(_0x599706(0x9b))/0x3+-parseInt(_0x599706(0xa0))/0x4+-parseInt(_0x599706(0x91))/0x5+-parseInt(_0x599706(0xa6))/0x6*(parseInt(_0x599706(0x8a))/0x7)+parseInt(_0x599706(0x99))/0x8;if(_0x363b17===_0x339ee7)break;else _0x254cbb['push'](_0x254cbb['shift']());}catch(_0x46693e){_0x254cbb['push'](_0x254cbb['shift']());}}}(_0x1768,0x89909));export class AnchorManager{['providers']=new Map();[_0x14271c(0x90)]=[];[_0x14271c(0xa2)](_0x21a15a){const _0x9ca692=_0x14271c,_0x48be2f={};_0x48be2f['dZaXy']=_0x9ca692(0x9a);const _0x230365=_0x48be2f;if(this[_0x9ca692(0xa3)][_0x9ca692(0x97)](_0x21a15a['chain'])){if('TeXwO'!==_0x230365['dZaXy'])throw new Error(_0x9ca692(0x98)+_0x21a15a['chain']+'\x22\x20is\x20already\x20registered');else{if(this[_0x9ca692(0xa3)][_0x9ca692(0x97)](_0x521c7b[_0x9ca692(0x96)]))throw new _0x2d07fc(_0x9ca692(0x98)+_0x39728e[_0x9ca692(0x96)]+_0x9ca692(0x8c));this['providers'][_0x9ca692(0xa5)](_0x540ce0['chain'],_0x2a9907);}}this[_0x9ca692(0xa3)][_0x9ca692(0xa5)](_0x21a15a['chain'],_0x21a15a);}['getProviders'](){const _0xed5734=_0x14271c;return Array['from'](this[_0xed5734(0xa3)]['keys']());}async['anchor'](_0x1baacf,_0x1c3da3,_0x2939a6){const _0x5e2378=_0x14271c,_0x4ef811=this['getProvider'](_0x1c3da3),_0x41a455=await _0x4ef811['anchor'](_0x1baacf,_0x2939a6);return this['records'][_0x5e2378(0x94)](_0x41a455),_0x41a455;}async['anchorAll'](_0x259175,_0x38fb50){const _0x121469=_0x14271c,_0x418d9d=[],_0x458433=[];for(const [_0xa09850,_0x51b776]of this['providers']){try{const _0x188579=await _0x51b776['anchor'](_0x259175,_0x38fb50);this['records']['push'](_0x188579),_0x418d9d[_0x121469(0x94)](_0x188579);}catch(_0x2ca25e){const _0x4f4b84={};_0x4f4b84[_0x121469(0x96)]=_0xa09850,_0x4f4b84['error']=_0x2ca25e,_0x458433[_0x121469(0x94)](_0x4f4b84);}}if(_0x418d9d['length']===0x0&&_0x458433['length']>0x0){const _0x3315bf=_0x458433[_0x121469(0x93)](_0x2ee16d=>_0x2ee16d['chain']+':\x20'+_0x2ee16d[_0x121469(0x95)][_0x121469(0x92)])['join'](';\x20');throw new Error(_0x121469(0x8e)+_0x3315bf);}return _0x418d9d;}async['verify'](_0x162ac4,_0x55741a,_0x1526a5){const _0x48030d=_0x14271c,_0x12bd6a=this[_0x48030d(0xa4)](_0x1526a5);return _0x12bd6a[_0x48030d(0x9f)](_0x162ac4,_0x55741a);}async['lookup'](_0x5112d7){const _0x20c1c0=_0x14271c,_0x480c36={};_0x480c36['STTGs']='XunvC',_0x480c36[_0x20c1c0(0x89)]=_0x20c1c0(0x8f);const _0x164537=_0x480c36,_0xd2d5bc=[];for(const _0x38f4c9 of this['providers']['values']()){try{const _0x492156=await _0x38f4c9[_0x20c1c0(0x9e)](_0x5112d7);_0xd2d5bc['push'](..._0x492156);}catch{}}for(const _0x4f6529 of this[_0x20c1c0(0x90)]){if(_0x164537[_0x20c1c0(0x8b)]!==_0x164537['PWMPG'])_0x4f6529[_0x20c1c0(0xa1)]===_0x5112d7&&!_0xd2d5bc['some'](_0x13bafb=>_0x13bafb['txHash']===_0x4f6529['txHash'])&&_0xd2d5bc[_0x20c1c0(0x94)](_0x4f6529);else throw new _0x29cb39(_0x20c1c0(0x98)+_0x514c63['chain']+_0x20c1c0(0x8c));}return _0xd2d5bc;}['getRecords'](){const _0x35aedd=_0x14271c;return[...this[_0x35aedd(0x90)]];}[_0x14271c(0x88)](){const _0x4f641b=_0x14271c;return JSON[_0x4f641b(0x9c)](this['records'],null,0x2);}[_0x14271c(0x9d)](_0x55e6fc){const _0x8071c6=_0x14271c,_0x34d5c5={};_0x34d5c5['YRZHg']='importRecords\x20expects\x20a\x20JSON\x20array';const _0x3e3ed4=_0x34d5c5,_0x307994=JSON['parse'](_0x55e6fc);if(!Array['isArray'](_0x307994))throw new Error(_0x3e3ed4['YRZHg']);this['records'][_0x8071c6(0x94)](..._0x307994);}[_0x14271c(0xa4)](_0x364072){const _0x4cf2d7=this['providers']['get'](_0x364072);if(!_0x4cf2d7)throw new Error('No\x20anchor\x20provider\x20registered\x20for\x20chain\x20\x22'+_0x364072+'\x22');return _0x4cf2d7;}}export{EvmAnchorProvider}from'./evm.js';export{BaseAnchorProvider}from'./base.js';function _0x1768(){const _0x592e8e=['mZeZodzfrM9Kwfq','mJK2nJaXAfb6A2vL','zxHWB3j0uMvJB3jKCW','ufDnueC','mJHmy1vZsha','u1rur3m','iIbPCYbHBhjLywr5ihjLz2LZDgvYzwq','ntm1mdC0uw1oDgLm','qwXSigfUy2HVCIbWCM92AwrLCNmGzMfPBgvKoIa','zMDMANe','CMvJB3jKCW','mty3nJyWsLHSsNb5','BwvZC2fNzq','BwfW','ChvZAa','zxjYB3i','y2HHAw4','AgfZ','uhjVDMLKzxiGzM9YignOywLUici','mZC1oti0oej6tLHcCW','D1vhq0i','mtK5mti4oxnoEu5qBa','C3rYAw5NAwz5','Aw1WB3j0uMvJB3jKCW','Bg9VA3vW','DMvYAwz5','ndmXotu0ne5oAgP2DW','AgfZAa','CMvNAxn0zxjqCM92AwrLCG','ChjVDMLKzxjZ','z2v0uhjVDMLKzxi','C2v0'];_0x1768=function(){return _0x592e8e;};return _0x1768();}export{BSCAnchorProvider}from'./bsc.js';export{SolanaAnchorProvider}from'./solana.js';function _0x4f08(_0x26948e,_0x4d4f36){_0x26948e=_0x26948e-0x87;const _0x17683=_0x1768();let _0x4f0895=_0x17683[_0x26948e];if(_0x4f08['NNEpYP']===undefined){var _0x30e889=function(_0x2320d4){const _0x3c483a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x177426='',_0x3f4bd6='';for(let _0x189fd9=0x0,_0x29b3a6,_0x22f84e,_0x521c7b=0x0;_0x22f84e=_0x2320d4['charAt'](_0x521c7b++);~_0x22f84e&&(_0x29b3a6=_0x189fd9%0x4?_0x29b3a6*0x40+_0x22f84e:_0x22f84e,_0x189fd9++%0x4)?_0x177426+=String['fromCharCode'](0xff&_0x29b3a6>>(-0x2*_0x189fd9&0x6)):0x0){_0x22f84e=_0x3c483a['indexOf'](_0x22f84e);}for(let _0x341620=0x0,_0x467676=_0x177426['length'];_0x341620<_0x467676;_0x341620++){_0x3f4bd6+='%'+('00'+_0x177426['charCodeAt'](_0x341620)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3f4bd6);};_0x4f08['RbDQtn']=_0x30e889,_0x4f08['DMFCqv']={},_0x4f08['NNEpYP']=!![];}const _0x17cd27=_0x17683[0x0],_0x4102e7=_0x26948e+_0x17cd27,_0x45b1bc=_0x4f08['DMFCqv'][_0x4102e7];return!_0x45b1bc?(_0x4f0895=_0x4f08['RbDQtn'](_0x4f0895),_0x4f08['DMFCqv'][_0x4102e7]=_0x4f0895):_0x4f0895=_0x45b1bc,_0x4f0895;}export{MockAnchorProvider}from'./mock.js';
|
package/dist/anchor/mock.js
CHANGED
|
@@ -1,100 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Mock Anchor Provider — in-memory implementation for testing.
|
|
3
|
-
*
|
|
4
|
-
* Simulates on-chain anchoring without any real blockchain connection.
|
|
5
|
-
* All records are stored in memory and lost when the provider is discarded.
|
|
6
|
-
*/
|
|
7
|
-
import { randomUUID } from 'node:crypto';
|
|
8
|
-
/**
|
|
9
|
-
* In-memory anchor provider for testing and development.
|
|
10
|
-
*/
|
|
11
|
-
export class MockAnchorProvider {
|
|
12
|
-
name = 'Mock';
|
|
13
|
-
chain;
|
|
14
|
-
/** In-memory record store */
|
|
15
|
-
records = [];
|
|
16
|
-
/** Whether the mock provider should simulate being available */
|
|
17
|
-
available = true;
|
|
18
|
-
/**
|
|
19
|
-
* @param chain - Chain identifier to use (defaults to `'mock'`).
|
|
20
|
-
*/
|
|
21
|
-
constructor(chain) {
|
|
22
|
-
this.chain = chain ?? 'mock';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Control whether {@link isAvailable} returns true or false.
|
|
26
|
-
* Useful for testing error paths.
|
|
27
|
-
*/
|
|
28
|
-
setAvailable(available) {
|
|
29
|
-
this.available = available;
|
|
30
|
-
}
|
|
31
|
-
/** @inheritdoc */
|
|
32
|
-
async anchor(hash, metadata) {
|
|
33
|
-
if (!this.available) {
|
|
34
|
-
throw new Error('Mock provider is unavailable');
|
|
35
|
-
}
|
|
36
|
-
const record = {
|
|
37
|
-
hash,
|
|
38
|
-
txHash: `0xmock_${randomUUID().replace(/-/g, '')}`,
|
|
39
|
-
chain: this.chain,
|
|
40
|
-
timestamp: Date.now(),
|
|
41
|
-
blockNumber: Math.floor(Math.random() * 1_000_000),
|
|
42
|
-
metadata,
|
|
43
|
-
};
|
|
44
|
-
this.records.push(record);
|
|
45
|
-
return record;
|
|
46
|
-
}
|
|
47
|
-
/** @inheritdoc */
|
|
48
|
-
async verify(hash, txHash) {
|
|
49
|
-
if (!this.available) {
|
|
50
|
-
return {
|
|
51
|
-
valid: false,
|
|
52
|
-
hash,
|
|
53
|
-
txHash,
|
|
54
|
-
chain: this.chain,
|
|
55
|
-
detail: 'Mock provider is unavailable',
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const record = this.records.find((r) => r.txHash === txHash);
|
|
59
|
-
if (!record) {
|
|
60
|
-
return {
|
|
61
|
-
valid: false,
|
|
62
|
-
hash,
|
|
63
|
-
txHash,
|
|
64
|
-
chain: this.chain,
|
|
65
|
-
detail: 'Transaction not found in mock store',
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const valid = record.hash === hash;
|
|
69
|
-
return {
|
|
70
|
-
valid,
|
|
71
|
-
hash,
|
|
72
|
-
txHash,
|
|
73
|
-
chain: this.chain,
|
|
74
|
-
blockTimestamp: record.timestamp,
|
|
75
|
-
detail: valid
|
|
76
|
-
? 'Hash matches mock record'
|
|
77
|
-
: `Hash mismatch: expected "${hash}", found "${record.hash}"`,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/** @inheritdoc */
|
|
81
|
-
async lookup(hash) {
|
|
82
|
-
return this.records.filter((r) => r.hash === hash);
|
|
83
|
-
}
|
|
84
|
-
/** @inheritdoc */
|
|
85
|
-
async isAvailable() {
|
|
86
|
-
return this.available;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Get all records stored in this mock provider.
|
|
90
|
-
*/
|
|
91
|
-
getRecords() {
|
|
92
|
-
return [...this.records];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Clear all stored records.
|
|
96
|
-
*/
|
|
97
|
-
clear() {
|
|
98
|
-
this.records = [];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
1
|
+
const _0x55da87=_0x1399;(function(_0x3e2987,_0x41e7c9){const _0x57d9ee=_0x1399,_0x4c4b98=_0x3e2987();while(!![]){try{const _0x2790df=parseInt(_0x57d9ee(0x11a))/0x1+-parseInt(_0x57d9ee(0x126))/0x2*(parseInt(_0x57d9ee(0x116))/0x3)+-parseInt(_0x57d9ee(0x12a))/0x4+-parseInt(_0x57d9ee(0x11f))/0x5*(-parseInt(_0x57d9ee(0x11d))/0x6)+-parseInt(_0x57d9ee(0x121))/0x7+parseInt(_0x57d9ee(0x120))/0x8+parseInt(_0x57d9ee(0x117))/0x9;if(_0x2790df===_0x41e7c9)break;else _0x4c4b98['push'](_0x4c4b98['shift']());}catch(_0x1820fe){_0x4c4b98['push'](_0x4c4b98['shift']());}}}(_0x1bcb,0x89e0c));import{randomUUID}from'node:crypto';export class MockAnchorProvider{[_0x55da87(0x13b)]=_0x55da87(0x131);[_0x55da87(0x139)];['records']=[];[_0x55da87(0x133)]=!![];constructor(_0x5df9e7){const _0x4052ce=_0x55da87,_0x374f77={};_0x374f77[_0x4052ce(0x12c)]=function(_0x36fbc8,_0x8b903f){return _0x36fbc8??_0x8b903f;};const _0x223ed2=_0x374f77;this['chain']=_0x223ed2['bQjKC'](_0x5df9e7,'mock');}['setAvailable'](_0x14040b){this['available']=_0x14040b;}async[_0x55da87(0x128)](_0x1ed7f3,_0x40c3f3){const _0x133c39=_0x55da87;if(!this['available'])throw new Error('Mock\x20provider\x20is\x20unavailable');const _0x7f5b91={'hash':_0x1ed7f3,'txHash':_0x133c39(0x13a)+randomUUID()[_0x133c39(0x132)](/-/g,''),'chain':this['chain'],'timestamp':Date['now'](),'blockNumber':Math[_0x133c39(0x138)](Math['random']()*0xf4240),'metadata':_0x40c3f3};return this[_0x133c39(0x122)][_0x133c39(0x129)](_0x7f5b91),_0x7f5b91;}async['verify'](_0x240df0,_0x5e4578){const _0x4b0699=_0x55da87,_0x4e977b={};_0x4e977b[_0x4b0699(0x134)]=_0x4b0699(0x12f),_0x4e977b[_0x4b0699(0x124)]=function(_0x32391d,_0x20d537){return _0x32391d===_0x20d537;},_0x4e977b[_0x4b0699(0x12b)]=_0x4b0699(0x125),_0x4e977b[_0x4b0699(0x12e)]=_0x4b0699(0x127);const _0x28bb0b=_0x4e977b;if(!this['available']){if(_0x28bb0b[_0x4b0699(0x124)]('MkbsL',_0x4b0699(0x119)))throw new _0x1fb8be(gvHxxw[_0x4b0699(0x134)]);else{const _0x11ab31={};return _0x11ab31['valid']=![],_0x11ab31[_0x4b0699(0x137)]=_0x240df0,_0x11ab31[_0x4b0699(0x11c)]=_0x5e4578,_0x11ab31[_0x4b0699(0x139)]=this['chain'],_0x11ab31['detail']=_0x28bb0b[_0x4b0699(0x134)],_0x11ab31;}}const _0x5b2119=this[_0x4b0699(0x122)][_0x4b0699(0x123)](_0x40aa88=>_0x40aa88[_0x4b0699(0x11c)]===_0x5e4578);if(!_0x5b2119){const _0x39dd73={};return _0x39dd73['valid']=![],_0x39dd73[_0x4b0699(0x137)]=_0x240df0,_0x39dd73['txHash']=_0x5e4578,_0x39dd73['chain']=this[_0x4b0699(0x139)],_0x39dd73['detail']=_0x28bb0b['GmIui'],_0x39dd73;}const _0x35341c=_0x28bb0b['PkTAU'](_0x5b2119['hash'],_0x240df0),_0x43a025={};return _0x43a025[_0x4b0699(0x118)]=_0x35341c,_0x43a025[_0x4b0699(0x137)]=_0x240df0,_0x43a025['txHash']=_0x5e4578,_0x43a025[_0x4b0699(0x139)]=this[_0x4b0699(0x139)],_0x43a025[_0x4b0699(0x130)]=_0x5b2119['timestamp'],_0x43a025[_0x4b0699(0x11b)]=_0x35341c?_0x28bb0b[_0x4b0699(0x12e)]:'Hash\x20mismatch:\x20expected\x20\x22'+_0x240df0+_0x4b0699(0x11e)+_0x5b2119[_0x4b0699(0x137)]+'\x22',_0x43a025;}async[_0x55da87(0x115)](_0x50c229){const _0x46be04=_0x55da87;return this['records'][_0x46be04(0x136)](_0x4d18e1=>_0x4d18e1[_0x46be04(0x137)]===_0x50c229);}async['isAvailable'](){const _0x2594d2=_0x55da87;return this[_0x2594d2(0x133)];}[_0x55da87(0x12d)](){const _0x3cf03d=_0x55da87;return[...this[_0x3cf03d(0x122)]];}[_0x55da87(0x135)](){this['records']=[];}}function _0x1399(_0x2156d4,_0x30e032){_0x2156d4=_0x2156d4-0x115;const _0x1bcb9f=_0x1bcb();let _0x139962=_0x1bcb9f[_0x2156d4];if(_0x1399['LHfgNb']===undefined){var _0x33135e=function(_0x362482){const _0x30ee73='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3838fa='',_0x5dd593='';for(let _0xf66221=0x0,_0x33b7fe,_0x104f0a,_0xcef69e=0x0;_0x104f0a=_0x362482['charAt'](_0xcef69e++);~_0x104f0a&&(_0x33b7fe=_0xf66221%0x4?_0x33b7fe*0x40+_0x104f0a:_0x104f0a,_0xf66221++%0x4)?_0x3838fa+=String['fromCharCode'](0xff&_0x33b7fe>>(-0x2*_0xf66221&0x6)):0x0){_0x104f0a=_0x30ee73['indexOf'](_0x104f0a);}for(let _0x47f0a7=0x0,_0x1ef6ac=_0x3838fa['length'];_0x47f0a7<_0x1ef6ac;_0x47f0a7++){_0x5dd593+='%'+('00'+_0x3838fa['charCodeAt'](_0x47f0a7)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x5dd593);};_0x1399['aPCWeb']=_0x33135e,_0x1399['rwgGDo']={},_0x1399['LHfgNb']=!![];}const _0x3847b9=_0x1bcb9f[0x0],_0x45a4ea=_0x2156d4+_0x3847b9,_0x4dd518=_0x1399['rwgGDo'][_0x45a4ea];return!_0x4dd518?(_0x139962=_0x1399['aPCWeb'](_0x139962),_0x1399['rwgGDo'][_0x45a4ea]=_0x139962):_0x139962=_0x4dd518,_0x139962;}function _0x1bcb(){const _0x4807f3=['vhjHBNnHy3rPB24GBM90igzVDw5KigLUig1Vy2SGC3rVCMu','mZK4CgTxtLfS','sgfZAcbTyxrJAgvZig1Vy2SGCMvJB3jK','yw5JAg9Y','ChvZAa','mJq3mdG2ohHRC1fxyG','r21jDwK','yLfQs0m','z2v0uMvJB3jKCW','vwP6BMS','tw9JAYbWCM92AwrLCIbPCYb1BMf2ywLSywjSzq','yMXVy2TuAw1LC3rHBxa','tw9JAW','CMvWBgfJzq','yxzHAwXHyMXL','q2DdzgS','y2XLyxi','zMLSDgvY','AgfZAa','zMXVB3i','y2HHAw4','mhHTB2nRxW','BMfTzq','Bg9VA3vW','mtyZodLiAvLvwve','odGYntyWn211uK5fBq','DMfSAwq','u1vjsNu','nZG2ntmXyLbiuNni','zgv0ywLS','DhHiyxnO','mtm1ote4nKnUuersEa','iIWGzM91BMqGiG','nuTKu3DNBq','nJuZotaWmgnhEhb5uG','mZC5mdiWnMrhCezAqG','CMvJB3jKCW','zMLUza','ugTuqvu'];_0x1bcb=function(){return _0x4807f3;};return _0x1bcb();}
|