@coinbase/cdp-hooks 0.0.61 → 0.0.63

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.
@@ -1,5 +1,5 @@
1
1
  import { stringToBytes as i } from "./index122.js";
2
- import { encodeLabelhash as h } from "./index265.js";
2
+ import { encodeLabelhash as h } from "./index264.js";
3
3
  import { labelhash as f } from "./index121.js";
4
4
  function y(s) {
5
5
  const o = s.replace(/^\.|\.$/gm, "");
@@ -1,4 +1,4 @@
1
- import { parseAvatarUri as o, parseNftUri as f, getNftTokenUri as v, resolveAvatarUri as l, getJsonImage as A, getMetadataAvatarUri as N } from "./index264.js";
1
+ import { parseAvatarUri as o, parseNftUri as f, getNftTokenUri as v, resolveAvatarUri as l, getJsonImage as A, getMetadataAvatarUri as N } from "./index265.js";
2
2
  async function b(r, { gatewayUrls: t, record: e }) {
3
3
  return /eip155:/i.test(e) ? U(r, { gatewayUrls: t, record: e }) : o({ uri: e, gatewayUrls: t });
4
4
  }
@@ -1,139 +1,6 @@
1
- import { readContract as w } from "./index69.js";
2
- import { EnsAvatarUriResolutionError as d, EnsAvatarInvalidNftUriError as p, EnsAvatarUnsupportedNamespaceError as I, EnsAvatarInvalidMetadataError as y } from "./index113.js";
3
- const v = /(?<protocol>https?:\/\/[^\/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/, A = /^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(?<target>[\w\-.]+))?(?<subtarget>\/.*)?$/, b = /^data:([a-zA-Z\-/+]*);base64,([^"].*)/, E = /^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;
4
- async function k(e) {
5
- try {
6
- const t = await fetch(e, { method: "HEAD" });
7
- return t.status === 200 ? t.headers.get("content-type")?.startsWith("image/") : !1;
8
- } catch (t) {
9
- return typeof t == "object" && typeof t.response < "u" || !globalThis.hasOwnProperty("Image") ? !1 : new Promise((n) => {
10
- const a = new Image();
11
- a.onload = () => {
12
- n(!0);
13
- }, a.onerror = () => {
14
- n(!1);
15
- }, a.src = e;
16
- });
17
- }
18
- }
19
- function l(e, t) {
20
- return e ? e.endsWith("/") ? e.slice(0, -1) : e : t;
21
- }
22
- function C({ uri: e, gatewayUrls: t }) {
23
- const n = b.test(e);
24
- if (n)
25
- return { uri: e, isOnChain: !0, isEncoded: n };
26
- const a = l(t?.ipfs, "https://ipfs.io"), r = l(t?.arweave, "https://arweave.net"), f = e.match(v), { protocol: i, subpath: c, target: s, subtarget: h = "" } = f?.groups || {}, u = i === "ipns:/" || c === "ipns/", m = i === "ipfs:/" || c === "ipfs/" || A.test(e);
27
- if (e.startsWith("http") && !u && !m) {
28
- let g = e;
29
- return t?.arweave && (g = e.replace(/https:\/\/arweave.net/g, t?.arweave)), { uri: g, isOnChain: !1, isEncoded: !1 };
30
- }
31
- if ((u || m) && s)
32
- return {
33
- uri: `${a}/${u ? "ipns" : "ipfs"}/${s}${h}`,
34
- isOnChain: !1,
35
- isEncoded: !1
36
- };
37
- if (i === "ar:/" && s)
38
- return {
39
- uri: `${r}/${s}${h || ""}`,
40
- isOnChain: !1,
41
- isEncoded: !1
42
- };
43
- let o = e.replace(E, "");
44
- if (o.startsWith("<svg") && (o = `data:image/svg+xml;base64,${btoa(o)}`), o.startsWith("data:") || o.startsWith("{"))
45
- return {
46
- uri: o,
47
- isOnChain: !0,
48
- isEncoded: !1
49
- };
50
- throw new d({ uri: e });
51
- }
52
- function U(e) {
53
- if (typeof e != "object" || !("image" in e) && !("image_url" in e) && !("image_data" in e))
54
- throw new y({ data: e });
55
- return e.image || e.image_url || e.image_data;
56
- }
57
- async function $({ gatewayUrls: e, uri: t }) {
58
- try {
59
- const n = await fetch(t).then((r) => r.json());
60
- return await R({
61
- gatewayUrls: e,
62
- uri: U(n)
63
- });
64
- } catch {
65
- throw new d({ uri: t });
66
- }
67
- }
68
- async function R({ gatewayUrls: e, uri: t }) {
69
- const { uri: n, isOnChain: a } = C({ uri: t, gatewayUrls: e });
70
- if (a || await k(n))
71
- return n;
72
- throw new d({ uri: t });
73
- }
74
- function D(e) {
75
- let t = e;
76
- t.startsWith("did:nft:") && (t = t.replace("did:nft:", "").replace(/_/g, "/"));
77
- const [n, a, r] = t.split("/"), [f, i] = n.split(":"), [c, s] = a.split(":");
78
- if (!f || f.toLowerCase() !== "eip155")
79
- throw new p({ reason: "Only EIP-155 supported" });
80
- if (!i)
81
- throw new p({ reason: "Chain ID not found" });
82
- if (!s)
83
- throw new p({
84
- reason: "Contract address not found"
85
- });
86
- if (!r)
87
- throw new p({ reason: "Token ID not found" });
88
- if (!c)
89
- throw new p({ reason: "ERC namespace not found" });
90
- return {
91
- chainID: Number.parseInt(i),
92
- namespace: c.toLowerCase(),
93
- contractAddress: s,
94
- tokenID: r
95
- };
96
- }
97
- async function O(e, { nft: t }) {
98
- if (t.namespace === "erc721")
99
- return w(e, {
100
- address: t.contractAddress,
101
- abi: [
102
- {
103
- name: "tokenURI",
104
- type: "function",
105
- stateMutability: "view",
106
- inputs: [{ name: "tokenId", type: "uint256" }],
107
- outputs: [{ name: "", type: "string" }]
108
- }
109
- ],
110
- functionName: "tokenURI",
111
- args: [BigInt(t.tokenID)]
112
- });
113
- if (t.namespace === "erc1155")
114
- return w(e, {
115
- address: t.contractAddress,
116
- abi: [
117
- {
118
- name: "uri",
119
- type: "function",
120
- stateMutability: "view",
121
- inputs: [{ name: "_id", type: "uint256" }],
122
- outputs: [{ name: "", type: "string" }]
123
- }
124
- ],
125
- functionName: "uri",
126
- args: [BigInt(t.tokenID)]
127
- });
128
- throw new I({ namespace: t.namespace });
1
+ function n(e) {
2
+ return `[${e.slice(2)}]`;
129
3
  }
130
4
  export {
131
- l as getGateway,
132
- U as getJsonImage,
133
- $ as getMetadataAvatarUri,
134
- O as getNftTokenUri,
135
- k as isImageUri,
136
- R as parseAvatarUri,
137
- D as parseNftUri,
138
- C as resolveAvatarUri
5
+ n as encodeLabelhash
139
6
  };
@@ -1,6 +1,139 @@
1
- function n(e) {
2
- return `[${e.slice(2)}]`;
1
+ import { readContract as w } from "./index69.js";
2
+ import { EnsAvatarUriResolutionError as d, EnsAvatarInvalidNftUriError as p, EnsAvatarUnsupportedNamespaceError as I, EnsAvatarInvalidMetadataError as y } from "./index113.js";
3
+ const v = /(?<protocol>https?:\/\/[^\/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/, A = /^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(?<target>[\w\-.]+))?(?<subtarget>\/.*)?$/, b = /^data:([a-zA-Z\-/+]*);base64,([^"].*)/, E = /^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;
4
+ async function k(e) {
5
+ try {
6
+ const t = await fetch(e, { method: "HEAD" });
7
+ return t.status === 200 ? t.headers.get("content-type")?.startsWith("image/") : !1;
8
+ } catch (t) {
9
+ return typeof t == "object" && typeof t.response < "u" || !globalThis.hasOwnProperty("Image") ? !1 : new Promise((n) => {
10
+ const a = new Image();
11
+ a.onload = () => {
12
+ n(!0);
13
+ }, a.onerror = () => {
14
+ n(!1);
15
+ }, a.src = e;
16
+ });
17
+ }
18
+ }
19
+ function l(e, t) {
20
+ return e ? e.endsWith("/") ? e.slice(0, -1) : e : t;
21
+ }
22
+ function C({ uri: e, gatewayUrls: t }) {
23
+ const n = b.test(e);
24
+ if (n)
25
+ return { uri: e, isOnChain: !0, isEncoded: n };
26
+ const a = l(t?.ipfs, "https://ipfs.io"), r = l(t?.arweave, "https://arweave.net"), f = e.match(v), { protocol: i, subpath: c, target: s, subtarget: h = "" } = f?.groups || {}, u = i === "ipns:/" || c === "ipns/", m = i === "ipfs:/" || c === "ipfs/" || A.test(e);
27
+ if (e.startsWith("http") && !u && !m) {
28
+ let g = e;
29
+ return t?.arweave && (g = e.replace(/https:\/\/arweave.net/g, t?.arweave)), { uri: g, isOnChain: !1, isEncoded: !1 };
30
+ }
31
+ if ((u || m) && s)
32
+ return {
33
+ uri: `${a}/${u ? "ipns" : "ipfs"}/${s}${h}`,
34
+ isOnChain: !1,
35
+ isEncoded: !1
36
+ };
37
+ if (i === "ar:/" && s)
38
+ return {
39
+ uri: `${r}/${s}${h || ""}`,
40
+ isOnChain: !1,
41
+ isEncoded: !1
42
+ };
43
+ let o = e.replace(E, "");
44
+ if (o.startsWith("<svg") && (o = `data:image/svg+xml;base64,${btoa(o)}`), o.startsWith("data:") || o.startsWith("{"))
45
+ return {
46
+ uri: o,
47
+ isOnChain: !0,
48
+ isEncoded: !1
49
+ };
50
+ throw new d({ uri: e });
51
+ }
52
+ function U(e) {
53
+ if (typeof e != "object" || !("image" in e) && !("image_url" in e) && !("image_data" in e))
54
+ throw new y({ data: e });
55
+ return e.image || e.image_url || e.image_data;
56
+ }
57
+ async function $({ gatewayUrls: e, uri: t }) {
58
+ try {
59
+ const n = await fetch(t).then((r) => r.json());
60
+ return await R({
61
+ gatewayUrls: e,
62
+ uri: U(n)
63
+ });
64
+ } catch {
65
+ throw new d({ uri: t });
66
+ }
67
+ }
68
+ async function R({ gatewayUrls: e, uri: t }) {
69
+ const { uri: n, isOnChain: a } = C({ uri: t, gatewayUrls: e });
70
+ if (a || await k(n))
71
+ return n;
72
+ throw new d({ uri: t });
73
+ }
74
+ function D(e) {
75
+ let t = e;
76
+ t.startsWith("did:nft:") && (t = t.replace("did:nft:", "").replace(/_/g, "/"));
77
+ const [n, a, r] = t.split("/"), [f, i] = n.split(":"), [c, s] = a.split(":");
78
+ if (!f || f.toLowerCase() !== "eip155")
79
+ throw new p({ reason: "Only EIP-155 supported" });
80
+ if (!i)
81
+ throw new p({ reason: "Chain ID not found" });
82
+ if (!s)
83
+ throw new p({
84
+ reason: "Contract address not found"
85
+ });
86
+ if (!r)
87
+ throw new p({ reason: "Token ID not found" });
88
+ if (!c)
89
+ throw new p({ reason: "ERC namespace not found" });
90
+ return {
91
+ chainID: Number.parseInt(i),
92
+ namespace: c.toLowerCase(),
93
+ contractAddress: s,
94
+ tokenID: r
95
+ };
96
+ }
97
+ async function O(e, { nft: t }) {
98
+ if (t.namespace === "erc721")
99
+ return w(e, {
100
+ address: t.contractAddress,
101
+ abi: [
102
+ {
103
+ name: "tokenURI",
104
+ type: "function",
105
+ stateMutability: "view",
106
+ inputs: [{ name: "tokenId", type: "uint256" }],
107
+ outputs: [{ name: "", type: "string" }]
108
+ }
109
+ ],
110
+ functionName: "tokenURI",
111
+ args: [BigInt(t.tokenID)]
112
+ });
113
+ if (t.namespace === "erc1155")
114
+ return w(e, {
115
+ address: t.contractAddress,
116
+ abi: [
117
+ {
118
+ name: "uri",
119
+ type: "function",
120
+ stateMutability: "view",
121
+ inputs: [{ name: "_id", type: "uint256" }],
122
+ outputs: [{ name: "", type: "string" }]
123
+ }
124
+ ],
125
+ functionName: "uri",
126
+ args: [BigInt(t.tokenID)]
127
+ });
128
+ throw new I({ namespace: t.namespace });
3
129
  }
4
130
  export {
5
- n as encodeLabelhash
131
+ l as getGateway,
132
+ U as getJsonImage,
133
+ $ as getMetadataAvatarUri,
134
+ O as getNftTokenUri,
135
+ k as isImageUri,
136
+ R as parseAvatarUri,
137
+ D as parseNftUri,
138
+ C as resolveAvatarUri
6
139
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cdp-hooks",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/**",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": ">=18.2.0",
18
- "@coinbase/cdp-core": "^0.0.61"
18
+ "@coinbase/cdp-core": "^0.0.63"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@testing-library/jest-dom": "^6.6.3",
@@ -30,7 +30,7 @@
30
30
  "@size-limit/webpack": "^11.2.0",
31
31
  "@size-limit/webpack-why": "^11.2.0",
32
32
  "size-limit": "^11.2.0",
33
- "@coinbase/cdp-core": "^0.0.61"
33
+ "@coinbase/cdp-core": "^0.0.63"
34
34
  },
35
35
  "size-limit": [
36
36
  {