enson.js
⚠️ This repo is under active development!
npm i @resolverworks/enson
✓
Record
import {Record} from '@resolverworks/enson';
let vitalik = Record.from({
name: 'Vitalik',
$eth: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
$btc: 'bc1pcm5cz7zqmc23ml65m628vrln0fja6hnhewmncya3x6n6rq7t7rdqhgqlvc',
avatar: 'eip155:1/erc1155:0xb32979486938aa9694bfc898f35dbed459f44424/10063',
'#ipfs': 'k2jmtxrxbr58aa3716vvr99qallufj3qae595op83p37jod4exujup32',
'#pubkey': {x: 1, y: 2},
'#name': 'vitalik.eth',
});
let name = vitalik.text('name');
let addr60 = vitalik.addr(60);
let hash = vitalik.contenthash();
let pubkey = vitalik.pubkey();
let name = vitalik.name();
vitalik.getAddress(60);
vitalik.getChash();
vitalik.getPubkey();
let calls = vitalik.makeSetters({name: 'vitalik.eth'});
let edit = Record.from(vitalik);
edit.delete('$btc');
edit.set('name', 'Vitamin');
edit.set('description', 'CEO of Ethereum');
let calls = edit.makeSetters({name: 'vitalik.eth', init: vitalik});
Profile
import {Record} from '@resolverworks/enson';
let profile0 = Profile.ENS();
let profile = Profile.from(vitalik);
let calls = profile.makeGetters({name: 'nick.eth'});
let answers = ...;
let nick = new Record();
nick.parseCalls(calls, answers);
Coin
import {Coin} from '@resolverworks/enson';
Coin.fromName('eth') === Coin.from({name: 'eth'}) === Coin.from('eth')
Coin.fromType(60) === Coin.from({type: 60}) === Coin.from(60)
Coin.fromChain(1) === Coin.from({chain: 1})
console.log(Coin.from('btc'));
console.log(Coin.fromChain(2));
console.log(Coin.from(69420));
Address
import {Address} from '@resolverworks/enson';
Address.from('0x51050ec063d393217B436747617aD1C2285Aeeee');
Address.from('btc', 'bc1q9ejpfyp7fvjdq5fjx5hhrd6uzevn9gupxd98aq');
Address.from(0, '0x00142e6414903e4b24d05132352f71b75c165932a381');
Chash
import {Chash} from '@resolverworks/enson';
let ipfs = Chash.from('0xe301017012201687de19f1516b9e560ab8655faa678e3a023ebff43494ac06a36581aafc957e');
ipfs.bytes;
ipfs.spec;
ipfs.toHash();
ipfs.toURL();
ipfs.toGatewayURL();
ipfs.toObject()
let onion = Chash.fromOnion('2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid');
onion.toObject();
onion.toURL();
let json = Chash.from({nice: 'chonk'}, 'json');
json.toObject();
json.toURL();
let file = Chash.from(readFileSync('chonk.mp4'), 'video/mp4');
Node
import {Node} from '@resolverworks/enson';
let node = Node.root();
node.create('vitalik.eth').record = vitalik;
node.find('raffy.eth').import({
name: 'Raffy',
$eth: '0x51050ec063d393217B436747617aD1C2285Aeeee'
});
root.find('eth').import({
'.': { name: 'Ether', $eth: '0x0000000000000000000000000000000000000000' },
slobo: { name: 'Alex', $eth: '0x0000000000000000000000000000000000000001' },
darian: { name: 'Darian', $eth: '0x0000000000000000000000000000000000000002' }
});
root.flat()
let rev = root.create('addr.reverse');
root.scan(node => {
let eth = node.record?.getAddress(60);
if (eth) {
rev.create(eth.toPhex().slice(2)).record = Record.from({
[Record.NAME]: node.name
});
}
});