@talismn/orb 0.3.0 → 0.3.2

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 (31) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/declarations/src/components/TalismanOrb.d.ts +1 -19
  3. package/dist/declarations/src/components/TalismanOrbLogo.d.ts +5 -0
  4. package/dist/declarations/src/components/TalismanOrbRectangle.d.ts +3 -0
  5. package/dist/declarations/src/components/index.d.ts +3 -0
  6. package/dist/declarations/src/components/types.d.ts +6 -0
  7. package/dist/declarations/src/components/useTalismanOrb.d.ts +10 -0
  8. package/dist/declarations/src/index.d.ts +1 -0
  9. package/dist/declarations/src/util/getTalismanOrbDataUrl.d.ts +4 -0
  10. package/dist/declarations/src/util/index.d.ts +1 -0
  11. package/dist/talismn-orb.cjs.dev.js +62 -105
  12. package/dist/talismn-orb.cjs.prod.js +62 -105
  13. package/dist/talismn-orb.esm.js +61 -106
  14. package/package.json +5 -6
  15. package/src/components/TalismanOrb.tsx +6 -167
  16. package/src/components/TalismanOrbLogo.tsx +60 -0
  17. package/src/components/TalismanOrbRectangle.tsx +40 -0
  18. package/src/components/index.ts +3 -0
  19. package/src/components/types.ts +1 -0
  20. package/src/components/useTalismanOrb.ts +70 -0
  21. package/src/index.ts +1 -0
  22. package/src/util/getTalismanOrbDataUrl.tsx +14 -0
  23. package/src/util/index.ts +1 -0
  24. package/dist/declarations/src/util/lib/ethAddress.d.ts +0 -2
  25. package/dist/declarations/src/util/lib/index.d.ts +0 -2
  26. package/dist/declarations/src/util/lib/subAddress.d.ts +0 -1
  27. package/dist/declarations/src/util/normalizeAddress.d.ts +0 -1
  28. package/src/util/lib/ethAddress.ts +0 -29
  29. package/src/util/lib/index.ts +0 -2
  30. package/src/util/lib/subAddress.ts +0 -39
  31. package/src/util/normalizeAddress.ts +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @talismn/orb
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - f0a103b: feat: updates for solana
8
+ - Updated dependencies [a922bed]
9
+ - Updated dependencies [f0a103b]
10
+ - @talismn/crypto@0.2.1
11
+
12
+ ## 0.3.1
13
+
14
+ ### Patch Changes
15
+
16
+ - 78f3616: bump pjs and papi deps
17
+
3
18
  ## 0.3.0
4
19
 
5
20
  ### Minor Changes
@@ -1,21 +1,3 @@
1
1
  import { FC } from "react";
2
- type TalismanOrbProps = {
3
- seed: string;
4
- width?: number;
5
- height?: number;
6
- className?: string;
7
- };
8
- type LogoIconType = "ethereum" | "substrate";
9
- export declare const useTalismanOrb: (seed: string) => {
10
- id: string;
11
- bgColor1: string;
12
- bgColor2: string;
13
- glowColor: string;
14
- transform: string;
15
- cx: number;
16
- cy: number;
17
- iconType: LogoIconType;
18
- };
2
+ import { TalismanOrbProps } from "./types";
19
3
  export declare const TalismanOrb: FC<TalismanOrbProps>;
20
- export declare const TalismanOrbRectangle: FC<TalismanOrbProps>;
21
- export {};
@@ -0,0 +1,5 @@
1
+ import { AccountPlatform } from "@talismn/crypto";
2
+ import { FC } from "react";
3
+ export declare const TalismanOrbLogo: FC<{
4
+ platform: AccountPlatform;
5
+ }>;
@@ -0,0 +1,3 @@
1
+ import { FC } from "react";
2
+ import { TalismanOrbProps } from "./types";
3
+ export declare const TalismanOrbRectangle: FC<TalismanOrbProps>;
@@ -1 +1,4 @@
1
+ export * from "./types";
2
+ export * from "./useTalismanOrb";
1
3
  export * from "./TalismanOrb";
4
+ export * from "./TalismanOrbRectangle";
@@ -0,0 +1,6 @@
1
+ export type TalismanOrbProps = {
2
+ seed: string;
3
+ width?: number;
4
+ height?: number;
5
+ className?: string;
6
+ };
@@ -0,0 +1,10 @@
1
+ export declare const useTalismanOrb: (seed: string) => {
2
+ id: string;
3
+ bgColor1: string;
4
+ bgColor2: string;
5
+ glowColor: string;
6
+ transform: string;
7
+ cx: number;
8
+ cy: number;
9
+ platform: import("@talismn/crypto").AccountPlatform;
10
+ };
@@ -1 +1,2 @@
1
1
  export * from "./components";
2
+ export * from "./util";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns a base64 encoded data url for the Talisman Orb svg
3
+ */
4
+ export declare const getTalismanOrbDataUrl: (address: string) => `data:image/svg+xml;base64,${string}`;
@@ -0,0 +1 @@
1
+ export * from "./getTalismanOrbDataUrl";
@@ -1,75 +1,17 @@
1
1
  'use strict';
2
2
 
3
+ var crypto = require('@talismn/crypto');
3
4
  var md5 = require('blueimp-md5');
4
5
  var Color = require('color');
5
6
  var react = require('react');
6
- var sha3 = require('@noble/hashes/sha3');
7
- var blake2b = require('@noble/hashes/blake2b');
8
- var base = require('@scure/base');
9
7
  var jsxRuntime = require('react/jsx-runtime');
8
+ var ReactDOMServer = require('react-dom/server');
10
9
 
11
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
11
 
13
12
  var md5__default = /*#__PURE__*/_interopDefault(md5);
14
13
  var Color__default = /*#__PURE__*/_interopDefault(Color);
15
-
16
- // inspired from https://github.com/wevm/viem/blob/main/src/utils/address/getAddress.ts
17
-
18
- const TEXT_ENCODER = new TextEncoder();
19
- const isEthAddress = address => /^0x[a-fA-F0-9]{40}$/.test(address);
20
- const normalizeEthAddress = address => {
21
- if (!isEthAddress(address)) throw new Error(`Invalid Ethereum address ${address}`);
22
- const rawAddress = address.toLowerCase().substring(2);
23
- const bytes = TEXT_ENCODER.encode(rawAddress);
24
- const hash = sha3.keccak_256(bytes);
25
-
26
- // apply checksum
27
- const csAddress = rawAddress.split("");
28
- for (let i = 0; i < 40; i += 2) {
29
- if (hash[i >> 1] >> 4 >= 8 && address[i]) {
30
- csAddress[i] = csAddress[i].toUpperCase();
31
- }
32
- if ((hash[i >> 1] & 0x0f) >= 8 && address[i + 1]) {
33
- csAddress[i + 1] = csAddress[i + 1].toUpperCase();
34
- }
35
- }
36
- return `0x${csAddress.join("")}`;
37
- };
38
-
39
- // inspired from https://github.com/polkadot-api/polkadot-api/blob/main/packages/substrate-bindings/src/codecs/scale/AccountId.ts
40
-
41
- const SS58_PREFIX = new TextEncoder().encode("SS58PRE");
42
- const SS58_FORMAT = 42;
43
- const CHECKSUM_LENGTH = 2;
44
- const VALID_BYTES_LENGTH = [32, 33];
45
- const encode = publicKey => {
46
- const prefixBytes = Uint8Array.of(SS58_FORMAT);
47
- const checksum = blake2b.blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), {
48
- dkLen: 64
49
- }).subarray(0, CHECKSUM_LENGTH);
50
- return base.base58.encode(Uint8Array.of(...prefixBytes, ...publicKey, ...checksum));
51
- };
52
- const decode = address => {
53
- const decoded = base.base58.decode(address);
54
- const prefixBytes = decoded.subarray(0, decoded[0] & 0b0100_0000 ? 2 : 1);
55
- const publicKey = decoded.subarray(prefixBytes.length, decoded.length - CHECKSUM_LENGTH);
56
- if (!VALID_BYTES_LENGTH.includes(publicKey.length)) throw new Error("Invalid public key length");
57
- const checksum = decoded.subarray(prefixBytes.length + publicKey.length);
58
- const expectedChecksum = blake2b.blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), {
59
- dkLen: 64
60
- }).subarray(0, CHECKSUM_LENGTH);
61
- if (checksum[0] !== expectedChecksum[0] || checksum[1] !== expectedChecksum[1]) throw new Error("Invalid checksum");
62
- return publicKey.slice();
63
- };
64
- const normalizeSubAddress = address => {
65
- // source address might be encoded with a different prefix than 42
66
- // decode then reencode with prefix 42
67
- return encode(decode(address));
68
- };
69
-
70
- const normalizeAddress = address => {
71
- return isEthAddress(address) ? normalizeEthAddress(address) : normalizeSubAddress(address);
72
- };
14
+ var ReactDOMServer__default = /*#__PURE__*/_interopDefault(ReactDOMServer);
73
15
 
74
16
  const djb2 = str => {
75
17
  let hash = 5381;
@@ -87,12 +29,17 @@ const rotateText = (text, nbChars = 0) => text.slice(nbChars) + text.slice(0, nb
87
29
  const useTalismanOrb = seed => {
88
30
  const id = react.useId();
89
31
  return react.useMemo(() => {
90
- const iconType = seed?.startsWith("0x") ? "ethereum" : "substrate";
91
32
  try {
33
+ // those break if seed is empty or an invalid address
34
+
35
+ // eslint-disable-next-line no-var
36
+ var platform = crypto.getAccountPlatformFromAddress(seed);
37
+
92
38
  // seed may be specific to a ss58 prefix, get the base address
93
39
  // eslint-disable-next-line no-var
94
- var address = normalizeAddress(seed);
40
+ var address = crypto.normalizeAddress(seed);
95
41
  } catch (err) {
42
+ platform = "polkadot";
96
43
  address = seed;
97
44
  }
98
45
 
@@ -120,15 +67,15 @@ const useTalismanOrb = seed => {
120
67
  transform: `rotate(${rotation} 32 32)`,
121
68
  cx: dotX,
122
69
  cy: dotY,
123
- iconType
70
+ platform
124
71
  };
125
72
  }, [id, seed]);
126
73
  };
74
+
127
75
  const TalismanOrbLogo = ({
128
- id,
129
- iconType
76
+ platform
130
77
  }) => {
131
- switch (iconType) {
78
+ switch (platform) {
132
79
  case "ethereum":
133
80
  return /*#__PURE__*/jsxRuntime.jsxs("g", {
134
81
  opacity: "0.75",
@@ -142,47 +89,46 @@ const TalismanOrbLogo = ({
142
89
  fill: "white"
143
90
  })]
144
91
  });
145
- case "substrate":
146
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
147
- children: [/*#__PURE__*/jsxRuntime.jsxs("g", {
148
- clipPath: `url(#${id}_1751_2030)`,
149
- opacity: "0.75",
150
- transform: "scale(2.2) translate(4.5 3.9)",
151
- className: "orb-type",
152
- children: [/*#__PURE__*/jsxRuntime.jsx("path", {
153
- d: "M9.99937 4.4612C12.1176 4.4612 13.8347 3.46253 13.8347 2.2306C13.8347 0.998674 12.1176 0 9.99937 0C7.88119 0 6.16406 0.998674 6.16406 2.2306C6.16406 3.46253 7.88119 4.4612 9.99937 4.4612Z",
154
- fill: "white"
155
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
156
- d: "M9.99937 21.2683C12.1176 21.2683 13.8347 20.2697 13.8347 19.0377C13.8347 17.8058 12.1176 16.8071 9.99937 16.8071C7.88119 16.8071 6.16406 17.8058 6.16406 19.0377C6.16406 20.2697 7.88119 21.2683 9.99937 21.2683Z",
157
- fill: "white"
158
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
159
- d: "M4.65427 7.54892C5.71336 5.71457 5.70649 3.72787 4.63892 3.11149C3.57135 2.49511 1.84735 3.48246 0.788259 5.31681C-0.270832 7.15115 -0.263958 9.13786 0.803612 9.75424C1.87118 10.3706 3.59518 9.38326 4.65427 7.54892Z",
160
- fill: "white"
161
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
162
- d: "M19.2083 15.9515C20.2674 14.1171 20.2611 12.1307 19.1943 11.5148C18.1274 10.8988 16.404 11.8865 15.3449 13.7209C14.2858 15.5552 14.2921 17.5416 15.3589 18.1575C16.4258 18.7735 18.1492 17.7858 19.2083 15.9515Z",
163
- fill: "white"
164
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
165
- d: "M4.6399 18.1571C5.70747 17.5407 5.71434 15.554 4.65525 13.7196C3.59616 11.8853 1.87216 10.8979 0.804589 11.5143C-0.262981 12.1307 -0.269855 14.1174 0.789235 15.9517C1.84833 17.7861 3.57233 18.7734 4.6399 18.1571Z",
166
- fill: "white"
167
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
168
- d: "M19.1952 9.75475C20.2621 9.13878 20.2684 7.15241 19.2093 5.31807C18.1502 3.48372 16.4268 2.49603 15.3599 3.11199C14.2931 3.72796 14.2868 5.71433 15.3459 7.54867C16.405 9.38302 18.1284 10.3707 19.1952 9.75475Z",
169
- fill: "white"
170
- })]
171
- }), /*#__PURE__*/jsxRuntime.jsx("defs", {
172
- children: /*#__PURE__*/jsxRuntime.jsx("clipPath", {
173
- id: `${id}_1751_2030`,
174
- children: /*#__PURE__*/jsxRuntime.jsx("rect", {
175
- width: "20",
176
- height: "21.2699",
177
- fill: "white"
178
- })
179
- })
92
+ case "polkadot":
93
+ return /*#__PURE__*/jsxRuntime.jsxs("g", {
94
+ opacity: "0.75",
95
+ transform: "scale(2.2) translate(4.5 3.9)",
96
+ className: "orb-type",
97
+ children: [/*#__PURE__*/jsxRuntime.jsx("path", {
98
+ d: "M9.99937 4.4612C12.1176 4.4612 13.8347 3.46253 13.8347 2.2306C13.8347 0.998674 12.1176 0 9.99937 0C7.88119 0 6.16406 0.998674 6.16406 2.2306C6.16406 3.46253 7.88119 4.4612 9.99937 4.4612Z",
99
+ fill: "white"
100
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
101
+ d: "M9.99937 21.2683C12.1176 21.2683 13.8347 20.2697 13.8347 19.0377C13.8347 17.8058 12.1176 16.8071 9.99937 16.8071C7.88119 16.8071 6.16406 17.8058 6.16406 19.0377C6.16406 20.2697 7.88119 21.2683 9.99937 21.2683Z",
102
+ fill: "white"
103
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
104
+ d: "M4.65427 7.54892C5.71336 5.71457 5.70649 3.72787 4.63892 3.11149C3.57135 2.49511 1.84735 3.48246 0.788259 5.31681C-0.270832 7.15115 -0.263958 9.13786 0.803612 9.75424C1.87118 10.3706 3.59518 9.38326 4.65427 7.54892Z",
105
+ fill: "white"
106
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
107
+ d: "M19.2083 15.9515C20.2674 14.1171 20.2611 12.1307 19.1943 11.5148C18.1274 10.8988 16.404 11.8865 15.3449 13.7209C14.2858 15.5552 14.2921 17.5416 15.3589 18.1575C16.4258 18.7735 18.1492 17.7858 19.2083 15.9515Z",
108
+ fill: "white"
109
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
110
+ d: "M4.6399 18.1571C5.70747 17.5407 5.71434 15.554 4.65525 13.7196C3.59616 11.8853 1.87216 10.8979 0.804589 11.5143C-0.262981 12.1307 -0.269855 14.1174 0.789235 15.9517C1.84833 17.7861 3.57233 18.7734 4.6399 18.1571Z",
111
+ fill: "white"
112
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
113
+ d: "M19.1952 9.75475C20.2621 9.13878 20.2684 7.15241 19.2093 5.31807C18.1502 3.48372 16.4268 2.49603 15.3599 3.11199C14.2931 3.72796 14.2868 5.71433 15.3459 7.54867C16.405 9.38302 18.1284 10.3707 19.1952 9.75475Z",
114
+ fill: "white"
180
115
  })]
181
116
  });
117
+ case "solana":
118
+ return /*#__PURE__*/jsxRuntime.jsx("g", {
119
+ opacity: "0.75",
120
+ className: "orb-type",
121
+ transform: "scale(0.45) translate(37.5, 37.5)",
122
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
123
+ d: "M70.6648 50.1769L58.9393 62.775C58.6844 63.0486 58.376 63.2668 58.0332 63.4159C57.6905 63.5651 57.3208 63.6419 56.9472 63.6417H1.36128C1.09605 63.6417 0.836598 63.5641 0.614804 63.4184C0.393011 63.2727 0.218536 63.0652 0.112817 62.8215C0.00709765 62.5779 -0.0252603 62.3085 0.0197186 62.0467C0.0646974 61.7848 0.185054 61.5418 0.366 61.3476L12.1006 48.7496C12.3548 48.4766 12.6623 48.2589 13.0039 48.1098C13.3455 47.9607 13.714 47.8834 14.0866 47.8828H69.6695C69.9348 47.8828 70.1942 47.9604 70.416 48.1062C70.6378 48.2519 70.8123 48.4593 70.918 48.703C71.0237 48.9467 71.0561 49.216 71.0111 49.4778C70.9661 49.7397 70.8458 49.9827 70.6648 50.1769V50.1769ZM58.9393 24.8081C58.6844 24.5345 58.376 24.3163 58.0332 24.1672C57.6905 24.0181 57.3208 23.9412 56.9472 23.9414H1.36128C1.09605 23.9414 0.836598 24.019 0.614804 24.1647C0.393011 24.3105 0.218536 24.5179 0.112817 24.7616C0.00709765 25.0053 -0.0252603 25.2746 0.0197186 25.5364C0.0646974 25.7983 0.185054 26.0413 0.366 26.2355L12.1006 38.8336C12.3548 39.1065 12.6623 39.3242 13.0039 39.4733C13.3455 39.6224 13.714 39.6997 14.0866 39.7003H69.6695C69.9348 39.7003 70.1942 39.6227 70.416 39.477C70.6378 39.3313 70.8123 39.1238 70.918 38.8801C71.0237 38.6365 71.0561 38.3671 71.0111 38.1053C70.9661 37.8434 70.8458 37.6004 70.6648 37.4062L58.9393 24.8081ZM1.36128 15.7589H56.9472C57.3208 15.7591 57.6905 15.6822 58.0332 15.5331C58.376 15.384 58.6844 15.1658 58.9393 14.8922L70.6648 2.29413C70.8458 2.09986 70.9661 1.85688 71.0111 1.59502C71.0561 1.33317 71.0237 1.06385 70.918 0.820169C70.8123 0.576485 70.6378 0.369047 70.416 0.223341C70.1942 0.0776352 69.9348 8.97308e-06 69.6695 0L14.0866 0C13.714 0.000635258 13.3455 0.077888 13.0039 0.226975C12.6623 0.376063 12.3548 0.593811 12.1006 0.866739L0.369025 13.4648C0.188254 13.6588 0.0679503 13.9016 0.0228694 14.1631C-0.0222115 14.4247 0.00988974 14.6938 0.115236 14.9373C0.220583 15.1809 0.394595 15.3884 0.615931 15.5343C0.837268 15.6802 1.09631 15.7583 1.36128 15.7589V15.7589Z",
124
+ fill: "white"
125
+ })
126
+ });
182
127
  default:
183
128
  return null;
184
129
  }
185
130
  };
131
+
186
132
  const TalismanOrb = ({
187
133
  seed,
188
134
  width = "1em",
@@ -197,7 +143,7 @@ const TalismanOrb = ({
197
143
  glowColor,
198
144
  cx,
199
145
  cy,
200
- iconType
146
+ platform
201
147
  } = useTalismanOrb(seed);
202
148
  return /*#__PURE__*/jsxRuntime.jsxs("svg", {
203
149
  width: width,
@@ -251,12 +197,12 @@ const TalismanOrb = ({
251
197
  opacity: 0.7
252
198
  })]
253
199
  }), /*#__PURE__*/jsxRuntime.jsx(TalismanOrbLogo, {
254
- id: id,
255
- iconType: iconType
200
+ platform: platform
256
201
  })]
257
202
  })]
258
203
  });
259
204
  };
205
+
260
206
  const TalismanOrbRectangle = ({
261
207
  width,
262
208
  height,
@@ -329,6 +275,17 @@ const TalismanOrbRectangle = ({
329
275
  });
330
276
  };
331
277
 
278
+ const getTalismanOrbDataUrl = address => {
279
+ // render the TalismanOrb component and output the SVG as text
280
+ const svg = ReactDOMServer__default.default.renderToStaticMarkup(/*#__PURE__*/jsxRuntime.jsx(TalismanOrb, {
281
+ seed: address
282
+ }));
283
+
284
+ // convert to data url
285
+ return `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`;
286
+ };
287
+
332
288
  exports.TalismanOrb = TalismanOrb;
333
289
  exports.TalismanOrbRectangle = TalismanOrbRectangle;
290
+ exports.getTalismanOrbDataUrl = getTalismanOrbDataUrl;
334
291
  exports.useTalismanOrb = useTalismanOrb;
@@ -1,75 +1,17 @@
1
1
  'use strict';
2
2
 
3
+ var crypto = require('@talismn/crypto');
3
4
  var md5 = require('blueimp-md5');
4
5
  var Color = require('color');
5
6
  var react = require('react');
6
- var sha3 = require('@noble/hashes/sha3');
7
- var blake2b = require('@noble/hashes/blake2b');
8
- var base = require('@scure/base');
9
7
  var jsxRuntime = require('react/jsx-runtime');
8
+ var ReactDOMServer = require('react-dom/server');
10
9
 
11
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
11
 
13
12
  var md5__default = /*#__PURE__*/_interopDefault(md5);
14
13
  var Color__default = /*#__PURE__*/_interopDefault(Color);
15
-
16
- // inspired from https://github.com/wevm/viem/blob/main/src/utils/address/getAddress.ts
17
-
18
- const TEXT_ENCODER = new TextEncoder();
19
- const isEthAddress = address => /^0x[a-fA-F0-9]{40}$/.test(address);
20
- const normalizeEthAddress = address => {
21
- if (!isEthAddress(address)) throw new Error(`Invalid Ethereum address ${address}`);
22
- const rawAddress = address.toLowerCase().substring(2);
23
- const bytes = TEXT_ENCODER.encode(rawAddress);
24
- const hash = sha3.keccak_256(bytes);
25
-
26
- // apply checksum
27
- const csAddress = rawAddress.split("");
28
- for (let i = 0; i < 40; i += 2) {
29
- if (hash[i >> 1] >> 4 >= 8 && address[i]) {
30
- csAddress[i] = csAddress[i].toUpperCase();
31
- }
32
- if ((hash[i >> 1] & 0x0f) >= 8 && address[i + 1]) {
33
- csAddress[i + 1] = csAddress[i + 1].toUpperCase();
34
- }
35
- }
36
- return `0x${csAddress.join("")}`;
37
- };
38
-
39
- // inspired from https://github.com/polkadot-api/polkadot-api/blob/main/packages/substrate-bindings/src/codecs/scale/AccountId.ts
40
-
41
- const SS58_PREFIX = new TextEncoder().encode("SS58PRE");
42
- const SS58_FORMAT = 42;
43
- const CHECKSUM_LENGTH = 2;
44
- const VALID_BYTES_LENGTH = [32, 33];
45
- const encode = publicKey => {
46
- const prefixBytes = Uint8Array.of(SS58_FORMAT);
47
- const checksum = blake2b.blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), {
48
- dkLen: 64
49
- }).subarray(0, CHECKSUM_LENGTH);
50
- return base.base58.encode(Uint8Array.of(...prefixBytes, ...publicKey, ...checksum));
51
- };
52
- const decode = address => {
53
- const decoded = base.base58.decode(address);
54
- const prefixBytes = decoded.subarray(0, decoded[0] & 0b0100_0000 ? 2 : 1);
55
- const publicKey = decoded.subarray(prefixBytes.length, decoded.length - CHECKSUM_LENGTH);
56
- if (!VALID_BYTES_LENGTH.includes(publicKey.length)) throw new Error("Invalid public key length");
57
- const checksum = decoded.subarray(prefixBytes.length + publicKey.length);
58
- const expectedChecksum = blake2b.blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), {
59
- dkLen: 64
60
- }).subarray(0, CHECKSUM_LENGTH);
61
- if (checksum[0] !== expectedChecksum[0] || checksum[1] !== expectedChecksum[1]) throw new Error("Invalid checksum");
62
- return publicKey.slice();
63
- };
64
- const normalizeSubAddress = address => {
65
- // source address might be encoded with a different prefix than 42
66
- // decode then reencode with prefix 42
67
- return encode(decode(address));
68
- };
69
-
70
- const normalizeAddress = address => {
71
- return isEthAddress(address) ? normalizeEthAddress(address) : normalizeSubAddress(address);
72
- };
14
+ var ReactDOMServer__default = /*#__PURE__*/_interopDefault(ReactDOMServer);
73
15
 
74
16
  const djb2 = str => {
75
17
  let hash = 5381;
@@ -87,12 +29,17 @@ const rotateText = (text, nbChars = 0) => text.slice(nbChars) + text.slice(0, nb
87
29
  const useTalismanOrb = seed => {
88
30
  const id = react.useId();
89
31
  return react.useMemo(() => {
90
- const iconType = seed?.startsWith("0x") ? "ethereum" : "substrate";
91
32
  try {
33
+ // those break if seed is empty or an invalid address
34
+
35
+ // eslint-disable-next-line no-var
36
+ var platform = crypto.getAccountPlatformFromAddress(seed);
37
+
92
38
  // seed may be specific to a ss58 prefix, get the base address
93
39
  // eslint-disable-next-line no-var
94
- var address = normalizeAddress(seed);
40
+ var address = crypto.normalizeAddress(seed);
95
41
  } catch (err) {
42
+ platform = "polkadot";
96
43
  address = seed;
97
44
  }
98
45
 
@@ -120,15 +67,15 @@ const useTalismanOrb = seed => {
120
67
  transform: `rotate(${rotation} 32 32)`,
121
68
  cx: dotX,
122
69
  cy: dotY,
123
- iconType
70
+ platform
124
71
  };
125
72
  }, [id, seed]);
126
73
  };
74
+
127
75
  const TalismanOrbLogo = ({
128
- id,
129
- iconType
76
+ platform
130
77
  }) => {
131
- switch (iconType) {
78
+ switch (platform) {
132
79
  case "ethereum":
133
80
  return /*#__PURE__*/jsxRuntime.jsxs("g", {
134
81
  opacity: "0.75",
@@ -142,47 +89,46 @@ const TalismanOrbLogo = ({
142
89
  fill: "white"
143
90
  })]
144
91
  });
145
- case "substrate":
146
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
147
- children: [/*#__PURE__*/jsxRuntime.jsxs("g", {
148
- clipPath: `url(#${id}_1751_2030)`,
149
- opacity: "0.75",
150
- transform: "scale(2.2) translate(4.5 3.9)",
151
- className: "orb-type",
152
- children: [/*#__PURE__*/jsxRuntime.jsx("path", {
153
- d: "M9.99937 4.4612C12.1176 4.4612 13.8347 3.46253 13.8347 2.2306C13.8347 0.998674 12.1176 0 9.99937 0C7.88119 0 6.16406 0.998674 6.16406 2.2306C6.16406 3.46253 7.88119 4.4612 9.99937 4.4612Z",
154
- fill: "white"
155
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
156
- d: "M9.99937 21.2683C12.1176 21.2683 13.8347 20.2697 13.8347 19.0377C13.8347 17.8058 12.1176 16.8071 9.99937 16.8071C7.88119 16.8071 6.16406 17.8058 6.16406 19.0377C6.16406 20.2697 7.88119 21.2683 9.99937 21.2683Z",
157
- fill: "white"
158
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
159
- d: "M4.65427 7.54892C5.71336 5.71457 5.70649 3.72787 4.63892 3.11149C3.57135 2.49511 1.84735 3.48246 0.788259 5.31681C-0.270832 7.15115 -0.263958 9.13786 0.803612 9.75424C1.87118 10.3706 3.59518 9.38326 4.65427 7.54892Z",
160
- fill: "white"
161
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
162
- d: "M19.2083 15.9515C20.2674 14.1171 20.2611 12.1307 19.1943 11.5148C18.1274 10.8988 16.404 11.8865 15.3449 13.7209C14.2858 15.5552 14.2921 17.5416 15.3589 18.1575C16.4258 18.7735 18.1492 17.7858 19.2083 15.9515Z",
163
- fill: "white"
164
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
165
- d: "M4.6399 18.1571C5.70747 17.5407 5.71434 15.554 4.65525 13.7196C3.59616 11.8853 1.87216 10.8979 0.804589 11.5143C-0.262981 12.1307 -0.269855 14.1174 0.789235 15.9517C1.84833 17.7861 3.57233 18.7734 4.6399 18.1571Z",
166
- fill: "white"
167
- }), /*#__PURE__*/jsxRuntime.jsx("path", {
168
- d: "M19.1952 9.75475C20.2621 9.13878 20.2684 7.15241 19.2093 5.31807C18.1502 3.48372 16.4268 2.49603 15.3599 3.11199C14.2931 3.72796 14.2868 5.71433 15.3459 7.54867C16.405 9.38302 18.1284 10.3707 19.1952 9.75475Z",
169
- fill: "white"
170
- })]
171
- }), /*#__PURE__*/jsxRuntime.jsx("defs", {
172
- children: /*#__PURE__*/jsxRuntime.jsx("clipPath", {
173
- id: `${id}_1751_2030`,
174
- children: /*#__PURE__*/jsxRuntime.jsx("rect", {
175
- width: "20",
176
- height: "21.2699",
177
- fill: "white"
178
- })
179
- })
92
+ case "polkadot":
93
+ return /*#__PURE__*/jsxRuntime.jsxs("g", {
94
+ opacity: "0.75",
95
+ transform: "scale(2.2) translate(4.5 3.9)",
96
+ className: "orb-type",
97
+ children: [/*#__PURE__*/jsxRuntime.jsx("path", {
98
+ d: "M9.99937 4.4612C12.1176 4.4612 13.8347 3.46253 13.8347 2.2306C13.8347 0.998674 12.1176 0 9.99937 0C7.88119 0 6.16406 0.998674 6.16406 2.2306C6.16406 3.46253 7.88119 4.4612 9.99937 4.4612Z",
99
+ fill: "white"
100
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
101
+ d: "M9.99937 21.2683C12.1176 21.2683 13.8347 20.2697 13.8347 19.0377C13.8347 17.8058 12.1176 16.8071 9.99937 16.8071C7.88119 16.8071 6.16406 17.8058 6.16406 19.0377C6.16406 20.2697 7.88119 21.2683 9.99937 21.2683Z",
102
+ fill: "white"
103
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
104
+ d: "M4.65427 7.54892C5.71336 5.71457 5.70649 3.72787 4.63892 3.11149C3.57135 2.49511 1.84735 3.48246 0.788259 5.31681C-0.270832 7.15115 -0.263958 9.13786 0.803612 9.75424C1.87118 10.3706 3.59518 9.38326 4.65427 7.54892Z",
105
+ fill: "white"
106
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
107
+ d: "M19.2083 15.9515C20.2674 14.1171 20.2611 12.1307 19.1943 11.5148C18.1274 10.8988 16.404 11.8865 15.3449 13.7209C14.2858 15.5552 14.2921 17.5416 15.3589 18.1575C16.4258 18.7735 18.1492 17.7858 19.2083 15.9515Z",
108
+ fill: "white"
109
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
110
+ d: "M4.6399 18.1571C5.70747 17.5407 5.71434 15.554 4.65525 13.7196C3.59616 11.8853 1.87216 10.8979 0.804589 11.5143C-0.262981 12.1307 -0.269855 14.1174 0.789235 15.9517C1.84833 17.7861 3.57233 18.7734 4.6399 18.1571Z",
111
+ fill: "white"
112
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
113
+ d: "M19.1952 9.75475C20.2621 9.13878 20.2684 7.15241 19.2093 5.31807C18.1502 3.48372 16.4268 2.49603 15.3599 3.11199C14.2931 3.72796 14.2868 5.71433 15.3459 7.54867C16.405 9.38302 18.1284 10.3707 19.1952 9.75475Z",
114
+ fill: "white"
180
115
  })]
181
116
  });
117
+ case "solana":
118
+ return /*#__PURE__*/jsxRuntime.jsx("g", {
119
+ opacity: "0.75",
120
+ className: "orb-type",
121
+ transform: "scale(0.45) translate(37.5, 37.5)",
122
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
123
+ d: "M70.6648 50.1769L58.9393 62.775C58.6844 63.0486 58.376 63.2668 58.0332 63.4159C57.6905 63.5651 57.3208 63.6419 56.9472 63.6417H1.36128C1.09605 63.6417 0.836598 63.5641 0.614804 63.4184C0.393011 63.2727 0.218536 63.0652 0.112817 62.8215C0.00709765 62.5779 -0.0252603 62.3085 0.0197186 62.0467C0.0646974 61.7848 0.185054 61.5418 0.366 61.3476L12.1006 48.7496C12.3548 48.4766 12.6623 48.2589 13.0039 48.1098C13.3455 47.9607 13.714 47.8834 14.0866 47.8828H69.6695C69.9348 47.8828 70.1942 47.9604 70.416 48.1062C70.6378 48.2519 70.8123 48.4593 70.918 48.703C71.0237 48.9467 71.0561 49.216 71.0111 49.4778C70.9661 49.7397 70.8458 49.9827 70.6648 50.1769V50.1769ZM58.9393 24.8081C58.6844 24.5345 58.376 24.3163 58.0332 24.1672C57.6905 24.0181 57.3208 23.9412 56.9472 23.9414H1.36128C1.09605 23.9414 0.836598 24.019 0.614804 24.1647C0.393011 24.3105 0.218536 24.5179 0.112817 24.7616C0.00709765 25.0053 -0.0252603 25.2746 0.0197186 25.5364C0.0646974 25.7983 0.185054 26.0413 0.366 26.2355L12.1006 38.8336C12.3548 39.1065 12.6623 39.3242 13.0039 39.4733C13.3455 39.6224 13.714 39.6997 14.0866 39.7003H69.6695C69.9348 39.7003 70.1942 39.6227 70.416 39.477C70.6378 39.3313 70.8123 39.1238 70.918 38.8801C71.0237 38.6365 71.0561 38.3671 71.0111 38.1053C70.9661 37.8434 70.8458 37.6004 70.6648 37.4062L58.9393 24.8081ZM1.36128 15.7589H56.9472C57.3208 15.7591 57.6905 15.6822 58.0332 15.5331C58.376 15.384 58.6844 15.1658 58.9393 14.8922L70.6648 2.29413C70.8458 2.09986 70.9661 1.85688 71.0111 1.59502C71.0561 1.33317 71.0237 1.06385 70.918 0.820169C70.8123 0.576485 70.6378 0.369047 70.416 0.223341C70.1942 0.0776352 69.9348 8.97308e-06 69.6695 0L14.0866 0C13.714 0.000635258 13.3455 0.077888 13.0039 0.226975C12.6623 0.376063 12.3548 0.593811 12.1006 0.866739L0.369025 13.4648C0.188254 13.6588 0.0679503 13.9016 0.0228694 14.1631C-0.0222115 14.4247 0.00988974 14.6938 0.115236 14.9373C0.220583 15.1809 0.394595 15.3884 0.615931 15.5343C0.837268 15.6802 1.09631 15.7583 1.36128 15.7589V15.7589Z",
124
+ fill: "white"
125
+ })
126
+ });
182
127
  default:
183
128
  return null;
184
129
  }
185
130
  };
131
+
186
132
  const TalismanOrb = ({
187
133
  seed,
188
134
  width = "1em",
@@ -197,7 +143,7 @@ const TalismanOrb = ({
197
143
  glowColor,
198
144
  cx,
199
145
  cy,
200
- iconType
146
+ platform
201
147
  } = useTalismanOrb(seed);
202
148
  return /*#__PURE__*/jsxRuntime.jsxs("svg", {
203
149
  width: width,
@@ -251,12 +197,12 @@ const TalismanOrb = ({
251
197
  opacity: 0.7
252
198
  })]
253
199
  }), /*#__PURE__*/jsxRuntime.jsx(TalismanOrbLogo, {
254
- id: id,
255
- iconType: iconType
200
+ platform: platform
256
201
  })]
257
202
  })]
258
203
  });
259
204
  };
205
+
260
206
  const TalismanOrbRectangle = ({
261
207
  width,
262
208
  height,
@@ -329,6 +275,17 @@ const TalismanOrbRectangle = ({
329
275
  });
330
276
  };
331
277
 
278
+ const getTalismanOrbDataUrl = address => {
279
+ // render the TalismanOrb component and output the SVG as text
280
+ const svg = ReactDOMServer__default.default.renderToStaticMarkup(/*#__PURE__*/jsxRuntime.jsx(TalismanOrb, {
281
+ seed: address
282
+ }));
283
+
284
+ // convert to data url
285
+ return `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`;
286
+ };
287
+
332
288
  exports.TalismanOrb = TalismanOrb;
333
289
  exports.TalismanOrbRectangle = TalismanOrbRectangle;
290
+ exports.getTalismanOrbDataUrl = getTalismanOrbDataUrl;
334
291
  exports.useTalismanOrb = useTalismanOrb;