Skip to content

Commit

Permalink
chore: Signature + PublicKey tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Nov 3, 2024
1 parent e492184 commit 3320493
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 287 deletions.
2 changes: 1 addition & 1 deletion examples/webauthn-p256/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function App() {
<pre>{Json.stringify(credential.publicKey, null, 2)}</pre>
<strong>Public Key (serialized): </strong>
<br />
<pre>{PublicKey.serialize(credential.publicKey)}</pre>
<pre>{PublicKey.toHex(credential.publicKey)}</pre>
</div>
)}
<br />
Expand Down
12 changes: 6 additions & 6 deletions site/pages/guides/ecdsa.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ It is important to note that `yParity` (recovery bit) may not be present in _all

### Serializing

You may need to serialize a Signature into Hex or Bytes format for specific use cases. You can do this using the [`Signature.serialize`](/api/Signature/serialize) function:
You may need to serialize a Signature into Hex or Bytes format for specific use cases. You can do this using the [`Signature.toHex`](/api/Signature/toHex) or [`Signature.toBytes`](/api/Signature/toBytes) functions:

```ts twoslash
import { Signature } from 'ox'
Expand All @@ -236,11 +236,11 @@ const signature = Signature.from({
s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
yParity: 0,
})
const serialized = Signature.serialize(signature)
const serialized = Signature.toHex(signature)
// ^?


const serialized_bytes = Signature.serialize(signature, { as: 'Bytes' })
const serialized_bytes = Signature.toBytes(signature)
// ^?


Expand Down Expand Up @@ -277,7 +277,7 @@ const publicKey_2 = PublicKey.from({

### Serializing

You may need to serialize a Public Key into Hex or Bytes format for specific use cases. You can do this using the [`PublicKey.serialize`](/api/PublicKey/serialize) function:
You may need to serialize a Public Key into Hex or Bytes format for specific use cases. You can do this using the [`PublicKey.toHex`](/api/PublicKey/toHex) or [`PublicKey.toBytes`](/api/PublicKey/toBytes) functions:

```ts twoslash
import { PublicKey } from 'ox'
Expand All @@ -286,11 +286,11 @@ const publicKey = PublicKey.from({
x: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
})
const serialized = PublicKey.serialize(publicKey)
const serialized = PublicKey.toHex(publicKey)
// ^?


const serialized_bytes = PublicKey.serialize(publicKey, { as: 'Bytes' })
const serialized_bytes = PublicKey.toBytes(publicKey)
// ^?


Expand Down
4 changes: 2 additions & 2 deletions src/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export function fromPublicKey(
options: fromPublicKey.Options = {},
): Address {
const address = Hash.keccak256(
`0x${PublicKey.serialize(publicKey).slice(4)}`,
`0x${PublicKey.toHex(publicKey).slice(4)}`,
).substring(26)
return from(`0x${address}`, options)
}
Expand All @@ -217,7 +217,7 @@ export declare namespace fromPublicKey {

type ErrorType =
| Hash.keccak256.ErrorType
| PublicKey.serialize.ErrorType
| PublicKey.toHex.ErrorType
| Errors.GlobalErrorType
}

Expand Down
2 changes: 1 addition & 1 deletion src/P256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export function verify(options: verify.Options): boolean {
return secp256r1.verify(
signature,
payload instanceof Uint8Array ? payload : Bytes.fromHex(payload),
PublicKey.serialize(publicKey).substring(2),
PublicKey.toHex(publicKey).substring(2),
...(hash ? [{ prehash: true, lowS: true }] : []),
)
}
Expand Down
Loading

0 comments on commit 3320493

Please sign in to comment.