-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support algo, ckb data & fix several issues OK-27484 OK-27478 (#…
…4633) * fix: ckb sign tx error * fix: algo wallect conenct * fix: algo wallect conenct * chore: add octa chain * fix: review issues * fix: review issues
- Loading branch information
1 parent
a7729d9
commit 50bd33c
Showing
19 changed files
with
328 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { utils } from '@ckb-lumos/base'; | ||
import { getConfig as getSDKConfig } from '@ckb-lumos/config-manager'; | ||
import { generateAddress, parseAddress } from '@ckb-lumos/helpers'; | ||
|
||
import type { Script } from '@ckb-lumos/base'; | ||
import type { Config } from '@ckb-lumos/config-manager'; | ||
import type { Options } from '@ckb-lumos/helpers'; | ||
|
||
function blake160(publicKey: string): string { | ||
return new utils.CKBHasher().update(publicKey).digestHex().slice(0, 42); | ||
} | ||
|
||
export function getConfig(chainId: string) { | ||
const config = getSDKConfig(); | ||
if (chainId === 'mainnet' && config.PREFIX === 'ckb') { | ||
return config; | ||
} | ||
if (chainId === 'testnet' && config.PREFIX === 'ckt') { | ||
return config; | ||
} | ||
|
||
throw new Error('Invalid chainId'); | ||
} | ||
|
||
export function scriptToAddress( | ||
script: Script, | ||
{ config = undefined }: Options = {}, | ||
): string { | ||
// It needs to be replaced with encodeToAddress | ||
return generateAddress(script, { config }); | ||
} | ||
|
||
export function pubkeyToAddress( | ||
publicKey: string, | ||
{ | ||
config, | ||
}: { | ||
config: Config; | ||
}, | ||
): string { | ||
const args = blake160(publicKey); | ||
const template = config.SCRIPTS.SECP256K1_BLAKE160; | ||
|
||
if (!template) { | ||
throw new Error('SECP256K1_BLAKE160 not found in config'); | ||
} | ||
|
||
const lockScript = { | ||
codeHash: template.CODE_HASH, | ||
hashType: template.HASH_TYPE, | ||
args, | ||
}; | ||
return scriptToAddress(lockScript, { config }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import type { TransactionSkeletonType } from '@ckb-lumos/helpers'; | ||
import type { Transaction } from '@ckb-lumos/base'; | ||
|
||
export type IEncodedTxCkb = TransactionSkeletonType; | ||
export type IEncodedTxCkb = { | ||
tx: Transaction; | ||
feeInfo: { | ||
price: string; | ||
limit: string; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/kit-bg/src/providers/ProviderApiWalletConnect/WalletConnectRequestProxyAlgo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types'; | ||
|
||
import { WalletConnectRequestProxy } from './WalletConnectRequestProxy'; | ||
|
||
export class WalletConnectRequestProxyAlgo extends WalletConnectRequestProxy { | ||
override providerName = IInjectedProviderNames.algo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.