Skip to content

Commit

Permalink
deriveBits: directly use goja.NewPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Apr 12, 2024
1 parent d538625 commit a15ebeb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions webcrypto/subtle_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ func (sc *SubtleCrypto) DeriveKey(
//
// The `length` parameter is the number of bits to derive. The number should be a multiple of 8.
func (sc *SubtleCrypto) DeriveBits(algorithm goja.Value, baseKey goja.Value, length int) *goja.Promise {
promise, resolve, reject := promises.New(sc.vu)
rt := sc.vu.Runtime()

var publicKey, privateKey CryptoKey
Expand Down Expand Up @@ -636,12 +635,15 @@ func (sc *SubtleCrypto) DeriveBits(algorithm goja.Value, baseKey goja.Value, len

return nil
}()

promise, resolve, reject := rt.NewPromise()
callback := sc.vu.RegisterCallback()
if err != nil {
reject(err)
return promise
}

go func() {
callback(func() error {
result, err := func() ([]byte, error) {
deriver, err := newBitsDeriver(algName)
if err != nil {
Expand All @@ -661,11 +663,12 @@ func (sc *SubtleCrypto) DeriveBits(algorithm goja.Value, baseKey goja.Value, len
}()
if err != nil {
reject(err)
return
return nil
}

resolve(rt.NewArrayBuffer(result))
}()
return nil
})

return promise
}
Expand Down

0 comments on commit a15ebeb

Please sign in to comment.