From 62ad2cb9c251acbf975a4a477c0915db2067fdf5 Mon Sep 17 00:00:00 2001 From: jin Date: Wed, 22 Nov 2023 15:47:30 +0300 Subject: [PATCH] $mol_base64: safe -> url --- base64/{safe/safe.ts => url/url.ts} | 4 ++-- crypto/auditor/auditor.ts | 20 ++++++++++---------- crypto/key/key.ts | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) rename base64/{safe/safe.ts => url/url.ts} (62%) diff --git a/base64/safe/safe.ts b/base64/url/url.ts similarity index 62% rename from base64/safe/safe.ts rename to base64/url/url.ts index 1116d6cf9a1..63c913ca77e 100644 --- a/base64/safe/safe.ts +++ b/base64/url/url.ts @@ -1,10 +1,10 @@ namespace $ { - export function $mol_base64_encode_safe( buffer: Uint8Array ) { + export function $mol_base64_url_encode( buffer: Uint8Array ) { return $mol_base64_encode( buffer ).replace( /\+/g, '-' ).replace( /\//g, '_' ).replace( /=/g, '' ) } - export function $mol_base64_safe_decode( str: string ) { + export function $mol_base64_url_decode( str: string ) { return $mol_base64_decode( str.replace( /-/g, '+' ).replace( /_/g, '/' ) ) } diff --git a/crypto/auditor/auditor.ts b/crypto/auditor/auditor.ts index 802d9762f39..54b5625d2a0 100644 --- a/crypto/auditor/auditor.ts +++ b/crypto/auditor/auditor.ts @@ -45,8 +45,8 @@ namespace $ { static async from( serial: string | Uint8Array ) { if( typeof serial !== 'string' ) { - serial = $mol_base64_encode_safe( serial.subarray( 0, 32 ) ) - + $mol_base64_encode_safe( serial.subarray( 32, 64 ) ) + serial = $mol_base64_url_encode( serial.subarray( 0, 32 ) ) + + $mol_base64_url_encode( serial.subarray( 32, 64 ) ) } return new this( await $mol_crypto_native.subtle.importKey( @@ -79,8 +79,8 @@ namespace $ { async toArray(): Promise< Uint8Array > { const { x, y, d } = await $mol_crypto_native.subtle.exportKey( 'jwk', this.native ) return new Uint8Array([ - ... $mol_base64_safe_decode( x! ), - ... $mol_base64_safe_decode( y! ), + ... $mol_base64_url_decode( x! ), + ... $mol_base64_url_decode( y! ), ]) } @@ -110,9 +110,9 @@ namespace $ { static async from( serial: string | Uint8Array ) { if( typeof serial !== 'string' ) { - serial = $mol_base64_encode_safe( serial.subarray( 0, 32 ) ) - + $mol_base64_encode_safe( serial.subarray( 32, 64 ) ) - + $mol_base64_encode_safe( serial.subarray( 64 ) ) + serial = $mol_base64_url_encode( serial.subarray( 0, 32 ) ) + + $mol_base64_url_encode( serial.subarray( 32, 64 ) ) + + $mol_base64_url_encode( serial.subarray( 64 ) ) } return new this( await $mol_crypto_native.subtle.importKey( @@ -143,9 +143,9 @@ namespace $ { async toArray(): Promise< Uint8Array > { const { x, y, d } = await $mol_crypto_native.subtle.exportKey( 'jwk', this.native ) return new Uint8Array([ - ... $mol_base64_safe_decode( x! ), - ... $mol_base64_safe_decode( y! ), - ... $mol_base64_safe_decode( d! ), + ... $mol_base64_url_decode( x! ), + ... $mol_base64_url_decode( y! ), + ... $mol_base64_url_decode( d! ), ]) } diff --git a/crypto/key/key.ts b/crypto/key/key.ts index e0f0d9be9ae..2367afadebb 100644 --- a/crypto/key/key.ts +++ b/crypto/key/key.ts @@ -12,9 +12,9 @@ namespace $ { if( typeof serial === 'string' ) { serial = new Uint8Array([ - ... $mol_base64_safe_decode( serial.slice( 0, 43 ) ), - ... $mol_base64_safe_decode( serial.slice( 43, 86 ) ), - ... $mol_base64_safe_decode( serial.slice( 86, 129 ) ), + ... $mol_base64_url_decode( serial.slice( 0, 43 ) ), + ... $mol_base64_url_decode( serial.slice( 43, 86 ) ), + ... $mol_base64_url_decode( serial.slice( 86, 129 ) ), ]) } @@ -28,9 +28,9 @@ namespace $ { @ $mol_memo.method toString() { const arr = this.asArray() - return $mol_base64_encode_safe( arr.subarray( 0, 32 ) ) - + $mol_base64_encode_safe( arr.subarray( 32, 64 ) ) - + $mol_base64_encode_safe( arr.subarray( 64 ) ) + return $mol_base64_url_encode( arr.subarray( 0, 32 ) ) + + $mol_base64_url_encode( arr.subarray( 32, 64 ) ) + + $mol_base64_url_encode( arr.subarray( 64 ) ) } }