Skip to content

Commit 422ff16

Browse files
committed
use bitauth for sha256 instead of crypto
1 parent 1909841 commit 422ff16

File tree

3 files changed

+49
-49
lines changed

3 files changed

+49
-49
lines changed

examples/get-records.ts

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,53 @@ import {
22
bitcannManager,
33
} from './common/setup.js';
44
import { parseRecords } from '../lib/util/parser.js';
5-
import { createHash } from 'crypto';
5+
import { binToHex, hexToBin, instantiateSha256 } from '@bitauth/libauth';
66

77
(async () =>
88
{
99
const name = 'satoshi';
1010
const records = await bitcannManager.getRecords({ name });
1111
console.log(records);
12-
})();
1312

1413

15-
const records = [
16-
'bio.name=Vikram Sarabhai',
17-
'bio.email.0=a@example.com',
18-
'bio.email.1=b@example.com',
19-
'bio.email.meta=type:array',
20-
'bio.description.0=Founder of ISRO.',
21-
'bio.description.1=Spearheaded India’s space program.',
22-
'bio.description.meta=type:text',
23-
'social.twitter=handle',
24-
'social.github=vikram123',
25-
'crypto.BCH.address=bitcoincash:qpm2qsznhks23z7629mms6s4cwef74abcdabdaabdc',
26-
`revoked=${createHash('sha256').update('bio.email.1=b@example.com')
27-
.digest('hex')}`,
28-
`revoked=${createHash('sha256').update('social.github=vikram123')
29-
.digest('hex')}`,
30-
`revoked=${createHash('sha256').update('bio.description.meta=type:text')
31-
.digest('hex')}`,
32-
'bio.name=Vikram Sarabhai',
33-
'bio.avatar=https://example.com/vikram.jpg',
34-
'bio.email=vikram@example.com',
35-
'bio.description.0=Founder of the Indian Space Research Organisation (ISRO).',
36-
'bio.description.1=Spearheaded India’s entry into the space age with the first satellite launch.',
37-
'bio.description.meta=type:text',
38-
`revoked=${createHash('sha256').update('bio.description.meta=type:text')
39-
.digest('hex')}`,
40-
`revoked=${createHash('sha256').update('bio.description.1=Spearheaded India’s entry into the space age with the first satellite launch.')
41-
.digest('hex')}`,
42-
'social.twitter=handle',
43-
'social.telegram=handle',
44-
'crypto.BCH.rpa=paycode:qygqyhh8kyxvda2rtatyh9dm0acvs89fgyhrpgplq0y6ac782cxhzaadq2l5tn8scc42kne6z6zfdx5t56ljkqsv9rg7thy0ffc42cdemyk82qqqqqqqq8cxkz4r',
45-
'crypto.BCH.address=bitcoincash:qpm2qsznhks23z7629mms6s4cwef74abcdabdaabdc',
46-
'crypto.USDT.version.ERC20.address=0xabcdef1234567890abcdef1234567890abcdef12',
47-
'token.EVM.ETH.address=0xabcdef1234567890abcdef1234567890abcdef12',
48-
'dns.a=192.168.1.1',
49-
'dns.aaaa=2606:2800:220:1:248:1893:25c8:194',
50-
'contract.fingerprint=0x1234567890abcdef1234567890abcdef12345678',
51-
'contract.params=1465077837 4 -789332029 e4',
52-
];
14+
const sha256 = await instantiateSha256();
15+
16+
const testRecords = [
17+
'bio.name=Vikram Sarabhai',
18+
'bio.email.0=a@example.com',
19+
'bio.email.1=b@example.com',
20+
'bio.email.meta=type:array',
21+
'bio.description.0=Founder of ISRO.',
22+
'bio.description.1=Spearheaded India’s space program.',
23+
'bio.description.meta=type:text',
24+
'social.twitter=handle',
25+
'social.github=vikram123',
26+
'crypto.BCH.address=bitcoincash:qpm2qsznhks23z7629mms6s4cwef74abcdabdaabdc',
27+
`revoked=${binToHex(sha256.hash(hexToBin('bio.email.1=b@example.com')))}`,
28+
`revoked=${binToHex(sha256.hash(hexToBin('social.github=vikram123')))}`,
29+
`revoked=${binToHex(sha256.hash(hexToBin('bio.description.meta=type:text')))}`,
30+
'bio.name=Vikram Sarabhai',
31+
'bio.avatar=https://example.com/vikram.jpg',
32+
'bio.email=vikram@example.com',
33+
'bio.description.0=Founder of the Indian Space Research Organisation (ISRO).',
34+
'bio.description.1=Spearheaded India’s entry into the space age with the first satellite launch.',
35+
'bio.description.meta=type:text',
36+
`revoked=${binToHex(sha256.hash(hexToBin('bio.description.meta=type:text')))}`,
37+
`revoked=${binToHex(sha256.hash(hexToBin('bio.description.1=Spearheaded India’s entry into the space age with the first satellite launch.')))}`,
38+
'social.twitter=handle',
39+
'social.telegram=handle',
40+
'crypto.BCH.rpa=paycode:qygqyhh8kyxvda2rtatyh9dm0acvs89fgyhrpgplq0y6ac782cxhzaadq2l5tn8scc42kne6z6zfdx5t56ljkqsv9rg7thy0ffc42cdemyk82qqqqqqqq8cxkz4r',
41+
'crypto.BCH.address=bitcoincash:qpm2qsznhks23z7629mms6s4cwef74abcdabdaabdc',
42+
'crypto.USDT.version.ERC20.address=0xabcdef1234567890abcdef1234567890abcdef12',
43+
'token.EVM.ETH.address=0xabcdef1234567890abcdef1234567890abcdef12',
44+
'dns.a=192.168.1.1',
45+
'dns.aaaa=2606:2800:220:1:248:1893:25c8:194',
46+
'contract.fingerprint=0x1234567890abcdef1234567890abcdef12345678',
47+
'contract.params=1465077837 4 -789332029 e4',
48+
];
49+
50+
51+
const parsed = await parseRecords(testRecords);
52+
console.log(JSON.stringify(parsed, null, 2));
53+
})();
5354

54-
const parsed = parseRecords(records);
55-
console.log(JSON.stringify(parsed, null, 2));

lib/util/parser.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createHash } from 'crypto';
1+
2+
import { binToHex, hexToBin, instantiateSha256 } from '@bitauth/libauth';
23

34
export interface ParsedRecordsInterface
45
{
@@ -7,8 +8,10 @@ export interface ParsedRecordsInterface
78
};
89
}
910

10-
export const parseRecords = (records: string[]): ParsedRecordsInterface =>
11+
export const parseRecords = async (records: string[]): Promise<ParsedRecordsInterface> =>
1112
{
13+
const sha256 = await instantiateSha256();
14+
1215
const result: ParsedRecordsInterface = {};
1316
const revocations = new Set<string>();
1417
const metaRecords: { [key: string]: { type: string } } = {};
@@ -44,8 +47,7 @@ export const parseRecords = (records: string[]): ParsedRecordsInterface =>
4447
continue;
4548
}
4649

47-
const hash = createHash('sha256').update(record)
48-
.digest('hex');
50+
const hash = binToHex(sha256.hash(hexToBin(record)));
4951
if(revocations.has(hash))
5052
{
5153
continue;
@@ -60,8 +62,7 @@ export const parseRecords = (records: string[]): ParsedRecordsInterface =>
6062
const metaType = metaRecords[`${namespace}.${baseSubKey}`]?.type;
6163
if(metaType)
6264
{
63-
const metaHash = createHash('sha256').update(`${metaKey}=type:${metaType}`)
64-
.digest('hex');
65+
const metaHash = binToHex(sha256.hash(hexToBin(`${metaKey}=type:${metaType}`)));
6566
if(revocations.has(metaHash))
6667
{
6768
continue;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitcann/core",
3-
"version": "0.0.11",
3+
"version": "0.0.12",
44
"description": "BitCANN - Bitcoin Cash for Assigned Names and Numbers is a decentralized domain name and identity system built on the Bitcoin Cash Blockchain.",
55
"type": "module",
66
"exports": {

0 commit comments

Comments
 (0)