-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a29b3c
commit 166cc52
Showing
10 changed files
with
117 additions
and
99 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
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
11 changes: 11 additions & 0 deletions
11
packages/cardano/src/wallet/util/derive-ed25519-key-hash-from-bip32-public-key.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,11 @@ | ||
import * as Crypto from '@cardano-sdk/crypto'; | ||
import * as KeyManagement from '@cardano-sdk/key-management'; | ||
|
||
export const deriveEd25519KeyHashFromBip32PublicKey = async ( | ||
key: Crypto.Bip32PublicKeyHex, | ||
derivationPath: KeyManagement.AccountKeyDerivationPath | ||
): Promise<Crypto.Ed25519KeyHashHex> => { | ||
const accountKey = Crypto.Bip32PublicKey.fromHex(key); | ||
const derivedKey = await accountKey.derive([derivationPath.role, derivationPath.index]); | ||
return Crypto.Ed25519KeyHashHex(await derivedKey.hash()); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './add-shared-wallet'; | ||
export * from './utils'; |
41 changes: 41 additions & 0 deletions
41
packages/core/src/shared-wallets/utils/build-shared-wallet-script.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,41 @@ | ||
import { Wallet } from '@lace/cardano'; | ||
|
||
export type ScriptKind = | ||
| { kind: Wallet.Cardano.NativeScriptKind.RequireAllOf } | ||
| { kind: Wallet.Cardano.NativeScriptKind.RequireAnyOf } | ||
| { kind: Wallet.Cardano.NativeScriptKind.RequireNOf; required: number }; | ||
|
||
type SharedWalletScriptParams = { | ||
derivationPath: Wallet.KeyManagement.AccountKeyDerivationPath; | ||
expectedSigners: Array<Wallet.Crypto.Bip32PublicKeyHex>; | ||
kindInfo: ScriptKind; | ||
}; | ||
|
||
type ScriptType = | ||
| Wallet.Cardano.RequireAllOfScript | ||
| Wallet.Cardano.RequireAtLeastScript | ||
| Wallet.Cardano.RequireAnyOfScript; | ||
|
||
export const buildSharedWalletScript = async ({ | ||
expectedSigners, | ||
derivationPath, | ||
kindInfo, | ||
}: SharedWalletScriptParams): Promise<ScriptType> => { | ||
const signers = [...expectedSigners].sort((key1, key2) => key1.localeCompare(key2)); | ||
|
||
const scripts: Wallet.Cardano.NativeScript[] = []; | ||
|
||
for (const signer of signers) { | ||
scripts.push({ | ||
__type: Wallet.Cardano.ScriptType.Native, | ||
keyHash: await Wallet.util.deriveEd25519KeyHashFromBip32PublicKey(signer, derivationPath), | ||
kind: Wallet.Cardano.NativeScriptKind.RequireSignature, | ||
}); | ||
} | ||
|
||
return { | ||
__type: Wallet.Cardano.ScriptType.Native, | ||
scripts, | ||
...kindInfo, | ||
}; | ||
}; |
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 @@ | ||
export * from './build-shared-wallet-script'; |