功能:同步小程序流程
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Purpose: utf8ToBytes supports crypto.js by holding or executing the utf8 to bytes page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function utf8ToBytes(text) {
|
||||
const encoded = unescape(encodeURIComponent(String(text || '')))
|
||||
const bytes = []
|
||||
@@ -7,14 +11,26 @@ function utf8ToBytes(text) {
|
||||
return bytes
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: bytesToHex supports crypto.js by holding or executing the bytes to hex page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function bytesToHex(bytes) {
|
||||
return (Array.isArray(bytes) ? bytes : []).map(item => item.toString(16).padStart(2, '0')).join('')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: rightRotate supports crypto.js by holding or executing the right rotate page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function rightRotate(value, amount) {
|
||||
return (value >>> amount) | (value << (32 - amount))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sha256Bytes supports crypto.js by holding or executing the sha256 bytes page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function sha256Bytes(messageBytes) {
|
||||
const k = [
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
@@ -113,10 +129,18 @@ function sha256Bytes(messageBytes) {
|
||||
return output
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sha256Hex supports crypto.js by holding or executing the sha256 hex page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function sha256Hex(text) {
|
||||
return bytesToHex(sha256Bytes(utf8ToBytes(text)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: hmacSha256Hex supports crypto.js by holding or executing the hmac sha256 hex page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function hmacSha256Hex(secret, message) {
|
||||
let keyBytes = utf8ToBytes(secret)
|
||||
if (keyBytes.length > 64) {
|
||||
@@ -137,6 +161,10 @@ function hmacSha256Hex(secret, message) {
|
||||
return bytesToHex(sha256Bytes(outer.concat(innerDigest)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildCanonicalParams supports crypto.js by holding or executing the build canonical params page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildCanonicalParams(input) {
|
||||
const source = input || {}
|
||||
const keys = Object.keys(source)
|
||||
@@ -154,6 +182,10 @@ function buildCanonicalParams(input) {
|
||||
}).join('&')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildJsonPayload supports crypto.js by holding or executing the build json payload page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildJsonPayload(data) {
|
||||
if (data === undefined || data === null || data === '') {
|
||||
return ''
|
||||
@@ -164,6 +196,10 @@ function buildJsonPayload(data) {
|
||||
return JSON.stringify(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: randomNonce supports crypto.js by holding or executing the random nonce page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function randomNonce() {
|
||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user