-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #907 from input-output-hk/feature/LW-8295-signData…
…-DRepID-support feat: add support for signing data with a DRepID in CIP-95 API
- Loading branch information
Showing
16 changed files
with
225 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Address, AddressType } from './Address'; | ||
import { OpaqueString, assertIsBech32WithPrefix, typedBech32 } from '@cardano-sdk/util'; | ||
/** | ||
* DRepID as bech32 string | ||
*/ | ||
export type DRepID = OpaqueString<'DRepID'>; | ||
|
||
/** | ||
* @param {string} value DRepID as bech32 string | ||
* @throws InvalidStringError | ||
*/ | ||
export const DRepID = (value: string): DRepID => typedBech32(value, ['drep']); | ||
|
||
DRepID.isValid = (value: string): boolean => { | ||
try { | ||
assertIsBech32WithPrefix(value, 'drep'); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
DRepID.canSign = (value: string): boolean => { | ||
try { | ||
return DRepID.isValid(value) && Address.fromBech32(value).getType() === AddressType.EnterpriseKey; | ||
} catch { | ||
return false; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { DRepID } from '../../../src/Cardano'; | ||
import { InvalidStringError } from '@cardano-sdk/util'; | ||
|
||
describe('Cardano/Address/DRepID', () => { | ||
it('DRepID() accepts a valid bech32 string with drep as prefix', () => { | ||
expect(() => DRepID('drep1vpzcgfrlgdh4fft0p0ju70czkxxkuknw0jjztl3x7aqgm9q3hqyaz')).not.toThrow(); | ||
}); | ||
|
||
it('DRepID() throws an error if the bech32 string has the wrong prefix', () => { | ||
expect(() => DRepID('addr_test1vpudzrw5uq46qwl6h5szlc66fydr0l2rlsw4nvaaxfld40g3ys07c')).toThrowError( | ||
InvalidStringError | ||
); | ||
}); | ||
|
||
describe('isValid', () => { | ||
it('is true if string is a valid DRepID', () => { | ||
expect(DRepID.isValid('drep1vpzcgfrlgdh4fft0p0ju70czkxxkuknw0jjztl3x7aqgm9q3hqyaz')).toBe(true); | ||
}); | ||
it('is false if string is not a valid DRepID', () => { | ||
expect(DRepID.isValid('addr_test1vpudzrw5uq46qwl6h5szlc66fydr0l2rlsw4nvaaxfld40g3ys07c')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('canSign', () => { | ||
it('is true if DRepID is a valid type 6 address', () => { | ||
expect(DRepID.canSign('drep1vpzcgfrlgdh4fft0p0ju70czkxxkuknw0jjztl3x7aqgm9q3hqyaz')).toBe(true); | ||
}); | ||
it('is false if DRepID is not a type 6 address', () => { | ||
expect(DRepID.canSign('drep1wpzcgfrlgdh4fft0p0ju70czkxxkuknw0jjztl3x7aqgm9qcluy2z')).toBe(false); | ||
}); | ||
}); | ||
}); |
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
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.