Skip to content

Signing Helpers

Signing helpers provide functions to cryptographically sign and verify data using HMAC-SHA256.

INFO

Signing is faster than encryption but users can view the original data.

ts
import { 
sign
,
unsign
} from '@orpc/server/helpers'
const
secret
= 'your-secret-key'
const
userData
= 'user123'
const
signedValue
= await
sign
(
userData
,
secret
)
// 'user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA' // ↑ Original data is visible to users const
verifiedValue
= await
unsign
(
signedValue
,
secret
) // 'user123'

INFO

The unsign helper accepts undefined or null as signed value and returns undefined for invalid inputs, enabling seamless handling of optional data.

Released under the MIT License.