@iam-protocol/pulse-sdk 0.2.0 → 0.2.2

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/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
- chunks.push(new Float32Array(e2.inputBuffer.getChannelData(0)));
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);
@@ -13857,13 +13864,14 @@ var PulseSession = class {
13857
13864
  this.touchElement = touchElement;
13858
13865
  }
13859
13866
  // --- Audio ---
13860
- async startAudio() {
13867
+ async startAudio(onAudioLevel) {
13861
13868
  if (this.audioStageState !== "idle")
13862
13869
  throw new Error("Audio capture already started");
13863
13870
  this.audioStageState = "capturing";
13864
13871
  this.audioController = new AbortController();
13865
13872
  this.audioPromise = captureAudio({
13866
- signal: this.audioController.signal
13873
+ signal: this.audioController.signal,
13874
+ onAudioLevel
13867
13875
  }).catch(() => null);
13868
13876
  }
13869
13877
  async stopAudio() {
@@ -14111,6 +14119,28 @@ function generatePhrase(wordCount = 5) {
14111
14119
  }
14112
14120
  return words.join(" ");
14113
14121
  }
14122
+ function generatePhraseSequence(count = 3, wordCount = 4) {
14123
+ const subsetSize = Math.floor(SYLLABLES.length / count);
14124
+ const phrases = [];
14125
+ for (let p = 0; p < count; p++) {
14126
+ const start = p * subsetSize % SYLLABLES.length;
14127
+ const subset = [
14128
+ ...SYLLABLES.slice(start, start + subsetSize),
14129
+ ...SYLLABLES.slice(0, Math.max(0, start + subsetSize - SYLLABLES.length))
14130
+ ];
14131
+ const words = [];
14132
+ for (let w = 0; w < wordCount; w++) {
14133
+ const syllableCount = 2 + Math.floor(Math.random() * 2);
14134
+ let word = "";
14135
+ for (let s = 0; s < syllableCount; s++) {
14136
+ word += subset[Math.floor(Math.random() * subset.length)];
14137
+ }
14138
+ words.push(word);
14139
+ }
14140
+ phrases.push(words.join(" "));
14141
+ }
14142
+ return phrases;
14143
+ }
14114
14144
 
14115
14145
  // src/challenge/lissajous.ts
14116
14146
  function randomLissajousParams() {
@@ -14141,6 +14171,33 @@ function generateLissajousPoints(params) {
14141
14171
  }
14142
14172
  return result;
14143
14173
  }
14174
+ function generateLissajousSequence(count = 2) {
14175
+ const allRatios = [
14176
+ [1, 2],
14177
+ [2, 3],
14178
+ [3, 4],
14179
+ [3, 5],
14180
+ [4, 5],
14181
+ [1, 3],
14182
+ [2, 5],
14183
+ [5, 6],
14184
+ [3, 7],
14185
+ [4, 7]
14186
+ ];
14187
+ const shuffled = [...allRatios].sort(() => Math.random() - 0.5);
14188
+ const sequence = [];
14189
+ for (let i = 0; i < count; i++) {
14190
+ const pair = shuffled[i % shuffled.length];
14191
+ const params = {
14192
+ a: pair[0],
14193
+ b: pair[1],
14194
+ delta: Math.PI * (0.1 + Math.random() * 0.8),
14195
+ points: 200
14196
+ };
14197
+ sequence.push({ params, points: generateLissajousPoints(params) });
14198
+ }
14199
+ return sequence;
14200
+ }
14144
14201
  export {
14145
14202
  DEFAULT_CAPTURE_MS,
14146
14203
  DEFAULT_MIN_DISTANCE,
@@ -14159,7 +14216,9 @@ export {
14159
14216
  fetchIdentityState,
14160
14217
  fuseFeatures,
14161
14218
  generateLissajousPoints,
14219
+ generateLissajousSequence,
14162
14220
  generatePhrase,
14221
+ generatePhraseSequence,
14163
14222
  generateProof,
14164
14223
  generateSalt,
14165
14224
  generateSolanaProof,