Skip to content

Commit

Permalink
fix(resolver): removing name hex tag
Browse files Browse the repository at this point in the history
  • Loading branch information
banklesss committed Jan 10, 2024
1 parent ef31266 commit 87245cd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@emurgo/csl-mobile-bridge": "6.0.0-alpha.2",
"@emurgo/react-native-blockies-svg": "^0.0.2",
"@emurgo/react-native-hid": "^5.15.6",
"@emurgo/yoroi-lib": "^0.14.1",
"@emurgo/yoroi-lib": "0.14.2",
"@formatjs/intl-datetimeformat": "^6.7.0",
"@formatjs/intl-getcanonicallocales": "^2.1.0",
"@formatjs/intl-locale": "^3.2.1",
Expand Down
15 changes: 10 additions & 5 deletions apps/wallet-mobile/src/yoroi-wallets/cardano/api/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {TokenRegistryEntry} from './tokenRegistry'
import {
fallbackTokenInfo,
hexToUtf8,
toAssetName,
toDisplayAssetName,
tokenInfo,
toPolicyId,
toTokenFingerprint,
Expand All @@ -14,24 +14,29 @@ import {
} from './utils'

describe('api utils', () => {
it('toPolicyId, toAssetName', () => {
it('toPolicyId, toDisplayAssetName', () => {
const policyId = '1'.repeat(56)
const assetName = 'assetName'
const assetNameHex = utf8ToHex('assetName')
const taggedAssetNameHex = `000de140${utf8ToHex('assetName')}`

const tokenIndentifier = policyId + '.' + assetNameHex
expect(toPolicyId(tokenIndentifier)).toEqual(policyId)
expect(toAssetName(tokenIndentifier)).toEqual(assetName)
expect(toDisplayAssetName(tokenIndentifier)).toEqual(assetName)

const tokenIndentifier2 = policyId + '.' + taggedAssetNameHex
expect(toPolicyId(tokenIndentifier2)).toEqual(policyId)
expect(toDisplayAssetName(tokenIndentifier)).toEqual(assetName)

const tokenSubject = policyId + assetNameHex
expect(toPolicyId(tokenSubject)).toEqual(policyId)

const noName = policyId
expect(toPolicyId(noName)).toEqual(policyId)
expect(toAssetName(noName)).toEqual('')
expect(toDisplayAssetName(noName)).toEqual('')

const longName = '1'.repeat(128)
expect(toAssetName(policyId + '.' + utf8ToHex(longName))).toEqual('1'.repeat(32))
expect(toDisplayAssetName(policyId + '.' + utf8ToHex(longName))).toEqual('1'.repeat(32))
})

describe('toTokenSubject', () => {
Expand Down
31 changes: 12 additions & 19 deletions apps/wallet-mobile/src/yoroi-wallets/cardano/api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AssetFingerprint from '@emurgo/cip14-js'
import {AssetNameUtils} from '@emurgo/yoroi-lib/dist/internals/utils/assets'
import {Balance} from '@yoroi/types'
import {Buffer} from 'memfs/lib/internal/buffer'

Expand All @@ -7,7 +8,7 @@ import {TokenRegistryEntry} from './tokenRegistry'

export const tokenInfo = (entry: TokenRegistryEntry): Balance.TokenInfo => {
const policyId = toPolicyId(entry.subject)
const assetName = toAssetName(entry.subject)
const assetName = toDisplayAssetName(entry.subject)

return {
kind: 'ft',
Expand Down Expand Up @@ -39,7 +40,7 @@ export const tokenInfo = (entry: TokenRegistryEntry): Balance.TokenInfo => {

export const fallbackTokenInfo = (tokenId: string): Balance.TokenInfo => {
const policyId = toPolicyId(tokenId)
const assetName = toAssetName(tokenId)
const assetName = toDisplayAssetName(tokenId)

return {
kind: 'ft',
Expand All @@ -61,8 +62,8 @@ export const toPolicyId = (tokenIdentifier: string) => {
const tokenSubject = toTokenSubject(tokenIdentifier)
return tokenSubject.slice(0, 56)
}
export const toAssetName = (tokenIdentifier: string) => {
return hexToUtf8(transformCIP0068AssetNameHex(toAssetNameHex(tokenIdentifier)))
export const toDisplayAssetName = (tokenIdentifier: string) => {
return hexToUtf8(toUntaggedAssetNameHex(tokenIdentifier))
}

export const toAssetNameHex = (tokenIdentifier: string) => {
Expand All @@ -71,6 +72,12 @@ export const toAssetNameHex = (tokenIdentifier: string) => {
return tokenSubject.slice(56, 56 + maxAssetNameLengthInBytes * 2)
}

export const toUntaggedAssetNameHex = (tokenIdentifier: string) => {
const hexName = toAssetNameHex(tokenIdentifier)
const untaggedNameHex = AssetNameUtils.resolveProperties(hexName).hexName
return untaggedNameHex
}

export const toTokenSubject = (tokenIdentifier: string) => tokenIdentifier.replace('.', '')

export const toTokenId = (tokenIdentifier: string) => {
Expand All @@ -88,7 +95,7 @@ export const utf8ToHex = (text: string) => Buffer.from(text, 'utf-8').toString('

export const toTokenInfo = (token: LegacyToken): Balance.TokenInfo => {
const policyId = toPolicyId(token.identifier)
const assetName = toAssetName(token.identifier)
const assetName = toDisplayAssetName(token.identifier)

return {
kind: 'ft',
Expand Down Expand Up @@ -125,17 +132,3 @@ export const toTokenFingerprint = ({
const assetFingerprint = AssetFingerprint.fromParts(Buffer.from(policyId, 'hex'), Buffer.from(assetNameHex, 'hex'))
return assetFingerprint.fingerprint()
}

export const transformCIP0068AssetNameHex = (assetNameHex) => {
const refprefix = '000643b0'
const usrprefix = '000de140'
const stringsToRemove = [refprefix, usrprefix]

let transformedAssetNameHex = assetNameHex

stringsToRemove.forEach((str) => {
transformedAssetNameHex = transformedAssetNameHex.replace(str, '')
})

return transformedAssetNameHex
}
14 changes: 10 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2112,17 +2112,18 @@
"@ledgerhq/logs" "^5.15.0"
rxjs "^6.5.5"

"@emurgo/yoroi-lib@^0.14.1":
version "0.14.1"
resolved "https://registry.yarnpkg.com/@emurgo/yoroi-lib/-/yoroi-lib-0.14.1.tgz#b938ce5e0338182b7ce043d04245aa22f2884f3c"
integrity sha512-RuHlmHTj7kkjvBVtQpbD1VAyTiej9KkzDBdoB4tynAI8wA0PFy71FHHqTBXglHNg7ImlCs8xpMdnURxoAorN/Q==
"@emurgo/[email protected].2":
version "0.14.2"
resolved "https://registry.yarnpkg.com/@emurgo/yoroi-lib/-/yoroi-lib-0.14.2.tgz#c7bbee40cd224ad405b5e97d738e8b9704fd8c40"
integrity sha512-9zJObcPeiRkylOPe9gcaVmu1PnIY8Zh74HBjGYLTEeyjzwAYByaohJg6iaqsfcCAGyuys9n1njy7gqj7LDeD8w==
dependencies:
"@cardano-foundation/ledgerjs-hw-app-cardano" "^6.0.0"
"@emurgo/cross-csl-core" "^4.0.0-alpha.1"
"@noble/hashes" "^1.3.2"
axios "^0.24.0"
bech32 "^2.0.0"
bignumber.js "^9.0.1"
easy-crc "1.1.0"

"@esbuild/[email protected]":
version "0.18.12"
Expand Down Expand Up @@ -10344,6 +10345,11 @@ eastasianwidth@^0.2.0:
resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb"
integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/easy-crc/-/easy-crc-1.1.0.tgz#fe59a33a9a33faf3ff54cf8f2ba7f13ab3730c1d"
integrity sha512-cvtERLTu8mYt1pOVVekJ4E0VdwyuKgL+VAfE3LY+Lw762i9M1bSEikm6fyGD2grxOdBfI0HgOmSi3HQneKr33A==

easy-stack@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/easy-stack/-/easy-stack-1.0.1.tgz#8afe4264626988cabb11f3c704ccd0c835411066"
Expand Down

0 comments on commit 87245cd

Please sign in to comment.