@talismn/orb 0.3.1 → 0.3.3

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 +16 -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 +3 -4
  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
@@ -1 +0,0 @@
1
- export declare const normalizeAddress: (address: string) => string;
@@ -1,29 +0,0 @@
1
- // inspired from https://github.com/wevm/viem/blob/main/src/utils/address/getAddress.ts
2
-
3
- import { keccak_256 } from "@noble/hashes/sha3"
4
-
5
- const TEXT_ENCODER = new TextEncoder()
6
-
7
- export const isEthAddress = (address: string): address is `0x${string}` =>
8
- /^0x[a-fA-F0-9]{40}$/.test(address)
9
-
10
- export const normalizeEthAddress = (address: `0x${string}`): `0x${string}` => {
11
- if (!isEthAddress(address)) throw new Error(`Invalid Ethereum address ${address}`)
12
-
13
- const rawAddress = address.toLowerCase().substring(2)
14
- const bytes = TEXT_ENCODER.encode(rawAddress)
15
- const hash = keccak_256(bytes)
16
-
17
- // apply checksum
18
- const csAddress = rawAddress.split("")
19
- for (let i = 0; i < 40; i += 2) {
20
- if (hash[i >> 1] >> 4 >= 8 && address[i]) {
21
- csAddress[i] = csAddress[i].toUpperCase()
22
- }
23
- if ((hash[i >> 1] & 0x0f) >= 8 && address[i + 1]) {
24
- csAddress[i + 1] = csAddress[i + 1].toUpperCase()
25
- }
26
- }
27
-
28
- return `0x${csAddress.join("")}`
29
- }
@@ -1,2 +0,0 @@
1
- export * from "./ethAddress"
2
- export * from "./subAddress"
@@ -1,39 +0,0 @@
1
- // inspired from https://github.com/polkadot-api/polkadot-api/blob/main/packages/substrate-bindings/src/codecs/scale/AccountId.ts
2
-
3
- import { blake2b } from "@noble/hashes/blake2b"
4
- import { base58 } from "@scure/base"
5
-
6
- const SS58_PREFIX = new TextEncoder().encode("SS58PRE")
7
- const SS58_FORMAT = 42
8
- const CHECKSUM_LENGTH = 2
9
- const VALID_BYTES_LENGTH = [32, 33]
10
-
11
- const encode = (publicKey: Uint8Array) => {
12
- const prefixBytes = Uint8Array.of(SS58_FORMAT)
13
- const checksum = blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), {
14
- dkLen: 64,
15
- }).subarray(0, CHECKSUM_LENGTH)
16
- return base58.encode(Uint8Array.of(...prefixBytes, ...publicKey, ...checksum))
17
- }
18
-
19
- const decode = (address: string) => {
20
- const decoded = base58.decode(address)
21
- const prefixBytes = decoded.subarray(0, decoded[0] & 0b0100_0000 ? 2 : 1)
22
- const publicKey = decoded.subarray(prefixBytes.length, decoded.length - CHECKSUM_LENGTH)
23
-
24
- if (!VALID_BYTES_LENGTH.includes(publicKey.length)) throw new Error("Invalid public key length")
25
- const checksum = decoded.subarray(prefixBytes.length + publicKey.length)
26
- const expectedChecksum = blake2b(Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey), {
27
- dkLen: 64,
28
- }).subarray(0, CHECKSUM_LENGTH)
29
- if (checksum[0] !== expectedChecksum[0] || checksum[1] !== expectedChecksum[1])
30
- throw new Error("Invalid checksum")
31
-
32
- return publicKey.slice()
33
- }
34
-
35
- export const normalizeSubAddress = (address: string) => {
36
- // source address might be encoded with a different prefix than 42
37
- // decode then reencode with prefix 42
38
- return encode(decode(address))
39
- }
@@ -1,5 +0,0 @@
1
- import { isEthAddress, normalizeEthAddress, normalizeSubAddress } from "./lib"
2
-
3
- export const normalizeAddress = (address: string) => {
4
- return isEthAddress(address) ? normalizeEthAddress(address) : normalizeSubAddress(address)
5
- }