Commit Graph

7 Commits

Author SHA1 Message Date
cmd
325adae009
Add method for deriving HMAC keys from the private key.
I ran into an issue where I want to derive child-keys from the parent private key, but there is currently no way to do this with the current spec.

I propose adding a `window.nostr.getDerivedKey(key: string): string` method to the spec, which is a simple HMAC method using the private key and a user supplied key. HMAC has wide-spread support in the WebCrypto spec, and is easy to implement. 

https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto

Here is some reference code for performing a simple HMAC operation using WebCrypto API:
```ts
async function hmac (
  // Perform an HMAC signing operation.
  key   : Uint8Array,
  data : Uint8Array,
  fmt   : string = 'SHA-256'
) : Promise<Uint8Array> {
  const cryptoKey = await importKey(key, fmt)
  return crypto.subtle
    .sign('HMAC', cryptoKey, data)
    .then((buffer) => new Uint8Array(buffer))
}
async function importKey (
  // Create a CryptoKey from the 
  // supplied key and format string.
  key : Uint8Array,
  fmt : string = 'SHA-256'
) : Promise<CryptoKey> {
  const config = { name: 'HMAC', hash: fmt }
  return crypto.subtle.importKey(
    'raw', key, config, false, ['sign', 'verify']
  )
}
```
2023-02-03 15:50:58 -06:00
fiatjaf
e5ae318984
add nos2x-fox to NIP-07 implementations. 2023-01-15 20:05:52 -03:00
fiatjaf
230f63dd5f
nip-07 extensions to also add .id and .pubkey when signing. 2023-01-15 15:37:42 -03:00
fiatjaf
745297e8c4
add blockcore to nip-07 and mark extra methods as optional. 2022-12-18 06:35:30 -03:00
alex
c840d75ce0 nip-07: add the missing functions
as per conversation in t.me/nostr_protcol

getRelays, nip04.encrypt and nip04.decrypt - these are already implemented
by nos2x and getalby.
2022-12-18 06:29:29 -03:00
fiatjaf
9302c35573
add alby to NIP-07. 2022-11-27 12:03:46 -03:00
fiatjaf
37eb53e3d9 publish NIP-07: window.nostr. 2022-05-06 20:54:45 -03:00