Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove witnessIndex and witnessLastIndex #34

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-cobras-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@joyid/common': minor
---

refactor: Remove witnessIndex and witnessLastIndex from SignCkbRawTxRequest
5 changes: 5 additions & 0 deletions .changeset/perfect-socks-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@joyid/ckb': major
---

refactor: Remove witnessIndex and witnessLastIndex from signRawTx
1 change: 0 additions & 1 deletion examples/ckb-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@joyid/ckb": "workspace:*",
"@nervina-labs/ckb-dex": "0.1.6",
"axios": "^1.6.0",
"ckb-omiga": "^0.0.12",
"cross-fetch": "^3.1.5",
"framer-motion": "^7.6.1",
"i18next": "^22.0.1",
Expand Down
8 changes: 0 additions & 8 deletions examples/ckb-demo/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ export const Home = () => {
}}>
Transfer CoTA NFT
</Button>
<Button
colorScheme="teal"
w="240px"
onClick={() => {
navi(RoutePath.SignCkbRawTx)
}}>
Sign CKB Raw Tx
</Button>
<Button
colorScheme="teal"
w="240px"
Expand Down
270 changes: 0 additions & 270 deletions examples/ckb-demo/src/pages/SignCkbRawTx/index.tsx

This file was deleted.

1 change: 0 additions & 1 deletion examples/ckb-demo/src/route/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export enum RoutePath {
SignMessage = '/sign-message',
CKBTransfer = '/ckb-transfer',
CotaNFTTransfer = '/cota-nft-transfer',
SignCkbRawTx = '/sign-ckb-raw-tx',
}
5 changes: 0 additions & 5 deletions examples/ckb-demo/src/route/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { SignMessage } from '../pages/SignMessage'
import { SignTransaction } from '../pages/SignTransaction'
import { RoutePath } from './path'
import { SignCotaNFT } from '../pages/SignCotaNFT'
import { SignCkbRawTx } from '../pages/SignCkbRawTx'

export const routers: RouteObject[] = [
{
Expand Down Expand Up @@ -34,10 +33,6 @@ export const routers: RouteObject[] = [
path: RoutePath.CotaNFTTransfer,
element: <SignCotaNFT />,
},
{
path: RoutePath.SignCkbRawTx,
element: <SignCkbRawTx />,
},
],
},
]
27 changes: 4 additions & 23 deletions packages/ckb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
append0x,
remove0x,
} from '@joyid/common'
import ckbUtils from '@nervosnetwork/ckb-sdk-utils'
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils'
import { Aggregator } from './aggregator'

export * from './verify'
Expand Down Expand Up @@ -62,16 +62,10 @@ export const initConfig = (config?: CkbDappConfig): CkbDappConfig => {

export const getConfig = (): CkbDappConfig => internalDappConfig

// The witnessIndexes represents the positions of the JoyID cells in inputs, the default value is empty array
// deprecated: The witnessIndex represents the position of the first JoyID cell in inputs, and the default value is 0
// deprecated: The witnessLastIndex represents the position of the last JoyID cell in inputs, and the default value is inputs.length - 1
// deprecated: The witnessLastIndex must not be smaller than witnessIndex.
// deprecated: For example: witnessIndex = 1, witnessLastIndex = 3, this means the inputs[1..3] are JoyID cell, and the other inputs are another lock scripts.
// The witnessIndexes represents the positions of the JoyID cells in inputs, the default value is an empty array
export type SignConfig = CkbDappConfig &
Pick<PopupConfigOptions, 'timeoutInSeconds' | 'popup'> & {
witnessIndexes?: number[]
witnessIndex?: number
witnessLastIndex?: number
}

export const connect = async (
Expand Down Expand Up @@ -195,9 +189,9 @@ export const signRawTransaction = async (
...config,
}

const { witnessIndexes, witnessIndex, witnessLastIndex } = config
const { witnessIndexes } = config

if (witnessIndexes) {
if (Array.isArray(witnessIndexes)) {
if (witnessIndexes.length === 0) {
throw new Error('The witnessIndexes must be not empty')
}
Expand All @@ -208,19 +202,6 @@ export const signRawTransaction = async (
}
}

if (witnessIndex && witnessLastIndex) {
if (witnessLastIndex < witnessIndex) {
throw new Error(
'The witnessLastIndex must not be smaller than the witnessIndex'
)
}
if (witnessLastIndex >= tx.inputs.length) {
throw new Error(
'The witnessLastIndex must be smaller than the length of inputs'
)
}
}

if (!config.popup) {
config.popup = openPopup('')

Expand Down
Loading
Loading