-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
663 additions
and
1,279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import rules from "@wcpos/eslint-config"; | ||
export default rules; | ||
import rules from '../../packages/eslint/index.js'; | ||
export default rules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,51 @@ | ||
import * as Crypto from 'expo-crypto'; | ||
|
||
// Polyfill for global.crypto if it doesn't exist. | ||
// Polyfill implementation for subtle.digest | ||
// Note: This is only needed for DEV because of the RxDB schema validation | ||
const subtlePolyfill = { | ||
async digest(algorithm: string, data: BufferSource): Promise<ArrayBuffer> { | ||
// Convert BufferSource to ArrayBuffer | ||
let dataBuffer: ArrayBuffer; | ||
if (data instanceof ArrayBuffer) { | ||
dataBuffer = data; | ||
} else if (ArrayBuffer.isView(data)) { | ||
dataBuffer = data.buffer; | ||
} else { | ||
throw new Error('Unsupported data type for digest'); | ||
} | ||
|
||
// Convert ArrayBuffer to a UTF-8 string. | ||
// WARNING: This assumes that the input is valid UTF-8. | ||
const decoded = new TextDecoder().decode(dataBuffer); | ||
|
||
// Calculate digest as a hex string using Expo Crypto. | ||
const digestHex = await Crypto.digestStringAsync(algorithm, decoded); | ||
|
||
// Convert hex string back to ArrayBuffer. | ||
const buffer = new ArrayBuffer(digestHex.length / 2); | ||
const view = new Uint8Array(buffer); | ||
for (let i = 0; i < digestHex.length; i += 2) { | ||
view[i / 2] = parseInt(digestHex.substr(i, 2), 16); | ||
} | ||
return buffer; | ||
}, | ||
}; | ||
|
||
if (typeof global.crypto === 'undefined') { | ||
// If global.crypto doesn't exist, create it with a polyfill for getRandomValues. | ||
global.crypto = { | ||
// Polyfill getRandomValues | ||
getRandomValues: <T extends ArrayBufferView | null>(buffer: T): T => { | ||
if (!buffer) return buffer; | ||
const ints = new Uint8Array(buffer.byteLength); | ||
Crypto.getRandomValues(ints); | ||
new Uint8Array(buffer.buffer).set(ints); | ||
return buffer; | ||
}, | ||
// Polyfill subtle if missing | ||
subtle: { | ||
async digest(algorithm: string, data: BufferSource): Promise<ArrayBuffer> { | ||
// Convert BufferSource to ArrayBuffer | ||
let dataBuffer: ArrayBuffer; | ||
if (data instanceof ArrayBuffer) { | ||
dataBuffer = data; | ||
} else if (ArrayBuffer.isView(data)) { | ||
dataBuffer = data.buffer; | ||
} else { | ||
throw new Error('Unsupported data type for digest'); | ||
} | ||
|
||
// Convert ArrayBuffer to a UTF-8 string. | ||
// WARNING: This assumes that the input is valid UTF-8. | ||
const decoded = new TextDecoder().decode(dataBuffer); | ||
|
||
// Calculate digest as a hex string using Expo Crypto. | ||
const digestHex = await Crypto.digestStringAsync(algorithm, decoded); | ||
|
||
// Convert hex string back to ArrayBuffer | ||
const buffer = new ArrayBuffer(digestHex.length / 2); | ||
const view = new Uint8Array(buffer); | ||
for (let i = 0; i < digestHex.length; i += 2) { | ||
view[i / 2] = parseInt(digestHex.substr(i, 2), 16); | ||
} | ||
return buffer; | ||
}, | ||
}, | ||
}; | ||
} else if (typeof global.crypto.subtle === 'undefined') { | ||
// If crypto exists but crypto.subtle is missing, add the subtle polyfill. | ||
global.crypto.subtle = { | ||
async digest(algorithm: string, data: BufferSource): Promise<ArrayBuffer> { | ||
let dataBuffer: ArrayBuffer; | ||
if (data instanceof ArrayBuffer) { | ||
dataBuffer = data; | ||
} else if (ArrayBuffer.isView(data)) { | ||
dataBuffer = data.buffer; | ||
} else { | ||
throw new Error('Unsupported data type for digest'); | ||
} | ||
|
||
const decoded = new TextDecoder().decode(dataBuffer); | ||
const digestHex = await Crypto.digestStringAsync(algorithm, decoded); | ||
const buffer = new ArrayBuffer(digestHex.length / 2); | ||
const view = new Uint8Array(buffer); | ||
for (let i = 0; i < digestHex.length; i += 2) { | ||
view[i / 2] = parseInt(digestHex.substr(i, 2), 16); | ||
} | ||
return buffer; | ||
}, | ||
// Only include subtle polyfill in the __DEV__ environment. | ||
...(__DEV__ ? { subtle: subtlePolyfill } : {}), | ||
}; | ||
} else if (__DEV__ && typeof global.crypto.subtle === 'undefined') { | ||
// If global.crypto exists but subtle is missing and we're in __DEV__, | ||
// add the subtle polyfill. | ||
global.crypto.subtle = subtlePolyfill; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import rules from "@wcpos/eslint-config"; | ||
import rules from "./packages/eslint/index.js"; | ||
export default rules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import rules from '../eslint/index.js'; | ||
export default rules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.