The PEM string actually is base 64 encoded (at least partially), but I don’t think it’s what you want here, it includes other details and I think you want the “raw” public key data.
Here’s one way you can get your key into the format I think you want. It’s a bit long winded but I don’t think Ruby’s OpenSSL bindings provide a more direct method (you’ll need to first):require "base64"
# Assuming the key is in ecdsa_public_key
Base64.urlsafe_encode64(ecdsa_public_key.public_key.to_bn.to_s(2), padding: false)
This calls to get the underlying public_key, then converts that to an OpenSSL::PKey::EC::Point in the correct format, and converts that to a binary string. Finally this string is base64 encoded. OpenSSL::BN