@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.
- package/CHANGELOG.md +16 -0
- package/dist/declarations/src/components/TalismanOrb.d.ts +1 -19
- package/dist/declarations/src/components/TalismanOrbLogo.d.ts +5 -0
- package/dist/declarations/src/components/TalismanOrbRectangle.d.ts +3 -0
- package/dist/declarations/src/components/index.d.ts +3 -0
- package/dist/declarations/src/components/types.d.ts +6 -0
- package/dist/declarations/src/components/useTalismanOrb.d.ts +10 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/util/getTalismanOrbDataUrl.d.ts +4 -0
- package/dist/declarations/src/util/index.d.ts +1 -0
- package/dist/talismn-orb.cjs.dev.js +62 -105
- package/dist/talismn-orb.cjs.prod.js +62 -105
- package/dist/talismn-orb.esm.js +61 -106
- package/package.json +3 -4
- package/src/components/TalismanOrb.tsx +6 -167
- package/src/components/TalismanOrbLogo.tsx +60 -0
- package/src/components/TalismanOrbRectangle.tsx +40 -0
- package/src/components/index.ts +3 -0
- package/src/components/types.ts +1 -0
- package/src/components/useTalismanOrb.ts +70 -0
- package/src/index.ts +1 -0
- package/src/util/getTalismanOrbDataUrl.tsx +14 -0
- package/src/util/index.ts +1 -0
- package/dist/declarations/src/util/lib/ethAddress.d.ts +0 -2
- package/dist/declarations/src/util/lib/index.d.ts +0 -2
- package/dist/declarations/src/util/lib/subAddress.d.ts +0 -1
- package/dist/declarations/src/util/normalizeAddress.d.ts +0 -1
- package/src/util/lib/ethAddress.ts +0 -29
- package/src/util/lib/index.ts +0 -2
- package/src/util/lib/subAddress.ts +0 -39
- 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
|
-
}
|
package/src/util/lib/index.ts
DELETED
|
@@ -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
|
-
}
|