@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.
Files changed (45) hide show
  1. package/dist/controller-types.d.ts +104 -0
  2. package/dist/controller-types.js +16 -0
  3. package/dist/core.d.ts +13 -10
  4. package/dist/core.js +144 -61
  5. package/dist/errors.d.ts +20 -0
  6. package/dist/errors.js +39 -0
  7. package/dist/index.d.ts +4 -0
  8. package/dist/index.js +4 -0
  9. package/dist/managed/index.d.ts +2 -9
  10. package/dist/managed/index.js +15 -5
  11. package/dist/managed/index.js.map +1 -1
  12. package/dist/managed/leaf.compact +39 -48
  13. package/dist/managed/managed/leaf/contract/{index.d.cts → index.d.ts} +55 -57
  14. package/dist/managed/managed/leaf/contract/index.js +2358 -0
  15. package/dist/managed/managed/leaf/contract/index.js.map +8 -0
  16. package/dist/operations.d.ts +78 -0
  17. package/dist/operations.js +421 -0
  18. package/dist/provider.d.ts +2 -3
  19. package/dist/provider.js +6 -7
  20. package/dist/react/DomainProfileWidget.d.ts +2 -2
  21. package/dist/react/DomainProfileWidget.js +6 -6
  22. package/dist/react/HolographicCard.d.ts +2 -2
  23. package/dist/react/HolographicCard.js +5 -5
  24. package/dist/results.d.ts +38 -0
  25. package/dist/results.js +88 -0
  26. package/dist/types.d.ts +2 -40
  27. package/dist/types.js +1 -61
  28. package/dist/utils/address.js +6 -5
  29. package/dist/utils/domain.d.ts +1 -0
  30. package/dist/utils/domain.js +1 -1
  31. package/dist/utils/imageResolver.d.ts +8 -0
  32. package/dist/utils/imageResolver.js +89 -0
  33. package/exported.md +7 -12
  34. package/managed/index.js +15 -5
  35. package/managed/index.js.map +1 -1
  36. package/managed/leaf.compact +39 -48
  37. package/managed/managed/leaf/contract/index.js +2358 -0
  38. package/managed/managed/leaf/contract/index.js.map +8 -0
  39. package/package.json +20 -10
  40. package/dist/managed/managed/leaf/contract/index.cjs +0 -2789
  41. package/dist/managed/managed/leaf/contract/index.cjs.map +0 -8
  42. package/managed/managed/leaf/contract/index.cjs +0 -2789
  43. package/managed/managed/leaf/contract/index.cjs.map +0 -8
  44. package/managed/managed/leaf/contract/index.d.cts +0 -146
  45. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,38 @@
1
+ import { MidnamesError } from "./errors.js";
2
+ export type Result<T, E = MidnamesError> = {
3
+ success: true;
4
+ data: T;
5
+ error?: never;
6
+ } | {
7
+ success: false;
8
+ data?: never;
9
+ error: E;
10
+ };
11
+ export declare function success<T, E = MidnamesError>(data: T): Result<T, E>;
12
+ export declare function failure<E = MidnamesError>(error: E): Result<never, E>;
13
+ export declare function match<T, E, U>(result: Result<T, E>, patterns: {
14
+ success: (data: T) => U;
15
+ error: (error: E) => U;
16
+ }): U;
17
+ export declare function map<T, U, E>(result: Result<T, E>, fn: (data: T) => U): Result<U, E>;
18
+ export declare function flatMap<T, U, E>(result: Result<T, E>, fn: (data: T) => Result<U, E>): Result<U, E>;
19
+ export declare function mapError<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
20
+ export declare function recover<T, E>(result: Result<T, E>, fn: (error: E) => T): Result<T, never>;
21
+ export declare function wrapAsync<T>(asyncFn: () => Promise<T>): Promise<Result<T>>;
22
+ export declare class ResultChain<T, E = MidnamesError> {
23
+ private result;
24
+ constructor(result: Result<T, E>);
25
+ map<U>(fn: (data: T) => U): ResultChain<U, E>;
26
+ flatMap<U>(fn: (data: T) => Result<U, E>): ResultChain<U, E>;
27
+ mapError<F>(fn: (error: E) => F): ResultChain<T, F>;
28
+ recover(fn: (error: E) => T): ResultChain<T, never>;
29
+ match<U>(patterns: {
30
+ success: (data: T) => U;
31
+ error: (error: E) => U;
32
+ }): U;
33
+ unwrap(): Result<T, E>;
34
+ }
35
+ export declare function chain<T, E = MidnamesError>(result: Result<T, E>): ResultChain<T, E>;
36
+ export declare function combine<T extends readonly unknown[], E>(results: {
37
+ [K in keyof T]: Result<T[K], E>;
38
+ }): Result<T, E>;
@@ -0,0 +1,88 @@
1
+ import { MidnamesError } from "./errors.js";
2
+ // Helper functions for Result type
3
+ export function success(data) {
4
+ return { success: true, data };
5
+ }
6
+ export function failure(error) {
7
+ return { success: false, error };
8
+ }
9
+ // Enhanced pattern matching for Results
10
+ export function match(result, patterns) {
11
+ if (result.success) {
12
+ return patterns.success(result.data);
13
+ }
14
+ else {
15
+ return patterns.error(result.error);
16
+ }
17
+ }
18
+ // Transform success value, keep error unchanged
19
+ export function map(result, fn) {
20
+ return result.success
21
+ ? success(fn(result.data))
22
+ : result;
23
+ }
24
+ // Chain operations that can fail
25
+ export function flatMap(result, fn) {
26
+ return result.success ? fn(result.data) : result;
27
+ }
28
+ // Transform error, keep success unchanged
29
+ export function mapError(result, fn) {
30
+ return result.success ? result : failure(fn(result.error));
31
+ }
32
+ // Recover from error with a fallback value
33
+ export function recover(result, fn) {
34
+ return result.success ? result : success(fn(result.error));
35
+ }
36
+ // Async result helpers
37
+ export async function wrapAsync(asyncFn) {
38
+ try {
39
+ const data = await asyncFn();
40
+ return success(data);
41
+ }
42
+ catch (error) {
43
+ if (error instanceof MidnamesError) {
44
+ return failure(error);
45
+ }
46
+ return failure(new MidnamesError(error instanceof Error ? error.message : String(error), "UNKNOWN_ERROR", error));
47
+ }
48
+ }
49
+ // Chainable Result class for fluent API
50
+ export class ResultChain {
51
+ constructor(result) {
52
+ this.result = result;
53
+ }
54
+ map(fn) {
55
+ return new ResultChain(map(this.result, fn));
56
+ }
57
+ flatMap(fn) {
58
+ return new ResultChain(flatMap(this.result, fn));
59
+ }
60
+ mapError(fn) {
61
+ return new ResultChain(mapError(this.result, fn));
62
+ }
63
+ recover(fn) {
64
+ return new ResultChain(recover(this.result, fn));
65
+ }
66
+ match(patterns) {
67
+ return match(this.result, patterns);
68
+ }
69
+ unwrap() {
70
+ return this.result;
71
+ }
72
+ }
73
+ // Helper function to start chain
74
+ export function chain(result) {
75
+ return new ResultChain(result);
76
+ }
77
+ // Combine multiple Results
78
+ export function combine(results) {
79
+ const data = [];
80
+ for (let i = 0; i < results.length; i++) {
81
+ const result = results[i];
82
+ if (!result.success) {
83
+ return result;
84
+ }
85
+ data[i] = result.data;
86
+ }
87
+ return success(data);
88
+ }
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export type { DomainData } from "../managed/index.js";
1
2
  export interface DomainInfo {
2
3
  owner: string;
3
4
  resolver: string;
@@ -11,45 +12,6 @@ export interface DomainProfileData {
11
12
  fullDomain: string;
12
13
  resolvedTarget: string | null;
13
14
  info: DomainInfo | null;
14
- fields: Array<[string, string]>;
15
+ fields: Map<string, string>;
15
16
  settings: DomainSettings | null;
16
17
  }
17
- export declare class MidNamesError extends Error {
18
- readonly code: string;
19
- readonly details?: unknown | undefined;
20
- constructor(message: string, code: string, details?: unknown | undefined);
21
- }
22
- export declare class NetworkError extends MidNamesError {
23
- constructor(message: string, details?: unknown);
24
- }
25
- export declare class ContractNotFoundError extends MidNamesError {
26
- constructor(contractAddress: string, details?: unknown);
27
- }
28
- export declare class DomainNotFoundError extends MidNamesError {
29
- constructor(domain: string, details?: unknown);
30
- }
31
- export declare class InvalidDomainError extends MidNamesError {
32
- constructor(domain: string, reason: string, details?: unknown);
33
- }
34
- export declare class ProviderError extends MidNamesError {
35
- constructor(message: string, details?: unknown);
36
- }
37
- export type Result<T, E = MidNamesError> = {
38
- success: true;
39
- data: T;
40
- } | {
41
- success: false;
42
- error: E;
43
- };
44
- export declare function success<T>(data: T): Result<T>;
45
- export declare function failure<E = MidNamesError>(error: E): Result<never, E>;
46
- export declare function isSuccess<T, E>(result: Result<T, E>): result is {
47
- success: true;
48
- data: T;
49
- };
50
- export declare function isError<T, E>(result: Result<T, E>): result is {
51
- success: false;
52
- error: E;
53
- };
54
- export declare function unwrap<T>(result: Result<T>): T;
55
- export declare function unwrapOr<T>(result: Result<T>, defaultValue: T): T;
package/dist/types.js CHANGED
@@ -1,61 +1 @@
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
- }
40
- // Helper functions for Result type
41
- export function success(data) {
42
- return { success: true, data };
43
- }
44
- export function failure(error) {
45
- return { success: false, error };
46
- }
47
- export function isSuccess(result) {
48
- return result.success;
49
- }
50
- export function isError(result) {
51
- return !result.success;
52
- }
53
- export function unwrap(result) {
54
- if (isSuccess(result)) {
55
- return result.data;
56
- }
57
- throw result.error;
58
- }
59
- export function unwrapOr(result, defaultValue) {
60
- return isSuccess(result) ? result.data : defaultValue;
61
- }
1
+ export {};
@@ -1,5 +1,5 @@
1
- import { MidnightBech32m, ShieldedCoinPublicKey, ShieldedAddress } from "@midnight-ntwrk/wallet-sdk-address-format";
2
- import { getZswapNetworkId } from "@midnight-ntwrk/midnight-js-network-id";
1
+ import { MidnightBech32m, ShieldedCoinPublicKey, ShieldedAddress, ShieldedEncryptionPublicKey } from "@midnight-ntwrk/wallet-sdk-address-format";
2
+ import { getNetworkId } from "@midnight-ntwrk/midnight-js-network-id";
3
3
  export function bytesToHex(bytes) {
4
4
  return Array.from(bytes).map((b) => b.toString(16).padStart(2, '0')).join('');
5
5
  }
@@ -11,12 +11,13 @@ export function deriveShieldedAddress(coinPublicKeyAddress, encryptionPublicKey)
11
11
  const cpkParsed = MidnightBech32m.parse(coinPublicKeyAddress);
12
12
  if (cpkParsed.type !== 'shield-cpk')
13
13
  return null;
14
- const coinPublicKey = ShieldedCoinPublicKey.codec.decode(getZswapNetworkId(), cpkParsed);
14
+ const coinPublicKey = ShieldedCoinPublicKey.codec.decode(getNetworkId(), cpkParsed);
15
15
  const epkParsed = MidnightBech32m.parse(encryptionPublicKey);
16
16
  if (epkParsed.type !== 'shield-epk')
17
17
  return null;
18
- const shieldedAddress = new ShieldedAddress(coinPublicKey, epkParsed);
19
- return ShieldedAddress.codec.encode(getZswapNetworkId(), shieldedAddress).asString();
18
+ const encPubKey = ShieldedEncryptionPublicKey.codec.decode(getNetworkId(), epkParsed);
19
+ const shieldedAddress = new ShieldedAddress(coinPublicKey, encPubKey);
20
+ return ShieldedAddress.codec.encode(getNetworkId(), shieldedAddress).asString();
20
21
  }
21
22
  catch {
22
23
  return null;
@@ -1,3 +1,4 @@
1
+ export declare const DEFAULT_TLD = "night";
1
2
  export declare function normalizeDomain(input: string, assumeTld?: boolean): string;
2
3
  export interface ParsedDomain {
3
4
  isValid: boolean;
@@ -1,4 +1,4 @@
1
- const DEFAULT_TLD = 'night';
1
+ export const DEFAULT_TLD = 'night';
2
2
  export function normalizeDomain(input, assumeTld = true) {
3
3
  const trimmedInput = input.trim().toLowerCase();
4
4
  const cleaned = trimmedInput.replace(/\.+/g, '.').replace(/\.$/, '');
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resolves a URL to an accessible HTTP(S) URL
3
+ * Handles IPFS URLs (ipfs://... and bare CIDs) by converting to gateway URLs
4
+ * Returns HTTP(S) URLs as-is
5
+ * @param url - The URL to resolve
6
+ * @returns Promise resolving to accessible URL
7
+ */
8
+ export declare function resolveImageUrl(url: string): Promise<string>;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Image resolution utilities for midnames-sdk
3
+ * Handles IPFS URLs and converts them to accessible HTTP(S) gateway URLs
4
+ */
5
+ const DEFAULT_IPFS_GATEWAYS = [
6
+ "https://ipfs.io/ipfs",
7
+ "https://4everland.io/ipfs",
8
+ "https://dweb.link/ipfs",
9
+ ];
10
+ /**
11
+ * Validates if a string is a valid IPFS CID
12
+ * @param cid - The string to validate
13
+ * @returns true if valid CID, false otherwise
14
+ */
15
+ function isValidIPFSCid(cid) {
16
+ if (!cid || cid.length < 10)
17
+ return false;
18
+ // Basic CIDv0 (Qm...) and CIDv1 (b...) validation
19
+ const cidv0Regex = /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/;
20
+ const cidv1Regex = /^b[A-Za-z2-7]{58}$/;
21
+ return cidv0Regex.test(cid) || cidv1Regex.test(cid);
22
+ }
23
+ /**
24
+ * Resolves an IPFS CID to an accessible gateway URL
25
+ * Tests multiple gateways concurrently and returns the first working one
26
+ * @param cid - The IPFS CID to resolve
27
+ * @returns Promise resolving to gateway URL
28
+ */
29
+ async function resolveIPFS(cid) {
30
+ return new Promise(async (resolve) => {
31
+ let resolved = false;
32
+ let successCount = 0;
33
+ let totalGateways = DEFAULT_IPFS_GATEWAYS.length;
34
+ // Test each gateway concurrently
35
+ DEFAULT_IPFS_GATEWAYS.forEach(async (gateway) => {
36
+ try {
37
+ const controller = new AbortController();
38
+ const timeoutId = setTimeout(() => controller.abort(), 3000);
39
+ const res = await fetch(`${gateway}/${cid}`, {
40
+ method: "HEAD",
41
+ signal: controller.signal,
42
+ });
43
+ clearTimeout(timeoutId);
44
+ if (res.ok && !resolved) {
45
+ resolved = true;
46
+ resolve(`${gateway}/${cid}`);
47
+ return;
48
+ }
49
+ }
50
+ catch (error) {
51
+ // Gateway failed, continue to next
52
+ }
53
+ successCount++;
54
+ // If all failed, use fallback
55
+ if (successCount === totalGateways && !resolved) {
56
+ resolved = true;
57
+ resolve(`${DEFAULT_IPFS_GATEWAYS[0]}/${cid}`);
58
+ }
59
+ });
60
+ });
61
+ }
62
+ /**
63
+ * Resolves a URL to an accessible HTTP(S) URL
64
+ * Handles IPFS URLs (ipfs://... and bare CIDs) by converting to gateway URLs
65
+ * Returns HTTP(S) URLs as-is
66
+ * @param url - The URL to resolve
67
+ * @returns Promise resolving to accessible URL
68
+ */
69
+ export async function resolveImageUrl(url) {
70
+ if (!url || !url.trim()) {
71
+ return "";
72
+ }
73
+ const trimmedUrl = url.trim();
74
+ // Return HTTP(S) URLs as-is
75
+ if (/^https?:\/\//i.test(trimmedUrl)) {
76
+ return trimmedUrl;
77
+ }
78
+ // Handle IPFS protocol URLs
79
+ if (trimmedUrl.startsWith("ipfs://")) {
80
+ const cid = trimmedUrl.replace("ipfs://", "");
81
+ return resolveIPFS(cid);
82
+ }
83
+ // Handle bare IPFS CIDs
84
+ if (isValidIPFSCid(trimmedUrl)) {
85
+ return resolveIPFS(trimmedUrl);
86
+ }
87
+ // For other protocols or invalid formats, return as-is
88
+ return trimmedUrl;
89
+ }
package/exported.md CHANGED
@@ -7,37 +7,32 @@ This document contains all exported functions, types, interfaces, classes, and c
7
7
  ### Core
8
8
 
9
9
  ```typescript
10
- export function resolveDomain(publicDataProvider: PublicDataProvider, domain: string, tldAddress?: string): Promise<Result<string>>
10
+ export function resolveDomain(domain: string, options?: { provider?: PublicDataProvider; tldAddress?: string }): Promise<Result<string>>
11
11
  ```
12
12
  Resolves a domain name to its target address.
13
13
 
14
14
  ```typescript
15
- export function getDomainInfo(publicDataProvider: PublicDataProvider, contractAddress: string, domainName: string): Promise<Result<DomainInfo>>
15
+ export function getDomainInfoInContract(contractAddress: string, domainName: string, options?: { provider?: PublicDataProvider }): Promise<Result<DomainInfo>>
16
16
  ```
17
17
  Gets information about a domain from a specific contract.
18
18
 
19
19
  ```typescript
20
- export function getDomainInfoByResolving(publicDataProvider: PublicDataProvider, fullDomain: string): Promise<Result<DomainInfo>>
20
+ export function getDomainInfo(fullDomain: string, options?: { provider?: PublicDataProvider }): Promise<Result<DomainInfo>>
21
21
  ```
22
22
  Gets domain information by resolving the full domain path.
23
23
 
24
24
  ```typescript
25
- export function getDomainFields(publicDataProvider: PublicDataProvider, contractAddress: string): Promise<Result<tuple[]>>
25
+ export function getDomainFields(contractAddress: string, options?: { provider?: PublicDataProvider }): Promise<Result<Array<[string, string]>>>
26
26
  ```
27
27
  Gets all fields stored in a domain contract.
28
28
 
29
29
  ```typescript
30
- export function getNamespacedDomainFields(publicDataProvider: PublicDataProvider, _parentContractAddress: string, fullDomainName: string): Promise<Result<tuple[]>>
31
- ```
32
- Gets fields for a domain by resolving its full namespace path.
33
-
34
- ```typescript
35
- export function getDomainSettings(publicDataProvider: PublicDataProvider, contractAddress: string): Promise<Result<DomainSettings>>
30
+ export function getDomainSettings(contractAddress: string, options?: { provider?: PublicDataProvider }): Promise<Result<DomainSettings>>
36
31
  ```
37
32
  Gets the settings (coin color, domain cost) for a domain contract.
38
33
 
39
34
  ```typescript
40
- export function getDomainProfile(publicDataProvider: PublicDataProvider, fullDomain: string): Promise<Result<DomainProfileData>>
35
+ export function getDomainProfile(fullDomain: string, options?: { provider?: PublicDataProvider }): Promise<Result<DomainProfileData>>
41
36
  ```
42
37
  Gets the complete profile data for a domain.
43
38
 
@@ -108,7 +103,7 @@ export type DomainProfileWidgetProps = {
108
103
  publicDataProvider: PublicDataProvider;
109
104
  className?: string;
110
105
  showStatus?: boolean;
111
- onError?: (error: MidNamesError) => void;
106
+ onError?: (error: MidnamesError) => void;
112
107
  }
113
108
 
114
109
  export function DomainProfileWidget(props: DomainProfileWidgetProps): JSX.Element
package/managed/index.js CHANGED
@@ -1,6 +1,16 @@
1
- export * as Leaf from "./managed/leaf/contract/index.cjs";
2
- import ContractModule from './managed/leaf/contract/index.cjs';
3
- export const ledger = ContractModule.ledger;
4
- export const pureCircuits = ContractModule.pureCircuits;
5
- export const { Contract } = ContractModule;
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":"AAcA,OAAO,KAAK,IAAI,MAAM,mCAAmC,CAAC;AAE1D,OAAO,cAAc,MAAM,mCAAmC,CAAC;AAG/D,MAAM,CAAC,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC;AAC5C,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,CAAC;AACxD,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC"}
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"}
@@ -1,6 +1,6 @@
1
- pragma language_version 0.17;
1
+ pragma language_version 0.20;
2
2
  /// # Unshielded Nameservice
3
- ///
3
+ ///
4
4
  /// Example:
5
5
  /// The `domain.mid` register would be deployed with
6
6
  /// - parent_domain: "mid"
@@ -20,8 +20,8 @@ pragma language_version 0.17;
20
20
  /// - target: arbitrary
21
21
  /// - domain: "hyper"
22
22
  /// - fields for the `hyper.sub.domain.mid` domain.
23
- ///
24
- ///
23
+ ///
24
+ ///
25
25
  import CompactStandardLibrary;
26
26
 
27
27
  // This is sealed. If the domain is sold in the parent contract
@@ -30,8 +30,8 @@ export sealed ledger PARENT_DOMAIN: Maybe<Opaque<'string'>>;
30
30
  export sealed ledger PARENT_RESOLVER: ContractAddress;
31
31
  export sealed ledger DOMAIN: Maybe<Opaque<'string'>>;
32
32
 
33
- export ledger DOMAIN_OWNER: ZswapCoinPublicKey;
34
- // This domain could target either a wallet or a contract
33
+ export ledger DOMAIN_OWNER: ZswapCoinPublicKey;
34
+ // This domain could target either a wallet or a contract
35
35
  export ledger DOMAIN_TARGET: Either<ZswapCoinPublicKey, ContractAddress>;
36
36
 
37
37
  // Map<domain, (owner, resolver)>.
@@ -43,7 +43,7 @@ export ledger domains_owned: Map<ZswapCoinPublicKey, Set<Opaque<'string'>>>;
43
43
  export ledger fields: Map<Opaque<'string'>, Opaque<'string'>>;
44
44
 
45
45
 
46
- export { DomainData, Either, Maybe, CoinInfo }
46
+ export { DomainData, Either, Maybe }
47
47
  struct DomainData {
48
48
  owner: ZswapCoinPublicKey,
49
49
  resolver: ContractAddress
@@ -54,9 +54,9 @@ constructor(
54
54
  parent_domain: Maybe<Opaque<'string'>>,
55
55
  parent_resolver: ContractAddress,
56
56
  target: Either<ZswapCoinPublicKey, ContractAddress>,
57
- domain: Maybe<Opaque<'string'>>,
57
+ domain: Maybe<Opaque<'string'>>,
58
58
  coin_color: Bytes<32>,
59
- domain_cost: Uint<64>,
59
+ domain_cost: Uint<128>,
60
60
  kvs: Vector<10, Maybe<[Opaque<'string'>, Opaque<'string'>]>>
61
61
  ) {
62
62
  DOMAIN_OWNER = ownPublicKey();
@@ -67,19 +67,18 @@ constructor(
67
67
  COIN_COLOR = disclose(coin_color);
68
68
  DOMAIN_COST = disclose(domain_cost);
69
69
  for (const kv of kvs) {
70
- if (disclose(kv) == none<[Opaque<'string'>, Opaque<'string'>]>()) {
71
- return;
70
+ if (disclose(kv) != none<[Opaque<'string'>, Opaque<'string'>]>()) {
71
+ fields.insert(disclose(kv.value[0]),disclose(kv.value[1]));
72
72
  }
73
- fields.insert(disclose(kv.value[0]),disclose(kv.value[1]));
74
73
  }
75
74
  }
76
75
 
77
- // ===========================================
78
- // Circuits
79
- // ===========================================
76
+ // ===========================================
77
+ // Circuits
78
+ // ===========================================
80
79
 
81
80
  export ledger COIN_COLOR: Bytes<32>;
82
- export ledger DOMAIN_COST: Uint<64>;
81
+ export ledger DOMAIN_COST: Uint<128>;
83
82
 
84
83
  export circuit update_color(c: Bytes<32>) : [] {
85
84
  assert(DOMAIN_OWNER == ownPublicKey(), "Not the owner");
@@ -92,39 +91,32 @@ export circuit update_cost(c: Uint<64>) : [] {
92
91
  }
93
92
 
94
93
  export circuit update_target_and_fields(
95
- new_target: Either<ZswapCoinPublicKey, ContractAddress>,
94
+ new_target: Either<ZswapCoinPublicKey, ContractAddress>,
96
95
  kvs: Vector<10, Maybe<[Opaque<'string'>, Opaque<'string'>]>>
97
96
  ) : [] {
98
97
  assert(DOMAIN_OWNER == ownPublicKey(), "Not the domain owner");
99
98
  for (const kv of kvs) {
100
- if (disclose(kv) == none<[Opaque<'string'>, Opaque<'string'>]>()) {
101
- return;
99
+ if (disclose(kv) != none<[Opaque<'string'>, Opaque<'string'>]>()) {
100
+ fields.insert(disclose(kv.value[0]),disclose(kv.value[1]));
102
101
  }
103
- fields.insert(disclose(kv.value[0]),disclose(kv.value[1]));
104
102
  }
105
103
  DOMAIN_TARGET = disclose(new_target);
106
104
 
107
105
  }
108
106
 
109
- export circuit buy_domain_for(owner: ZswapCoinPublicKey, domain: Opaque<'string'>, resolver: ContractAddress, payment: CoinInfo): [] {
107
+ export circuit buy_domain_for(owner: ZswapCoinPublicKey, domain: Opaque<'string'>, resolver: ContractAddress): [] {
110
108
  assert(!domains.member(disclose(domain)), "Domain already exists");
111
109
 
112
- const d_payment = disclose(payment);
113
- assert(d_payment.value == DOMAIN_COST, "Wrong amount");
114
- assert(d_payment.color == COIN_COLOR, "Wrong coin");
115
- receive(d_payment);
116
- sendImmediate(d_payment, left<ZswapCoinPublicKey, ContractAddress>(DOMAIN_OWNER), DOMAIN_COST);
117
-
118
- const d_owner = disclose(owner);
110
+ // receiveUnshielded(COIN_COLOR, DOMAIN_COST);
111
+ // sendUnshielded(COIN_COLOR, DOMAIN_COST, right<ContractAddress, UserAddress>(UserAddress { bytes: DOMAIN_OWNER.bytes }));
119
112
 
120
- const domain_data = DomainData {
113
+ const d_owner = disclose(owner);
114
+ const domain_data = DomainData {
121
115
  d_owner,
122
116
  disclose(resolver)
123
117
  };
124
-
125
- domains.insert(disclose(domain), disclose(domain_data));
126
-
127
- // Track domains owned by address
118
+ domains.insert(disclose(domain), disclose(domain_data));
119
+ // Track domains owned by address
128
120
  if (!domains_owned.member(d_owner)) {
129
121
  domains_owned.insert(d_owner, default<Set<Opaque<'string'>>>);
130
122
  }
@@ -134,10 +126,9 @@ export circuit buy_domain_for(owner: ZswapCoinPublicKey, domain: Opaque<'string'
134
126
  export circuit add_multiple_fields(kvs: Vector<10, Maybe<[Opaque<'string'>, Opaque<'string'>]>>) : [] {
135
127
  assert(DOMAIN_OWNER == ownPublicKey(), "Not the domain owner");
136
128
  for (const kv of kvs) {
137
- if (disclose(kv) == none<[Opaque<'string'>, Opaque<'string'>]>()) {
138
- return;
129
+ if (disclose(kv) != none<[Opaque<'string'>, Opaque<'string'>]>()) {
130
+ fields.insert(disclose(kv.value[0]),disclose(kv.value[1]));
139
131
  }
140
- fields.insert(disclose(kv.value[0]),disclose(kv.value[1]));
141
132
  }
142
133
  }
143
134
 
@@ -160,14 +151,14 @@ export circuit register_domain_for(owner: ZswapCoinPublicKey, domain: Opaque<'st
160
151
  assert(!domains.member(disclose(domain)), "Domain already exists");
161
152
  assert(DOMAIN_OWNER == ownPublicKey(), "Not the domain owner");
162
153
 
163
- const d_owner = disclose(owner);
154
+ const d_owner = disclose(owner);
164
155
  const domain_data = DomainData {
165
156
  d_owner,
166
157
  disclose(resolver)
167
158
  };
168
-
159
+
169
160
  domains.insert(disclose(domain), disclose(domain_data));
170
-
161
+
171
162
  // Track domains owned by address
172
163
  if (!domains_owned.member(d_owner)) {
173
164
  domains_owned.insert(d_owner, default<Set<Opaque<'string'>>>);
@@ -177,37 +168,37 @@ export circuit register_domain_for(owner: ZswapCoinPublicKey, domain: Opaque<'st
177
168
 
178
169
  export circuit set_resolver(domain: Opaque<'string'>, resolver: ContractAddress): [] {
179
170
  assert(domains.member(disclose(domain)), "Domain does not exist");
180
-
171
+
181
172
  const current_data = domains.lookup(disclose(domain));
182
173
  assert(current_data.owner == ownPublicKey(), "Not the domain owner");
183
-
174
+
184
175
  const new_data = DomainData {
185
176
  current_data.owner,
186
177
  disclose(resolver)
187
178
  };
188
-
179
+
189
180
  domains.insert(disclose(domain), disclose(new_data));
190
181
  }
191
182
 
192
183
  export circuit update_domain_target(new_target: Either<ZswapCoinPublicKey, ContractAddress>): [] {
193
184
  assert(DOMAIN_OWNER == ownPublicKey(), "Not the contract owner");
194
-
185
+
195
186
  DOMAIN_TARGET = disclose(new_target);
196
187
  }
197
188
 
198
189
  export circuit transfer_domain(domain: Opaque<'string'>, new_owner: ZswapCoinPublicKey): [] {
199
190
  assert(domains.member(disclose(domain)), "Domain does not exist");
200
-
191
+
201
192
  const current_data = domains.lookup(disclose(domain));
202
193
  assert(current_data.owner == ownPublicKey(), "Not the domain owner");
203
-
194
+
204
195
  const new_data = DomainData {
205
196
  disclose(new_owner),
206
197
  current_data.resolver
207
198
  };
208
-
199
+
209
200
  domains.insert(disclose(domain), disclose(new_data));
210
-
201
+
211
202
  // Update ownership tracking
212
203
  domains_owned.lookup(ownPublicKey()).remove(disclose(domain));
213
204
  if (!domains_owned.member(disclose(new_owner))) {
@@ -255,4 +246,4 @@ export circuit addr_owns_domain(addr: ZswapCoinPublicKey, domain: Opaque<'string
255
246
  return domains_owned.lookup(disclose(addr)).member(disclose(domain));
256
247
  }
257
248
 
258
- */
249
+ */