@iam-protocol/pulse-sdk 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +38 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -0
- package/src/pulse.ts +36 -2
- package/src/sensor/audio.ts +9 -1
- package/src/sensor/types.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -12967,7 +12967,8 @@ async function captureAudio(options = {}) {
|
|
|
12967
12967
|
const {
|
|
12968
12968
|
signal,
|
|
12969
12969
|
minDurationMs = MIN_CAPTURE_MS,
|
|
12970
|
-
maxDurationMs = MAX_CAPTURE_MS
|
|
12970
|
+
maxDurationMs = MAX_CAPTURE_MS,
|
|
12971
|
+
onAudioLevel
|
|
12971
12972
|
} = options;
|
|
12972
12973
|
const stream = await navigator.mediaDevices.getUserMedia({
|
|
12973
12974
|
audio: {
|
|
@@ -12987,7 +12988,13 @@ async function captureAudio(options = {}) {
|
|
|
12987
12988
|
const bufferSize = 4096;
|
|
12988
12989
|
const processor = ctx.createScriptProcessor(bufferSize, 1, 1);
|
|
12989
12990
|
processor.onaudioprocess = (e2) => {
|
|
12990
|
-
|
|
12991
|
+
const data = e2.inputBuffer.getChannelData(0);
|
|
12992
|
+
chunks.push(new Float32Array(data));
|
|
12993
|
+
if (onAudioLevel) {
|
|
12994
|
+
let sum = 0;
|
|
12995
|
+
for (let i = 0; i < data.length; i++) sum += data[i] * data[i];
|
|
12996
|
+
onAudioLevel(Math.sqrt(sum / data.length));
|
|
12997
|
+
}
|
|
12991
12998
|
};
|
|
12992
12999
|
source.connect(processor);
|
|
12993
13000
|
processor.connect(ctx.destination);
|
|
@@ -13766,7 +13773,32 @@ function extractFeatures(data) {
|
|
|
13766
13773
|
const touchFeatures = extractTouchFeatures(data.touch);
|
|
13767
13774
|
return fuseFeatures(audioFeatures, motionFeatures, touchFeatures);
|
|
13768
13775
|
}
|
|
13776
|
+
var MIN_AUDIO_SAMPLES = 16e3;
|
|
13777
|
+
var MIN_MOTION_SAMPLES = 10;
|
|
13778
|
+
var MIN_TOUCH_SAMPLES = 10;
|
|
13769
13779
|
async function processSensorData(sensorData, config, wallet, connection) {
|
|
13780
|
+
const audioSamples = sensorData.audio?.samples.length ?? 0;
|
|
13781
|
+
const motionSamples = sensorData.motion.length;
|
|
13782
|
+
const touchSamples = sensorData.touch.length;
|
|
13783
|
+
const hasAudio = audioSamples >= MIN_AUDIO_SAMPLES;
|
|
13784
|
+
const hasMotion = motionSamples >= MIN_MOTION_SAMPLES;
|
|
13785
|
+
const hasTouch = touchSamples >= MIN_TOUCH_SAMPLES;
|
|
13786
|
+
if (!hasAudio && !hasMotion && !hasTouch) {
|
|
13787
|
+
return {
|
|
13788
|
+
success: false,
|
|
13789
|
+
commitment: new Uint8Array(32),
|
|
13790
|
+
isFirstVerification: true,
|
|
13791
|
+
error: "Insufficient behavioral data. Please speak the phrase and trace the curve during capture."
|
|
13792
|
+
};
|
|
13793
|
+
}
|
|
13794
|
+
if (!hasAudio) {
|
|
13795
|
+
return {
|
|
13796
|
+
success: false,
|
|
13797
|
+
commitment: new Uint8Array(32),
|
|
13798
|
+
isFirstVerification: true,
|
|
13799
|
+
error: "No voice data detected. Please speak the phrase clearly during capture."
|
|
13800
|
+
};
|
|
13801
|
+
}
|
|
13770
13802
|
const features = extractFeatures(sensorData);
|
|
13771
13803
|
const fingerprint = simhash(features);
|
|
13772
13804
|
const tbh = await generateTBH(fingerprint);
|
|
@@ -13813,7 +13845,7 @@ async function processSensorData(sensorData, config, wallet, connection) {
|
|
|
13813
13845
|
submission = await submitViaRelayer(
|
|
13814
13846
|
solanaProof ?? { proofBytes: new Uint8Array(0), publicInputs: [] },
|
|
13815
13847
|
tbh.commitmentBytes,
|
|
13816
|
-
{ relayerUrl: config.relayerUrl, isFirstVerification }
|
|
13848
|
+
{ relayerUrl: config.relayerUrl, apiKey: config.relayerApiKey, isFirstVerification }
|
|
13817
13849
|
);
|
|
13818
13850
|
} else {
|
|
13819
13851
|
return {
|
|
@@ -13857,13 +13889,14 @@ var PulseSession = class {
|
|
|
13857
13889
|
this.touchElement = touchElement;
|
|
13858
13890
|
}
|
|
13859
13891
|
// --- Audio ---
|
|
13860
|
-
async startAudio() {
|
|
13892
|
+
async startAudio(onAudioLevel) {
|
|
13861
13893
|
if (this.audioStageState !== "idle")
|
|
13862
13894
|
throw new Error("Audio capture already started");
|
|
13863
13895
|
this.audioStageState = "capturing";
|
|
13864
13896
|
this.audioController = new AbortController();
|
|
13865
13897
|
this.audioPromise = captureAudio({
|
|
13866
|
-
signal: this.audioController.signal
|
|
13898
|
+
signal: this.audioController.signal,
|
|
13899
|
+
onAudioLevel
|
|
13867
13900
|
}).catch(() => null);
|
|
13868
13901
|
}
|
|
13869
13902
|
async stopAudio() {
|