Skip to content

Commit 9488bc0

Browse files
pradelaulneau
authored andcommitted
fix: fix lookupProfile throwing error for some BNS
1 parent 2b3d6d0 commit 9488bc0

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { getTokenFileUrl } from './index';
2+
3+
const ZONEFILE_CONTENT = {
4+
$origin: 'sigle.btc.',
5+
$ttl: 3600,
6+
uri: [
7+
{
8+
name: '@',
9+
target: '',
10+
priority: 10,
11+
weight: 1,
12+
},
13+
{
14+
name: '_http._tcp',
15+
target: 'https://gaia.blockstack.org/hub/15FF6jnJ1vV4fvo8LFPY1AK6dSbxMP6hkE/profile.json',
16+
priority: 10,
17+
weight: 1,
18+
},
19+
],
20+
};
21+
22+
describe('getTokenFileUrl tests', () => {
23+
it('should get token file url', async () => {
24+
expect(getTokenFileUrl(ZONEFILE_CONTENT)).toBe(ZONEFILE_CONTENT.uri[1].target);
25+
});
26+
});

packages/core/src/storage/common/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ export function getTokenFileUrl(zoneFileJson: any): string | null {
3838
if (zoneFileJson.uri.length < 1) {
3939
return null;
4040
}
41-
const firstUriRecord = zoneFileJson.uri[0];
4241

43-
if (!firstUriRecord.hasOwnProperty('target')) {
42+
const validRecords = zoneFileJson.uri.filter(
43+
(record: any) => record.hasOwnProperty('target') && record.name === '_http._tcp'
44+
);
45+
46+
if (validRecords.length < 1) {
47+
return null;
48+
}
49+
50+
const firstValidRecord = validRecords[0];
51+
52+
if (!firstValidRecord.hasOwnProperty('target')) {
4453
return null;
4554
}
46-
let tokenFileUrl = firstUriRecord.target;
55+
let tokenFileUrl = firstValidRecord.target;
4756

4857
if (tokenFileUrl.startsWith('https')) {
4958
// pass

0 commit comments

Comments
 (0)