j4
j4
DDeno
Created by j4 on 10/26/2024 in #help
Vite plugin's global variables are `undefined` when using Deno
This turned out to be an issue with my Vite plugin config. It was working with a locally-linked package with bun (bun link <name>). But this isn't how Vite handles things with non-locally-linked packages. So, this is what resolved it for me:
...
return {
define: {
'XINK_VITE_MODE': JSON.stringify(mode)
},
ssr: { noExternal: [ '@xinkjs/xink' ] // the plugin's package name
}
...
...
return {
define: {
'XINK_VITE_MODE': JSON.stringify(mode)
},
ssr: { noExternal: [ '@xinkjs/xink' ] // the plugin's package name
}
...
2 replies
DDeno
Created by j4 on 12/30/2022 in #help
Getting error `Unrecognized algorithm name` on `crypto.subtle.importKey()`
/* decode base64 key */
const decoded_key = decode64ToString(Deno.env.get('SIGNATURE_PRIVATE_KEY') || '')
console.log('decoded base64', decoded_key)

/* convert decoded key into ArrayBuffer */
const encoder = new TextEncoder()
const buffer_key = encoder.encode(decoded_key)
console.log('ArrayBuffer key', buffer_key)

/* create a CryptoKey */
let key
try {
key = await crypto.subtle.importKey('pkcs8', buffer_key, {
name: 'ECDSA',
namedCurve: 'P-521',
hash: 'SHA-512'
}, false, ['sign'])

console.log('key', key)
} catch(err) {
console.log('key error', err)
throw err
}

/* later on, sign message */
/* decode base64 key */
const decoded_key = decode64ToString(Deno.env.get('SIGNATURE_PRIVATE_KEY') || '')
console.log('decoded base64', decoded_key)

/* convert decoded key into ArrayBuffer */
const encoder = new TextEncoder()
const buffer_key = encoder.encode(decoded_key)
console.log('ArrayBuffer key', buffer_key)

/* create a CryptoKey */
let key
try {
key = await crypto.subtle.importKey('pkcs8', buffer_key, {
name: 'ECDSA',
namedCurve: 'P-521',
hash: 'SHA-512'
}, false, ['sign'])

console.log('key', key)
} catch(err) {
console.log('key error', err)
throw err
}

/* later on, sign message */
4 replies
DDeno
Created by j4 on 12/30/2022 in #help
Getting error `Unrecognized algorithm name` on `crypto.subtle.importKey()`
Found out I need to base64 decode the key, before I convert it to an array buffer. But even then, undefined is thrown. Thoughts?
4 replies
DDeno
Created by j4 on 12/30/2022 in #help
Getting error `Unrecognized algorithm name` on `crypto.subtle.importKey()`
I've now tried passing in an eliptical curve params object, instead of 'SHA-512'. This ends up throwing an undefined error.
{
name: 'ECDSA',
namedCurve: 'P-521'
}
{
name: 'ECDSA',
namedCurve: 'P-521'
}
I also changed spki to pkcs8, as I realized this is for a private key.
4 replies