Skip to content

Commit

Permalink
feat(hedera): added support for hedera network by krypc team (#4)
Browse files Browse the repository at this point in the history
* Added support for Hedera network.

* feat(hedera): added support for hedera network

we have added mainnet and testnet hedera network configurations.

---------

Co-authored-by: piruthivi2 <piruthivi@techbreakthrough.co.in>
  • Loading branch information
piruthivi3232 and piruthivi2 committed Dec 6, 2023
1 parent b33bf37 commit b14e3eb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
15 changes: 15 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,18 @@ describe("queryDns", () => {
}
});
});

describe("getDocumentStoreRecords for Hedera", () => {
const sampleDnsTextRecord = {
type: "openatts",
net: "hedera",
netId: "296",
dnssec: false,
addr: "0x3498b8e0A00fC8c3a1f64647AC85EEE8E1baF953",
};

test("it should work with trustlv.org", async () => {
const records = await getDocumentStoreRecords("trustlv.org");
expect(records).toStrictEqual([sampleDnsTextRecord]);
});
});
35 changes: 25 additions & 10 deletions src/records/dnsTxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { Static, Boolean, String, Literal, Record, Union, Partial } from "runtyp

export const RecordTypesT = Literal("openatts");

export const BlockchainNetworkT = Literal("ethereum");
// export const BlockchainNetworkT = Literal("ethereum");
export const BlockchainNetworkT = Union(Literal("ethereum"), Literal("hedera"));

export const EthereumAddressT = String.withConstraint((maybeAddress: string) => {
return /0x[a-fA-F0-9]{40}/.test(maybeAddress) || `${maybeAddress} is not a valid ethereum address`;
});

export const HederaAccountIDT = String.withConstraint((maybeAddress: string) => {
return /0x[a-fA-F0-9]{40}/.test(maybeAddress) || `${maybeAddress} is not a valid hedera address`;
});

export enum EthereumNetworks {
homestead = "1",
ropsten = "3",
Expand All @@ -21,6 +26,12 @@ export enum EthereumNetworks {
xdcapothem = "51",
}

export enum HederaNetworks {
mainnet = "295",
testnet = "296",
}
export const HederaNetworkIdT = Union(Literal(HederaNetworks.mainnet), Literal(HederaNetworks.testnet));

export const EthereumNetworkIdT = Union(
Literal(EthereumNetworks.homestead),
Literal(EthereumNetworks.ropsten),
Expand All @@ -34,15 +45,19 @@ export const EthereumNetworkIdT = Union(
Literal(EthereumNetworks.local)
);

export const OpenAttestationDNSTextRecordT = Record({
type: RecordTypesT,
net: BlockchainNetworkT, // key names are directly lifted from the dns-txt record format
netId: EthereumNetworkIdT, // they are abbreviated because of 255 char constraint on dns-txt records
addr: EthereumAddressT,
}).And(
Partial({
dnssec: Boolean,
})
export const OpenAttestationDNSTextRecordT = Union(
Record({
type: RecordTypesT,
net: Literal("ethereum"),
netId: EthereumNetworkIdT,
addr: EthereumAddressT,
}).And(Partial({ dnssec: Boolean })),
Record({
type: RecordTypesT,
net: Literal("hedera"),
netId: HederaNetworkIdT,
addr: HederaAccountIDT,
}).And(Partial({ dnssec: Boolean }))
);

export type BlockchainNetwork = Static<typeof BlockchainNetworkT>;
Expand Down

0 comments on commit b14e3eb

Please sign in to comment.