@midnames/sdk 0.2.0 → 1.0.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/controller-types.d.ts +104 -0
- package/dist/controller-types.js +16 -0
- package/dist/core.d.ts +13 -10
- package/dist/core.js +144 -61
- package/dist/errors.d.ts +20 -0
- package/dist/errors.js +39 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/managed/index.d.ts +2 -9
- package/dist/managed/index.js +15 -5
- package/dist/managed/index.js.map +1 -1
- package/dist/managed/leaf.compact +39 -48
- package/dist/managed/managed/leaf/contract/{index.d.cts → index.d.ts} +55 -57
- package/dist/managed/managed/leaf/contract/index.js +2358 -0
- package/dist/managed/managed/leaf/contract/index.js.map +8 -0
- package/dist/operations.d.ts +78 -0
- package/dist/operations.js +421 -0
- package/dist/provider.d.ts +2 -3
- package/dist/provider.js +6 -7
- package/dist/react/DomainProfileWidget.d.ts +2 -2
- package/dist/react/DomainProfileWidget.js +6 -6
- package/dist/react/HolographicCard.d.ts +2 -2
- package/dist/react/HolographicCard.js +5 -5
- package/dist/results.d.ts +38 -0
- package/dist/results.js +88 -0
- package/dist/types.d.ts +2 -40
- package/dist/types.js +1 -61
- package/dist/utils/address.js +6 -5
- package/dist/utils/domain.d.ts +1 -0
- package/dist/utils/domain.js +1 -1
- package/dist/utils/imageResolver.d.ts +8 -0
- package/dist/utils/imageResolver.js +89 -0
- package/exported.md +7 -12
- package/managed/index.js +15 -5
- package/managed/index.js.map +1 -1
- package/managed/leaf.compact +39 -48
- package/managed/managed/leaf/contract/index.js +2358 -0
- package/managed/managed/leaf/contract/index.js.map +8 -0
- package/package.json +20 -10
- package/dist/managed/managed/leaf/contract/index.cjs +0 -2789
- package/dist/managed/managed/leaf/contract/index.cjs.map +0 -8
- package/managed/managed/leaf/contract/index.cjs +0 -2789
- package/managed/managed/leaf/contract/index.cjs.map +0 -8
- package/managed/managed/leaf/contract/index.d.cts +0 -146
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controller Types for the Nameservice SDK
|
|
3
|
+
*
|
|
4
|
+
* These types define the interface for the LeafContractController
|
|
5
|
+
* which manages domain contract interactions with RxJS observable state.
|
|
6
|
+
*
|
|
7
|
+
* Note: The full LeafContractController implementation is in the frontend
|
|
8
|
+
* module at: modules/midnight/nameservice-sdk/api/leafContractController.ts
|
|
9
|
+
*/
|
|
10
|
+
import type { Observable, Subject } from 'rxjs';
|
|
11
|
+
/**
|
|
12
|
+
* Target address - domains can point to either a wallet (CoinPublicKey) or another contract
|
|
13
|
+
*/
|
|
14
|
+
export interface EitherTarget {
|
|
15
|
+
is_left: boolean;
|
|
16
|
+
left: {
|
|
17
|
+
bytes: Uint8Array;
|
|
18
|
+
};
|
|
19
|
+
right: {
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Subdomain data stored in the parent contract
|
|
25
|
+
*/
|
|
26
|
+
export interface SubdomainData {
|
|
27
|
+
owner: {
|
|
28
|
+
bytes: Uint8Array;
|
|
29
|
+
};
|
|
30
|
+
resolver: {
|
|
31
|
+
bytes: Uint8Array;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Observable state for a single domain contract
|
|
36
|
+
*/
|
|
37
|
+
export interface DomainState {
|
|
38
|
+
contractAddress: string;
|
|
39
|
+
target: EitherTarget;
|
|
40
|
+
fields: Map<string, string>;
|
|
41
|
+
subdomains: Map<string, SubdomainData>;
|
|
42
|
+
coinColor: Uint8Array;
|
|
43
|
+
domainCost: bigint;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Operation status for tracking async operations
|
|
47
|
+
*/
|
|
48
|
+
export type OperationStatus = {
|
|
49
|
+
type: 'idle';
|
|
50
|
+
} | {
|
|
51
|
+
type: 'proving';
|
|
52
|
+
message?: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'signing';
|
|
55
|
+
message?: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'submitting';
|
|
58
|
+
message?: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'complete';
|
|
61
|
+
txHash?: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'error';
|
|
64
|
+
error: Error;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Result of a transaction operation
|
|
68
|
+
*/
|
|
69
|
+
export interface TxResult {
|
|
70
|
+
txHash: string;
|
|
71
|
+
blockHeight?: bigint;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Derived state combining contract state with operation status
|
|
75
|
+
*/
|
|
76
|
+
export interface DerivedDomainState {
|
|
77
|
+
domain: DomainState | null;
|
|
78
|
+
operationStatus: OperationStatus;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Interface for the LeafContractController
|
|
82
|
+
*
|
|
83
|
+
* This interface defines the contract for managing domain operations.
|
|
84
|
+
* The implementation uses RxJS observables for reactive state updates.
|
|
85
|
+
*/
|
|
86
|
+
export interface LeafContractControllerInterface {
|
|
87
|
+
/** The contract address this controller is connected to */
|
|
88
|
+
readonly contractAddress: string;
|
|
89
|
+
/** Observable stream of domain state */
|
|
90
|
+
readonly state$: Observable<DerivedDomainState>;
|
|
91
|
+
/** Subject for operation status updates */
|
|
92
|
+
readonly operations$: Subject<OperationStatus>;
|
|
93
|
+
updateTarget(target: EitherTarget): Promise<TxResult>;
|
|
94
|
+
insertField(key: string, value: string): Promise<TxResult>;
|
|
95
|
+
clearField(key: string): Promise<TxResult>;
|
|
96
|
+
clearAllFields(): Promise<TxResult>;
|
|
97
|
+
addMultipleFields(kvs: Array<[string, string]>): Promise<TxResult>;
|
|
98
|
+
registerDomainFor(ownerCoinPublicKey: Uint8Array, domainName: string, resolverAddress: string): Promise<TxResult>;
|
|
99
|
+
transferDomain(domainName: string, newOwnerCoinPublicKey: Uint8Array): Promise<TxResult>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Empty initial state constant
|
|
103
|
+
*/
|
|
104
|
+
export declare const emptyDomainState: DerivedDomainState;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controller Types for the Nameservice SDK
|
|
3
|
+
*
|
|
4
|
+
* These types define the interface for the LeafContractController
|
|
5
|
+
* which manages domain contract interactions with RxJS observable state.
|
|
6
|
+
*
|
|
7
|
+
* Note: The full LeafContractController implementation is in the frontend
|
|
8
|
+
* module at: modules/midnight/nameservice-sdk/api/leafContractController.ts
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Empty initial state constant
|
|
12
|
+
*/
|
|
13
|
+
export const emptyDomainState = {
|
|
14
|
+
domain: null,
|
|
15
|
+
operationStatus: { type: 'idle' },
|
|
16
|
+
};
|
package/dist/core.d.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import type { PublicDataProvider } from
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import type { PublicDataProvider } from "@midnight-ntwrk/midnight-js-types";
|
|
2
|
+
import { type DomainData } from "../managed/index.js";
|
|
3
|
+
import type { DomainInfo, DomainSettings, DomainProfileData } from "./types.js";
|
|
4
|
+
import { Result } from "./results.js";
|
|
5
|
+
export declare const TESTNET_TLD_ADDRESS = "b00a62ce58c108b86af4670e662fa240844e0206c54009a539c64155d62e6b6a";
|
|
6
|
+
export declare function queryContractStateSafely(publicDataProvider: PublicDataProvider, contractAddress: string): Promise<Result<any>>;
|
|
4
7
|
export declare function resolveDomain(domain: string, options?: {
|
|
5
8
|
provider?: PublicDataProvider;
|
|
6
9
|
tldAddress?: string;
|
|
7
10
|
}): Promise<Result<string>>;
|
|
8
|
-
export declare function getDomainInfo(
|
|
11
|
+
export declare function getDomainInfo(fullDomain: string, options?: {
|
|
9
12
|
provider?: PublicDataProvider;
|
|
10
13
|
}): Promise<Result<DomainInfo>>;
|
|
11
|
-
export declare function
|
|
14
|
+
export declare function getDomainFields(fullDomain: string, options?: {
|
|
12
15
|
provider?: PublicDataProvider;
|
|
13
|
-
}): Promise<Result<
|
|
14
|
-
export declare function
|
|
15
|
-
provider?: PublicDataProvider;
|
|
16
|
-
}): Promise<Result<Array<[string, string]>>>;
|
|
17
|
-
export declare function getDomainSettings(contractAddress: string, options?: {
|
|
16
|
+
}): Promise<Result<Map<string, string>>>;
|
|
17
|
+
export declare function getDomainSettings(fullDomain: string, options?: {
|
|
18
18
|
provider?: PublicDataProvider;
|
|
19
19
|
}): Promise<Result<DomainSettings>>;
|
|
20
20
|
export declare function getDomainProfile(fullDomain: string, options?: {
|
|
21
21
|
provider?: PublicDataProvider;
|
|
22
22
|
}): Promise<Result<DomainProfileData>>;
|
|
23
|
+
export declare function getSubdomains(fullDomain: string, options?: {
|
|
24
|
+
provider?: PublicDataProvider;
|
|
25
|
+
}): Promise<Result<Map<string, DomainData>>>;
|
package/dist/core.js
CHANGED
|
@@ -1,47 +1,46 @@
|
|
|
1
|
-
import { getNetworkId
|
|
2
|
-
import { ShieldedCoinPublicKey } from
|
|
3
|
-
import { ledger } from
|
|
4
|
-
import { formatContractAddress } from
|
|
5
|
-
import { normalizeDomain, parseFullDomain } from
|
|
6
|
-
import { success, failure,
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
export const TESTNET_TLD_ADDRESS =
|
|
1
|
+
import { getNetworkId } from "@midnight-ntwrk/midnight-js-network-id";
|
|
2
|
+
import { ShieldedCoinPublicKey } from "@midnight-ntwrk/wallet-sdk-address-format";
|
|
3
|
+
import { ledger } from "./managed/index.js";
|
|
4
|
+
import { formatContractAddress, bytesToHex } from "./utils/address.js";
|
|
5
|
+
import { normalizeDomain, parseFullDomain, DEFAULT_TLD, isTLD } from "./utils/domain.js";
|
|
6
|
+
import { success, failure, wrapAsync } from "./results.js";
|
|
7
|
+
import { NetworkError, ContractNotFoundError, DomainNotFoundError, InvalidDomainError, } from "./errors.js";
|
|
8
|
+
import { getDefaultProvider } from "./provider.js";
|
|
9
|
+
export const TESTNET_TLD_ADDRESS = "b00a62ce58c108b86af4670e662fa240844e0206c54009a539c64155d62e6b6a";
|
|
10
10
|
function getDefaultTldAddress() {
|
|
11
11
|
const currentNetwork = getNetworkId();
|
|
12
12
|
switch (currentNetwork) {
|
|
13
|
-
case
|
|
13
|
+
case "preprod":
|
|
14
14
|
return TESTNET_TLD_ADDRESS;
|
|
15
15
|
default:
|
|
16
|
-
throw new Error(
|
|
16
|
+
throw new Error("Provide an address to use the resolver on a Standalone Network.");
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
function getTargetFromLedger(contractLedger) {
|
|
20
20
|
const target = contractLedger.DOMAIN_TARGET;
|
|
21
21
|
if (target.is_left) {
|
|
22
22
|
const coinPublicKey = new ShieldedCoinPublicKey(Buffer.from(target.left.bytes));
|
|
23
|
-
return ShieldedCoinPublicKey.codec
|
|
23
|
+
return ShieldedCoinPublicKey.codec
|
|
24
|
+
.encode(getNetworkId(), coinPublicKey)
|
|
25
|
+
.asString();
|
|
24
26
|
}
|
|
25
27
|
else {
|
|
26
28
|
return formatContractAddress(target.right.bytes);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
async function queryContractStateSafely(publicDataProvider, contractAddress) {
|
|
30
|
-
|
|
31
|
+
export async function queryContractStateSafely(publicDataProvider, contractAddress) {
|
|
32
|
+
return wrapAsync(async () => {
|
|
31
33
|
const contractState = await publicDataProvider.queryContractState(contractAddress);
|
|
32
34
|
if (contractState == null) {
|
|
33
|
-
|
|
35
|
+
throw new ContractNotFoundError(contractAddress, undefined);
|
|
34
36
|
}
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
return failure(new ProviderError(`Failed to query contract state: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
39
|
-
}
|
|
37
|
+
return contractState;
|
|
38
|
+
});
|
|
40
39
|
}
|
|
41
40
|
async function traverseDomainHierarchy(publicDataProvider, fullDomain, returnFinalTarget = false) {
|
|
42
41
|
try {
|
|
43
42
|
const tldAddress = getDefaultTldAddress();
|
|
44
|
-
const domainParts = fullDomain.split(
|
|
43
|
+
const domainParts = fullDomain.split(".");
|
|
45
44
|
const traversalParts = domainParts.slice(0, -1).reverse();
|
|
46
45
|
let currentResolver = tldAddress;
|
|
47
46
|
// If we're resolving the TLD itself and want the target
|
|
@@ -67,7 +66,8 @@ async function traverseDomainHierarchy(publicDataProvider, fullDomain, returnFin
|
|
|
67
66
|
}
|
|
68
67
|
const domainData = contractLedger.domains.lookup(part);
|
|
69
68
|
const resolverBytes = domainData.resolver.bytes;
|
|
70
|
-
|
|
69
|
+
// Use raw hex for queryContractState (no 0200 prefix)
|
|
70
|
+
currentResolver = bytesToHex(resolverBytes);
|
|
71
71
|
}
|
|
72
72
|
// Return either the final resolver address or the target it points to
|
|
73
73
|
if (returnFinalTarget) {
|
|
@@ -87,16 +87,22 @@ async function getResolverAddress(publicDataProvider, fullDomain) {
|
|
|
87
87
|
return traverseDomainHierarchy(publicDataProvider, fullDomain, false);
|
|
88
88
|
}
|
|
89
89
|
export async function resolveDomain(domain, options = {}) {
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (domainParts[domainParts.length - 1] !== TLD) {
|
|
95
|
-
return failure(new InvalidDomainError(fullDomain, `Domain must end with .${TLD}`));
|
|
90
|
+
// Simple validation
|
|
91
|
+
const normalized = normalizeDomain(domain);
|
|
92
|
+
if (!normalized.endsWith(`.${DEFAULT_TLD}`)) {
|
|
93
|
+
return failure(new InvalidDomainError(domain, "Domain must end with .night", undefined));
|
|
96
94
|
}
|
|
97
|
-
|
|
95
|
+
// Use the simple wrapper
|
|
96
|
+
return wrapAsync(async () => {
|
|
97
|
+
const result = await traverseDomainHierarchy(options.provider || getDefaultProvider(), normalized, true);
|
|
98
|
+
if (!result.success) {
|
|
99
|
+
throw result.error;
|
|
100
|
+
}
|
|
101
|
+
return result.data;
|
|
102
|
+
});
|
|
98
103
|
}
|
|
99
|
-
|
|
104
|
+
/** Looks up a subdomain's info (owner, resolver) within a specific parent contract. */
|
|
105
|
+
async function getDomainInfoInContract(contractAddress, domainName, options = {}) {
|
|
100
106
|
const publicDataProvider = options.provider || getDefaultProvider();
|
|
101
107
|
try {
|
|
102
108
|
const contractStateResult = await queryContractStateSafely(publicDataProvider, contractAddress);
|
|
@@ -108,57 +114,96 @@ export async function getDomainInfo(contractAddress, domainName, options = {}) {
|
|
|
108
114
|
}
|
|
109
115
|
const domainData = contractLedger.domains.lookup(domainName);
|
|
110
116
|
const ownerCoinPublicKey = new ShieldedCoinPublicKey(Buffer.from(domainData.owner.bytes));
|
|
111
|
-
const ownerAddress = ShieldedCoinPublicKey.codec
|
|
112
|
-
|
|
117
|
+
const ownerAddress = ShieldedCoinPublicKey.codec
|
|
118
|
+
.encode(getNetworkId(), ownerCoinPublicKey)
|
|
119
|
+
.asString();
|
|
120
|
+
return success({
|
|
121
|
+
owner: ownerAddress,
|
|
122
|
+
resolver: formatContractAddress(domainData.resolver.bytes),
|
|
123
|
+
});
|
|
113
124
|
}
|
|
114
125
|
catch (error) {
|
|
115
126
|
return failure(new NetworkError(`Failed to get domain info: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
116
127
|
}
|
|
117
128
|
}
|
|
118
|
-
export async function
|
|
129
|
+
export async function getDomainInfo(fullDomain, options = {}) {
|
|
119
130
|
const publicDataProvider = options.provider || getDefaultProvider();
|
|
120
131
|
try {
|
|
121
132
|
const normalizedDomain = normalizeDomain(fullDomain);
|
|
122
133
|
const parsed = parseFullDomain(normalizedDomain);
|
|
123
134
|
if (!parsed.isValid) {
|
|
124
|
-
return failure(new InvalidDomainError(fullDomain,
|
|
135
|
+
return failure(new InvalidDomainError(fullDomain, "Invalid domain format"));
|
|
125
136
|
}
|
|
126
137
|
const parentContractAddressResult = await getResolverAddress(publicDataProvider, parsed.parentDomainPath);
|
|
127
138
|
if (!parentContractAddressResult.success)
|
|
128
139
|
return failure(parentContractAddressResult.error);
|
|
129
|
-
const infoResult = await
|
|
140
|
+
const infoResult = await getDomainInfoInContract(parentContractAddressResult.data, parsed.domainName, { provider: publicDataProvider });
|
|
130
141
|
if (!infoResult.success)
|
|
131
142
|
return failure(infoResult.error);
|
|
132
|
-
return success({
|
|
143
|
+
return success({
|
|
144
|
+
...infoResult.data,
|
|
145
|
+
contractAddress: parentContractAddressResult.data,
|
|
146
|
+
});
|
|
133
147
|
}
|
|
134
148
|
catch (error) {
|
|
135
149
|
return failure(new NetworkError(`Failed to get domain info by resolving: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
136
150
|
}
|
|
137
151
|
}
|
|
138
|
-
|
|
152
|
+
async function readContractLedger(publicDataProvider, resolverAddress) {
|
|
153
|
+
const rawAddress = resolverAddress.startsWith('0200')
|
|
154
|
+
? resolverAddress.slice(4)
|
|
155
|
+
: resolverAddress;
|
|
156
|
+
const contractStateResult = await queryContractStateSafely(publicDataProvider, rawAddress);
|
|
157
|
+
if (!contractStateResult.success)
|
|
158
|
+
return failure(contractStateResult.error);
|
|
159
|
+
return success(ledger(contractStateResult.data.data));
|
|
160
|
+
}
|
|
161
|
+
export async function getDomainFields(fullDomain, options = {}) {
|
|
139
162
|
const publicDataProvider = options.provider || getDefaultProvider();
|
|
140
163
|
try {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
164
|
+
const normalized = normalizeDomain(fullDomain);
|
|
165
|
+
const infoResult = await getDomainInfo(normalized, { provider: publicDataProvider });
|
|
166
|
+
if (!infoResult.success)
|
|
167
|
+
return failure(infoResult.error);
|
|
168
|
+
const ledgerResult = await readContractLedger(publicDataProvider, infoResult.data.resolver);
|
|
169
|
+
if (!ledgerResult.success)
|
|
170
|
+
return failure(ledgerResult.error);
|
|
171
|
+
const fields = new Map();
|
|
172
|
+
for (const [key, value] of ledgerResult.data.fields)
|
|
173
|
+
fields.set(key, value);
|
|
148
174
|
return success(fields);
|
|
149
175
|
}
|
|
150
176
|
catch (error) {
|
|
151
177
|
return failure(new NetworkError(`Failed to get domain fields: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
152
178
|
}
|
|
153
179
|
}
|
|
154
|
-
export async function getDomainSettings(
|
|
180
|
+
export async function getDomainSettings(fullDomain, options = {}) {
|
|
155
181
|
const publicDataProvider = options.provider || getDefaultProvider();
|
|
156
182
|
try {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
183
|
+
const normalized = normalizeDomain(fullDomain, false);
|
|
184
|
+
// Special case: TLD itself — read settings directly from TLD contract
|
|
185
|
+
if (isTLD(normalized)) {
|
|
186
|
+
const tldAddress = getDefaultTldAddress();
|
|
187
|
+
const ledgerResult = await readContractLedger(publicDataProvider, tldAddress);
|
|
188
|
+
if (!ledgerResult.success)
|
|
189
|
+
return failure(ledgerResult.error);
|
|
190
|
+
return success({
|
|
191
|
+
coinColor: ledgerResult.data.COIN_COLOR,
|
|
192
|
+
domainCost: ledgerResult.data.DOMAIN_COST,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// Normal case: subdomain — resolve via getDomainInfo
|
|
196
|
+
const normalizedFull = normalizeDomain(fullDomain);
|
|
197
|
+
const infoResult = await getDomainInfo(normalizedFull, { provider: publicDataProvider });
|
|
198
|
+
if (!infoResult.success)
|
|
199
|
+
return failure(infoResult.error);
|
|
200
|
+
const ledgerResult = await readContractLedger(publicDataProvider, infoResult.data.resolver);
|
|
201
|
+
if (!ledgerResult.success)
|
|
202
|
+
return failure(ledgerResult.error);
|
|
203
|
+
return success({
|
|
204
|
+
coinColor: ledgerResult.data.COIN_COLOR,
|
|
205
|
+
domainCost: ledgerResult.data.DOMAIN_COST,
|
|
206
|
+
});
|
|
162
207
|
}
|
|
163
208
|
catch (error) {
|
|
164
209
|
return failure(new NetworkError(`Failed to get domain settings: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
@@ -170,22 +215,60 @@ export async function getDomainProfile(fullDomain, options = {}) {
|
|
|
170
215
|
const normalized = normalizeDomain(fullDomain);
|
|
171
216
|
const [resolvedTargetResult, infoResult] = await Promise.all([
|
|
172
217
|
resolveDomain(normalized, { provider: publicDataProvider }),
|
|
173
|
-
|
|
218
|
+
getDomainInfo(normalized, { provider: publicDataProvider }),
|
|
174
219
|
]);
|
|
175
|
-
const resolvedTarget = resolvedTargetResult.success
|
|
220
|
+
const resolvedTarget = resolvedTargetResult.success
|
|
221
|
+
? resolvedTargetResult.data
|
|
222
|
+
: null;
|
|
176
223
|
const info = infoResult.success ? infoResult.data : null;
|
|
177
|
-
if (info && info.
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
224
|
+
if (info && info.resolver) {
|
|
225
|
+
const ledgerResult = await readContractLedger(publicDataProvider, info.resolver);
|
|
226
|
+
if (ledgerResult.success) {
|
|
227
|
+
const fields = new Map();
|
|
228
|
+
for (const [key, value] of ledgerResult.data.fields)
|
|
229
|
+
fields.set(key, value);
|
|
230
|
+
const settings = {
|
|
231
|
+
coinColor: ledgerResult.data.COIN_COLOR,
|
|
232
|
+
domainCost: ledgerResult.data.DOMAIN_COST,
|
|
233
|
+
};
|
|
234
|
+
return success({
|
|
235
|
+
fullDomain: normalized,
|
|
236
|
+
resolvedTarget,
|
|
237
|
+
info,
|
|
238
|
+
fields,
|
|
239
|
+
settings,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
185
242
|
}
|
|
186
|
-
return success({
|
|
243
|
+
return success({
|
|
244
|
+
fullDomain: normalized,
|
|
245
|
+
resolvedTarget,
|
|
246
|
+
info,
|
|
247
|
+
fields: new Map(),
|
|
248
|
+
settings: null,
|
|
249
|
+
});
|
|
187
250
|
}
|
|
188
251
|
catch (error) {
|
|
189
252
|
return failure(new NetworkError(`Failed to get domain profile: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
190
253
|
}
|
|
191
254
|
}
|
|
255
|
+
export async function getSubdomains(fullDomain, options = {}) {
|
|
256
|
+
const publicDataProvider = options.provider || getDefaultProvider();
|
|
257
|
+
try {
|
|
258
|
+
const normalized = normalizeDomain(fullDomain);
|
|
259
|
+
const infoResult = await getDomainInfo(normalized, { provider: publicDataProvider });
|
|
260
|
+
if (!infoResult.success)
|
|
261
|
+
return failure(infoResult.error);
|
|
262
|
+
const ledgerResult = await readContractLedger(publicDataProvider, infoResult.data.resolver);
|
|
263
|
+
if (!ledgerResult.success)
|
|
264
|
+
return failure(ledgerResult.error);
|
|
265
|
+
const subdomains = new Map();
|
|
266
|
+
for (const [name, data] of ledgerResult.data.domains) {
|
|
267
|
+
subdomains.set(name, data);
|
|
268
|
+
}
|
|
269
|
+
return success(subdomains);
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
return failure(new NetworkError(`Failed to get subdomains: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
273
|
+
}
|
|
274
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class MidnamesError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly details?: unknown | undefined;
|
|
4
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
5
|
+
}
|
|
6
|
+
export declare class NetworkError extends MidnamesError {
|
|
7
|
+
constructor(message: string, details?: unknown);
|
|
8
|
+
}
|
|
9
|
+
export declare class ContractNotFoundError extends MidnamesError {
|
|
10
|
+
constructor(contractAddress: string, details?: unknown);
|
|
11
|
+
}
|
|
12
|
+
export declare class DomainNotFoundError extends MidnamesError {
|
|
13
|
+
constructor(domain: string, details?: unknown);
|
|
14
|
+
}
|
|
15
|
+
export declare class InvalidDomainError extends MidnamesError {
|
|
16
|
+
constructor(domain: string, reason: string, details?: unknown);
|
|
17
|
+
}
|
|
18
|
+
export declare class ProviderError extends MidnamesError {
|
|
19
|
+
constructor(message: string, details?: unknown);
|
|
20
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Error handling types
|
|
2
|
+
export class MidnamesError extends Error {
|
|
3
|
+
constructor(message, code, details) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.details = details;
|
|
7
|
+
this.name = 'MidnamesError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class NetworkError extends MidnamesError {
|
|
11
|
+
constructor(message, details) {
|
|
12
|
+
super(message, 'NETWORK_ERROR', details);
|
|
13
|
+
this.name = 'NetworkError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class ContractNotFoundError extends MidnamesError {
|
|
17
|
+
constructor(contractAddress, details) {
|
|
18
|
+
super(`Contract not found: ${contractAddress}`, 'CONTRACT_NOT_FOUND', details);
|
|
19
|
+
this.name = 'ContractNotFoundError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class DomainNotFoundError extends MidnamesError {
|
|
23
|
+
constructor(domain, details) {
|
|
24
|
+
super(`Domain not found: ${domain}`, 'DOMAIN_NOT_FOUND', details);
|
|
25
|
+
this.name = 'DomainNotFoundError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class InvalidDomainError extends MidnamesError {
|
|
29
|
+
constructor(domain, reason, details) {
|
|
30
|
+
super(`Invalid domain "${domain}": ${reason}`, 'INVALID_DOMAIN', details);
|
|
31
|
+
this.name = 'InvalidDomainError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class ProviderError extends MidnamesError {
|
|
35
|
+
constructor(message, details) {
|
|
36
|
+
super(message, 'PROVIDER_ERROR', details);
|
|
37
|
+
this.name = 'ProviderError';
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,7 @@ export * from './utils/domain.js';
|
|
|
3
3
|
export * from './utils/address.js';
|
|
4
4
|
export * from './core.js';
|
|
5
5
|
export * from './provider.js';
|
|
6
|
+
export * from './operations.js';
|
|
7
|
+
export * from './results.js';
|
|
8
|
+
export * from './errors.js';
|
|
9
|
+
export * from './controller-types.js';
|
package/dist/index.js
CHANGED
|
@@ -3,3 +3,7 @@ export * from './utils/domain.js';
|
|
|
3
3
|
export * from './utils/address.js';
|
|
4
4
|
export * from './core.js';
|
|
5
5
|
export * from './provider.js';
|
|
6
|
+
export * from './operations.js';
|
|
7
|
+
export * from './results.js';
|
|
8
|
+
export * from './errors.js';
|
|
9
|
+
export * from './controller-types.js';
|
package/dist/managed/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
import ContractModule from './managed/leaf/contract/index.cjs';
|
|
4
|
-
import type { Contract as ContractType, Witnesses } from './managed/leaf/contract/index.cjs';
|
|
5
|
-
export declare const ledger: typeof ContractModule.ledger;
|
|
6
|
-
export declare const pureCircuits: ContractModule.PureCircuits;
|
|
7
|
-
export declare const Contract: typeof ContractModule.Contract;
|
|
8
|
-
export type Contract<T, W extends Witnesses<T> = Witnesses<T>> = ContractType<T, W>;
|
|
9
|
-
export type Ledger = ContractModule.Ledger;
|
|
1
|
+
export * as Leaf from "./managed/leaf/contract";
|
|
2
|
+
export { type DomainData, type Either, type Maybe, type Witnesses, type Ledger, ledger, Contract } from "./managed/leaf/contract";
|
package/dist/managed/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
export * as
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
/* export * as Registry from "./managed/registry/contract/index.cjs";
|
|
2
|
+
export * as Resolver from "./managed/resolver/contract/index.cjs";
|
|
3
|
+
export * as UnifiedDomain from "./managed/unified-domain/contract/index.cjs";
|
|
4
|
+
export * as NS from "./managed/ns/contract/index.cjs";
|
|
5
|
+
export * from "./witnesses.js";
|
|
6
|
+
export { type RegistryRecord } from "./managed/registry/contract/index.cjs";
|
|
7
|
+
export { type ResolutionData } from "./managed/resolver/contract/index.cjs";
|
|
8
|
+
export { type DomainData as UnifiedDomainData } from "./managed/unified-domain/contract/index.cjs";
|
|
9
|
+
export {
|
|
10
|
+
type DomainData,
|
|
11
|
+
type DomainReference,
|
|
12
|
+
} from "./managed/ns/contract/index.cjs";
|
|
13
|
+
*/
|
|
14
|
+
export * as Leaf from "./managed/leaf/contract/index.js";
|
|
15
|
+
export { ledger, Contract } from "./managed/leaf/contract/index.js";
|
|
6
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,IAAI,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAML,MAAM,EACN,QAAQ,EACT,MAAM,yBAAyB,CAAC"}
|